There appears to be no way to truly "reset" the project timeout value
for a specific users. And since the session is not "reset," the event
gets triggered again every few minutes as NetDynamics scans for eligible
sessions to expire, or when any user activity takes place. Because of
this, one must code the onSessionExpiringEvent to SKIP the event over
and over again.
Moreover, since the user may be active again and then timeout again it
is not sufficient to merely set up a counter of some sort and decrement
it, since you don't know whether this is a "new" timeout or the
continuation of an "existing" timeout.
So, in lieu of a more efficient way, you have to track both the user
timeout value allowed AND the time since the last timeout event was fired.
I don't know if it is the best solution, but the code below does get the
job done.
------------------------------- // ---------------------------------
//[[SPIDER_EVENT<this_onSessionExpiringEvent>
public int this_onSessionExpiringEvent(CSpProjectSessionEvent event)
{
CSpSession sessObject = event.getActiveSession();
// get default project timeout value (in minutes)
CSpProject thisProject = CSpider.getProject("MyProject");
int project_timeout_value = thisProject.getSessionTimeout()/60000;
// get specific user's timeout value (in minutes.) Note that this // value is IN
ADDITION TO the project timeout value
int user_timeout_value = 0;
try
{
user_timeout_value = sessObject.get("UserTimeoutValue").intValue();
}
catch (Exception ex)
{
// ignore, always NullPointerException
}
if (user_timeout_value > 0) // can we extend this timeout?
{
CSpDatetime timeStamp = new CSpDatetime();
// determine if is this the first time through a new project timeout // event or
is there an active project level timeout event in process?
boolean new_timeout = true;
CSpDatetime userTimeoutStartTime = (CSpDatetime)
sessObject.get("UserTimeoutStartTime");
CSpDatetime lastTimeoutEvent = (CSpDatetime)
sessObject.get("LastTimeoutEvent");
if (lastTimeoutEvent != null)
{
// if more than the project timeout value has elapsed then this // user has had
activity since the last time through this event
new_timeout = Util.hasTimeElapsed(lastTimeoutEvent,
project_timeout_value);
}
// If this is a new (project) timeout, reset user clock & skip event. // Else, if
the user timeout period has not elapsed, skip event.
// Otherwise, let the event proceed and allow user session to expire.
if (new_timeout) // new project timeout, initialize user timeout values
{
sessObject.put("UserTimeoutStartTime", timeStamp);
sessObject.put("LastTimeoutEvent", timeStamp); return(SKIP);
}
else if (!Util.hasTimeElapsed(userTimeoutStartTime, user_timeout_value))
{
sessObject.put("LastTimeoutEvent", timeStamp); return(SKIP);
}
}
// add entry to log file and allow session to expire
String cust_name = "";
String cust_bill = "";
try // retrieve most likely USOs first
{
cust_name = sessObject.get("CurrentUser_Name").stringValue();
cust_bill = sessObject.get("CurrentUser_BillTo").stringValue();
}
catch (Exception ex)
{
// ignore, always NullPointerException
}
CSpLog.send (this, CSpLog.WARNING, "SESSION TIMEOUT " +
event.getProblematicSessionId().stringValue() + " >> " +
cust_bill + " " + cust_name);
return (PROCEED); // allow session to expire
}
//]]SPIDER_EVENT<this_onSessionExpiringEvent>
_________________________________________________________________________
For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
For dire need help, email: [EMAIL PROTECTED]