{
long currTime = System.currentTimeMillis();
Iterator iterator = existingSessions.iterator();
FastStringBuffer debugBuffer = null;
boolean isDisconnectDebugEnabled =
Log.aribaweb_userstatus_disconnectTime.isDebugEnabled();
if (isDisconnectDebugEnabled) {
debugBuffer = new FastStringBuffer();
}
while (iterator.hasNext()) {
// check if the session is
// a) invalidated -- remove from list and send out disconnect
// b) is connected and has not been accessed in time --
// set disconnected and send out disconnect
// c) is disconnected, but has reconnected --
// set connected and send out reconnect
// d) needs to be added to the DB list
AWSession session = (AWSession)iterator.next();
long disconnectTime = session.disconnectTime();
if (session.isInvalidated()) {
trackSessionTerminate(session);
iterator.remove();
}
else if (disconnectTime != -1) {
// If disconnectTime is -1, then we don't know when the session
// is going to disconnect so don't attempt to update connected state.
// For these sessions, the only valid states are Connected and
// Disconnected, there is no pending disconnect or reconnect.
if (session.isConnected() &&
currTime > disconnectTime) {
session.setConnected(false);
// add to disconnect notification list
trackSessionPendingDisconnect(session);
}
else if (!session.isConnected() &&
currTime < session.disconnectTime()) {
session.setConnected(true);
trackSessionReconnect(session);
}
}
if (isDisconnectDebugEnabled) {
debugBuffer.append(session.debugDisconnectString());
debugBuffer.append("\n");
}
}
if (connectList != null) {
AWConcreteApplication.SessionWrapper sessOp = null;
while ((sessOp = connectList.poll()) != null) {
if (sessOp.op == AWConcreteApplication.SessionOp.Add) {
try {
trackSessionConnect(sessOp.session);
existingSessions.add(sessOp.session);
}
catch (UserSessionExistsException fae) {
//In development mode, always log this error.
//In production, log it only if debug is enabled.
if (AWConcreteApplication.IsDebuggingEnabled
|| Log.aribaweb_userstatus.isDebugEnabled())
{
Log.aribaweb_userstatus.error(fae.getMessage(), sessOp.callTrace);
}
}
}
else {
trackSessionTerminate(sessOp.session);
existingSessions.remove(sessOp.session);
}
if (isDisconnectDebugEnabled) {
debugBuffer.append(sessOp.session.debugDisconnectString());
debugBuffer.append("\n");
}
}
}
if (isDisconnectDebugEnabled) {
String debugString = debugBuffer.toString();
if (!StringUtil.nullOrEmptyOrBlankString(debugString)) {
Log.aribaweb_userstatus_disconnectTime.debug(debugString);
Log.aribaweb_userstatus_disconnectTime.setLevel(Log.WarnLevel);
}
}