Methods Summary |
---|
private void | connect()
if (connected)
return;
connect(null, false);
|
private void | connect(java.lang.String cmd, boolean disconnect)
try{
String uri = notifMgrUri;
if (cmd != null)
uri = uri + "&" +
DefaultConfiguration.NOTIF_CMD_PARAM +
"=" + DefaultConfiguration.NOTIF_CMD_CLOSE;
System.setProperty("sun.net.client.defaultConnectTimeout",
Integer.toString(DefaultConfiguration.NOTIF_CONNECT_TIMEOUT)); // XXX: For Sun JDK only
URLConnection conn = ad.openConnection(uri);
// conn.setConnectTimeout(2000); // XXX: For jdk 1.5
InputStream inStream = conn.getInputStream();
if (!disconnect) {
mConnection = conn;
in = inStream;
connected = true;
nReconnected = 0;
} else {
disconnect(conn, inStream);
}
} catch (IOException ioe){
ioe.printStackTrace();
throw (ioe);
}
|
private void | disconnect(java.net.URLConnection conn, java.io.InputStream in)
if (conn instanceof HttpURLConnection) {
((HttpURLConnection)conn).disconnect();
} else
in.close();
|
private void | disconnect()
disconnect(mConnection, in);
|
public void | exit()
exit = true;
sendCloseMessage();
disconnect();
receiveThr.join();
|
private java.lang.String | getNotifMgrURI()
String uri = ad.getPath();
if (uri == null || uri.trim().length() == 0)
uri = DefaultConfiguration.DEFAULT_SERVLET_CONTEXT_ROOT;
uri = uri +
DefaultConfiguration.NOTIF_MGR_PATHINFO +
"?" + DefaultConfiguration.NOTIF_ID_PARAM +
"=" + mgr.getId();
return uri;
|
public boolean | hasTimedout()Returns if the receiver has timedout while trying to receive
notitifications from the server.
Timedout -- If a socket timeout happens while trying to connect
If the server is not reachable 3 times consequtively during thread loop.
If not able to connect when reinit is called.
return timedout;
|
private boolean | isDisconnected(java.io.IOException ioe)
if (ioe instanceof ClosedChannelException ||
ioe instanceof SocketException ||
ioe instanceof ConnectException ||
ioe instanceof ConnectIOException ||
ioe instanceof EOFException)
return true;
return false;
|
private boolean | isExiting()
return exit;
|
private void | readNotification()
Object obj = null;
try {
objIn = new ObjectInputStream(in);
obj = objIn.readObject();
} catch (IOException ioe) {
String msg = ioe.getMessage();
if (msg != null && msg.indexOf("EOF") != -1)
throw (new EOFException(msg));
throw ioe;
} catch (ClassNotFoundException notfound) {
// Ignore; Unknown Object ???
return;
}
NotificationWrapper wrapr = (NotificationWrapper) obj;
if (wrapr.getType() == NotificationWrapper.WAIT) {
return;
}
mgr.raiseEvent(wrapr);
|
public boolean | reinit()Reinitialized the connection, if the connection is dropped.
This method is invoked from ClientNotificationManager every time the client
invokes a method on MBeanServerConnection.
if (connected)
return true;
timedout = false;
try {
connect();
} catch (IOException ioe) {
timedout = true;
throw ioe;
}
nReconnected = 0;
receiveThr = new Thread(this);
receiveThr.start();
return true;
|
public void | run()The notification receiver thread loop.
This loop, if client has not called JMXConnector.close, will
try to read a notification message from the connection and notify
the ClientNotificationManager to dispatch the notification.
while (!isExiting()) {
try {
connect();
readNotification();
} catch (IOException ioe) {
if (isExiting())
break;
ioe.printStackTrace();
if (ioe instanceof SocketTimeoutException) {
timedout = true;
break;
}
if (isDisconnected(ioe)) {
connected = false;
nReconnected++;
if (nReconnected > 3) {
timedout = true;
break;
}
continue;
} else if (isExiting()) {
break;
}
}
}
|
private void | sendCloseMessage()
connect("close", true);
|