Methods Summary |
---|
private boolean | checkServerStatus()Check status of server stub file and refresh if needed.
boolean gotNew = false;
if (stubFile.exists()) {
long ts = stubFile.lastModified();
if (ts > stubFileTs) {
if (stubFile.canRead()) {
RemoteAdminChannel obj = readStub();
if (obj != null) {
gotNew = true;
stub = obj;
}
} else {
warn(FILE_READ_ERROR, stubFile.getName());
}
}
} else {
if (stub != null) {
stub = null;
}
}
return gotNew;
|
static void | debug(java.lang.String s)
logger.fine(s);
|
static void | debug(java.lang.String msgkey, java.lang.String obj1)
logger.log(Level.FINE, msgkey, obj1);
|
static void | debug(java.lang.String msgkey, java.lang.Object[] objarr)
logger.log(Level.FINE, msgkey, objarr);
|
static void | debug(java.lang.Throwable t)
logger.log(Level.FINE, t.getMessage(), t);
|
public int | getConflictedPort()Get the port where the conflict occurs.
int conflictedPort = 0;
boolean gotNew = checkServerStatus();
if (stub != null) {
try {
conflictedPort = stub.getConflictedPort(key);
} catch (RemoteException re) {
debug(CHANNEL_COMM_ERROR, stubFile.getName());
if (re.detail != null) {
trace(re.detail);
}
trace(re);
}
}
return conflictedPort;
|
public int | getInstanceStatusCode()Get server instance status code. If the instance can not be contacted
over rmi channel then the method reports that instance is not running.
The return value of this method is one of the constants
kInstanceStartingCode, kInstanceRunningCode, kInstanceStoppingCode or
kInstanceNotRunningCode from the class
com.sun.enterprise.admin.common.Status .
boolean gotNew = checkServerStatus();
int statusCode = Status.kInstanceNotRunningCode;
if (stub != null) {
try {
statusCode = stub.getServerStatusCode(key);
} catch (RemoteException re) {
debug(CHANNEL_COMM_ERROR, stubFile.getName());
if (re.detail != null) {
trace(re.detail);
}
trace(re);
} catch (IllegalArgumentException iae) {
debug(CHANNEL_COMM_ERROR, stubFile.getName());
trace(iae);
// This means that the key did not match. Attempt to read
// the key from the disk again to work around the race
// condition when the file is read on the client before the
// server has finished writing (and hence client has partial
// key). Another read updates the shared key on the client.
byte[] newKey = null;
try {
newKey = readSeed();
} catch (IOException ioe) {
debug(FILE_READ_ERROR, seedFile.getName());
trace(ioe);
}
if (newKey != null) {
key = newKey;
}
throw iae;
}
}
return statusCode;
|
public boolean | hasRestartedSince(long ts)Has the server instance restarted since specified timestamp. If instance
is not running, the method will return false. The return value is
accurate within the timespan as specified in getClientRefreshInterval()
of AdminChannel -- meaning that if the time period since instance restart
is less than the specified timespan then the method may return false
instead of true.
return hasRestartedSince(ts, false);
|
public boolean | hasRestartedSince(long ts, boolean refreshStub)Has the server instance restarted since specified timestamp. If instance
is not running, the method will return false. If refreshStub is true
then the method will attempt to read newer stub (if any) and will report
status using that. If refreshStub is false then the stub is not re-read
and return value is dependent on the cached stub (if any).
if (refreshStub) {
boolean gotNew = checkServerStatus();
}
boolean restarted = false;
if (stubFile != null) {
if (stubFileTs > ts) {
restarted = true;
}
}
return restarted;
|
public boolean | isAlive()Determines wheter the instance with given name is alive.
Really speaking, checks whether the RMI channel is responsive.
The method returns immediately with the status without any retries.
return isAlive(false);
|
public boolean | isAlive(boolean refreshStub)Determines whether the instance represented by this object is alive.
Unless the parameter refreshStub is true, the responsiveness of
instance is checked by using cached stub (if any) and if there is no
cached stub the method returns false.
if (refreshStub) {
boolean gotNew = checkServerStatus();
}
boolean isAlive = true;
if (stub != null) {
try {
stub.pingServer(key);
}
catch(RemoteException re) {
debug(re);
isAlive = false;
}
}
else {
isAlive = false;
}
return ( isAlive );
|
public boolean | isRestartNeeded()Is restart needed on the instance. The status is set by admin server and
instance just keeps track of it across admin server restarts. If the
instance has already restarted since admin server set the status, the
instance does not require restart (as expected).
boolean restartNeeded = false;
boolean gotNew = checkServerStatus();
if (stub != null) {
try {
restartNeeded = stub.isRestartNeeded(key);
} catch (RemoteException re) {
debug(CHANNEL_COMM_ERROR, stubFile.getName());
if (re.detail != null) {
trace(re.detail);
}
trace(re);
}
}
return restartNeeded;
|
private byte[] | readSeed()Read shared secret from file.
byte[] seed = null;
if (seedFile.exists() && seedFile.canRead()) {
// Seed file is updated after creating stub file and therefore
// it should only be read only if it has been modified since stub
// file was modified. NOTE: This relies on the fact that the
// server always (on every startup) writes seed file after stubfile.
long seedFileTs = seedFile.lastModified();
if (seedFileTs >= stubFileTs) {
FileInputStream fis = null;
try {
fis = new FileInputStream(seedFile);
seed = new byte[AdminChannel.SEED_LENGTH];
fis.read(seed);
} catch (IOException ioe) {
warn(AdminChannel.KEY_READ_ERROR);
debug(ioe);
seed = null;
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ioe) {
}
}
}
} else {
debug(SEED_FILE_OLDER,
new Long[] {new Long(seedFileTs), new Long(stubFileTs)});
}
} else {
warn(AdminChannel.KEY_READ_ERROR);
debug(FILE_READ_ERROR, seedFile.getName());
}
if (seed == null) {
String msg = localStrings.getString( "admin.server.core.channel.unable_initializing_key", seedFile );
throw new IOException( msg );
}
return seed;
|
private RemoteAdminChannel | readStub()Read stub from stub file
RemoteAdminChannel obj = null;
FileInputStream fis = null;
try {
stubFileTs = stubFile.lastModified();
fis = new FileInputStream(stubFile);
ObjectInputStream ois = new ObjectInputStream(fis);
obj = (RemoteAdminChannel)ois.readObject();
} catch (IOException ioe) {
warn(CLIENT_INIT_ERROR);
debug(ioe);
} catch (ClassNotFoundException cnfe) {
warn(CLIENT_INIT_ERROR);
debug(cnfe);
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ioe) {
}
}
}
try {
key = readSeed();
} catch (IOException ioe) {
warn(CLIENT_INIT_ERROR);
debug(ioe);
obj = null;
}
if (obj == null) {
stubFileTs = 0;
}
return obj;
|
public void | run()Auto refresh this rmi client.
while (autoRefresh) {
try {
Thread.sleep(autoRefreshInterval);
} catch (InterruptedException ie) {
warn(AUTO_REFRESH_INTR);
autoRefresh = false;
}
if (autoRefresh) {
checkServerStatus();
}
}
|
public com.sun.enterprise.admin.event.AdminEventResult | sendNotification(com.sun.enterprise.admin.event.AdminEvent event)Send specified event notification over admin channel
// Normal handling, send the event
boolean doRetry = true;
AdminEventResult result = null;
if (stub != null) {
try {
result = stub.sendNotification(key, event);
doRetry = false;
} catch (ServerException re) {
if ((re.detail != null) &&
(re.detail instanceof java.lang.IllegalArgumentException
|| re.detail instanceof java.lang.SecurityException)) {
doRetry = false;
warn(EVENT_NOTIFY_ERROR);
debug(re.detail);
} else {
if (re.detail != null) {
debug(re.detail);
}
debug(re);
}
} catch (RemoteException re) {
if (re.detail != null) {
debug(re.detail);
}
debug(re);
}
}
if (doRetry) {
// Normal processing did not work, try to get stub again and then
// attempt to send the event
boolean gotNew = checkServerStatus();
if (stub != null && gotNew) {
try {
result = stub.sendNotification(key, event);
} catch (RemoteException re) {
warn(EVENT_RENOTIFY_ERROR);
if (re.detail != null) {
debug(re.detail);
}
debug(re);
}
}
}
if (result == null) {
// Still couldn't communicate, set result appropriately
result = new AdminEventResult(event.getSequenceNumber());
result.setResultCode(AdminEventResult.TRANSMISSION_ERROR);
if (stub == null) {
result.addMessage(event.getEffectiveDestination(),
"Remote Stub is null");
}
}
return result;
|
public void | setRestartNeeded(boolean restartNeeded)Set restart needed status for a server instance. If the instance is not
running or if there is an error in communicating, the instance restart
status will not be changed. The status set by this method is preserved
in the instance across admin server restarts.
boolean gotNew = checkServerStatus();
if (stub != null) {
try {
stub.setRestartNeeded(key, restartNeeded);
} catch (RemoteException re) {
debug(CHANNEL_COMM_ERROR, stubFile.getName());
if (re.detail != null) {
trace(re.detail);
}
trace(re);
}
}
|
void | startAutoRefreshThread(long interval)Start auto refresh thread. The auto refresh thread refreshes the remote
stub if the stub file has changed on the disk.
if (interval <= 0) {
throw new IllegalArgumentException(INVALID_AUTO_REFRESH_INTERVAL);
}
autoRefresh = true;
autoRefreshInterval = interval;
if (autoRefreshThread != null && autoRefreshThread.isAlive()) {
return;
} else {
autoRefreshThread = new Thread(this);
autoRefreshThread.start();
}
|
void | stopAutoRefreshThread()Stop auto refresh thread.
autoRefresh = false;
|
static void | trace(java.lang.Throwable t)
logger.log(Level.FINEST, t.getMessage(), t);
|
public void | triggerServerExit()Triggers exit of the server VM. Server VM will client
that got the conflicted port number calls this method.
boolean gotNew = checkServerStatus();
if (stub != null) {
try {
stub.triggerServerExit(key);
} catch (RemoteException re) {
debug(CHANNEL_COMM_ERROR, stubFile.getName());
if (re.detail != null) {
trace(re.detail);
}
trace(re);
}
}
|
static void | warn(java.lang.String s)
logger.warning(s);
|
static void | warn(java.lang.String msgkey, java.lang.String obj1)
logger.log(Level.WARNING, msgkey, obj1);
|