Listeners and Events
Listener objects and event objects allow an application to respond directly to certain events. An event encapsulates information about a specific event in the HydraExpress servlet container, such as the container constructing a new session. A listener receives an event instance from the servlet container when an event occurs. Together, these two groups of classes provide a mechanism for reacting to events within a context independently of any particular request or any particular servlet. Further, some events occur outside of any servlet, and these events can only be handled by using a listener.
For example, a listener can assign a database connection to a new client when the client connects. When the client has been inactive for a certain period of time, the listener can close the connection. This approach is appealing for two reasons. First, the individual servlets in the context do not need to contain code for creating and closing connections. Second, a servlet is only active while processing a request and therefore cannot detect events, such as a timeout, that occur while no request is active.
HydraExpress provides base classes for creating listeners that respond to events that act upon sessions or contexts. For a discussion on programming listeners and handling events, see
Implementing a Filter.