|
Session Listeners
Definition
The application session listeners are objects instantiated at server startup and are
notified when a client session invokes the application for the first time and when the
client disconnects. We need a session listener to remove the subscription for disconnected
clients:
public class SubscriptionCleanup implements ISessionListener
{
/**
* Does nothing.
*
* @since 1.0
*/
public void init() throws InitSessionListenerException
{
// initialize the session listener
}
/**
* Does nothing.
*
* @since 1.0
*/
public void sessionOpened( IConnectionContext connection )
{
// allocate session data, for example create an empty shopping cart
}
/**
* Removes the session subscription when closed.
*
* @see com.accendia.iris.server.IConnectionContext
*
* @since 1.0
*/
public void sessionClosed( IConnectionContext connection )
{
SubscriptionManager.instance().removeSubscription( connection );
}
}
Session Listener Declaration
The session listener must be declared in the application.properties file:
Application.session_listener=cleanup
Application.session_listener.cleanup=com.accendia.datasynch.server.SubscriptionCleanup
Application.session_listener.cleanup.enabled=true
The listener name is not used by the application code but is useful in self documenting
the application.properties file.
|