User Activity Monitoring and Auto Logoff

Activity monitoring works out of the box with most workbench views and will keep a user’s session alive as long as user input is happening. As long as the active ord target is pointing to a fox session, this will work out of the box. If you have written a custom view that uses a fox session, but is not loaded on a station component, special handling may be required.

ActivityListener

If your view is not loaded on a station component, any fox session(s) that it uses will not be automatically kept alive. In this case, your view will have to listen for user input, and notify the fox session(s) of the activity. This can be done using the ActivityListener interface. Any ActivityListener added to a BWbShell will have the activity() method called each time user activity is detected in Workbench. The userActivity() method on BFoxProxySession can then be called to keep the session alive.

public class BMyView extends BWbView implements ActivityListener
{
  @Override
  public void activated()
  {
    // add activity listener when activated
    getWbShell().addActivityListener(this);
  }

  @Override
  public void deactivated()
  {
    // remove activity listener when deactivated
    getWbShell().removeActivityListener(this);
  }
  
  @Override
  public void activity()
  {
    if (!isVisible())
    {
      // do not keep the session alive if this view is not visible
      return;
    }
    session.userActivity();
  }
  
  private BFoxProxySession session; // initialize and connect this session when view is loaded
}

NotifyListener

In addition to notifying the session to activity, it is also advisable to notify the user when the session is about to expire. Again, this functionality works out of the box for most views and special handling is only necessary if your view is not loaded on a station component. This can be done using the NotifyListener interface. Any NotifyListener added to a BFoxProxySession will have the onNotify() method called when the session will expire in 30 seconds or less. The notifyTimeout() method on a BWbShell can be used to display a dialog to the user stating that the session is about to timeout.

public class BMyView extends BWbView implements NotifyListener
{
  @Override
  public void doLoadValue(BObject value, Context cx)
  {
    // connect to the fox session
    ...
    session.addNotifyListener(this);
    ...
  }
  
  @Override
  public void deactivated()
  {
    // remove activity listener when deactivated
    session.removeNotifyListener(this);
  }
  
  @Override
  public void onNotify(BFoxProxySession session)
  {
    getWbShell().notifyTimeout(this, session);
  }
    
  private BFoxProxySession session; // initialize and connect this session when view is loaded
}

Pause Activity Monitor

You may have a scenario in which your view uses a fox session to do some processing that may take an extended period of time. In this case, the activity monitor can be “paused” so that the session will be kept alive until the processing is complete, even if user input is not occurring. It is important to make sure that the activity monitor is resumed after processing is complete, otherwise the session will not time out as expected.

public class BMyView extends BWbView
{
  @Override
  public void doLoadValue(BObject value, Context cx)
  {
    BFoxProxySession session;
    // connect to the fox session
    ...
    Object pauseToken = null;
    try
    {
      pauseToken = session.pauseActivityMonitor();
      ...
    }
    finally
    {
      // resume the activity monitor here so it will not be skipped if an exception is thrown
      session.resumeActivityMonitor(pauseToken);
    }
  }
}