EAF 7.4 Implementation

com.lutris.appserver.server
Class Enhydra

java.lang.Object
  extended by com.lutris.appserver.server.Enhydra

public class Enhydra
extends java.lang.Object

The Enhydra class provides static methods that allow each application to conviently get at their application object. It also provides access

This class implements dynamically scoped global variables, accessed via static methods. Which variable is accessed (and thus which Application object is returned) depends on the flow of control of the program before the access (the call stack).

Currently a hashtable keyed on the threads themselves is used to store the different Application, in Java 1.2 threads will have a field already available for storing client data.

Normal usage of this class is to call register() when a thread enters your application, then unRegister() when it leaves. It is very important that every register() is matched with an unRegister(), or else it will be a memory leak, threads that re-enter the application will have a stale Application (until the first register()), and an extra pointer to the Application will be left around, preventing garbage collection.

If no thread is passed in (the normal usage), the current thread is used. If your application creates new threads, these will not initially be associated with any Application. These new threads can be passed in to register(), to assocaiate them with an Application. You may call register() before calling start() on the thread.

To ensure that every register() is balanced with an unRegister(), the following code is recommended:

 Enhydra.register(application);
 try {
     doSomeWork();
 } finally {
     Enhydra.unRegister();
 }
 
This will ensure that the unRegister() is called even if an exception is thrown, but it will not interfere with the exception processing.

Since:
LBS1.8
Version:
$Revision: 1.6 $
Author:
Paul Morgan, Andy John

Constructor Summary
protected Enhydra()
          Prevent instantiation
 
Method Summary
static com.lutris.appserver.server.Application getApplication()
          Return the application object for current application.
static com.lutris.appserver.server.sql.DatabaseManager getDatabaseManager()
          Return the database manager object for current application.
static com.lutris.logging.LogChannel getLogChannel()
          Return the LogChannel in the current Application object, or a log channel to the facility "Enhydra" if there is no current Application set.
static com.lutris.appserver.server.session.SessionManager getSessionManager()
          Return the session manager object for current application.
static void register(com.lutris.appserver.server.Application app)
          Associate the given application with the current thread.
static void register(java.lang.Thread thread, com.lutris.appserver.server.Application app)
          Associate the given application with the given thread.
static void unRegister()
          Remove the association between the current thread and it's Application.
static void unRegister(java.lang.Thread thread)
          Remove the association between the specified thread and it's Application.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Enhydra

protected Enhydra()
Prevent instantiation

Method Detail

register

public static void register(com.lutris.appserver.server.Application app)
Associate the given application with the current thread. After this call, calls to getApplication() made by this thread will return app. Be sure to call unRegister() when you are done with the thread. This must be called before the any calls to getApplication().

Parameters:
app - The Application object to associate with the current thread. This Application will be returned by calls made by this thread to getApplication().

register

public static void register(java.lang.Thread thread,
                            com.lutris.appserver.server.Application app)
Associate the given application with the given thread. After this call, calls to getApplication() made by the specified thread thread will return app. Be sure to call unRegister() when you are done with the thread. This must be called before the thread calls getApplication().

Parameters:
thread - the thread to associate with app.
app - the Application object to associate with the specified thread. This Application will be returned by calls made by this thread to getApplication().

unRegister

public static void unRegister()
Remove the association between the current thread and it's Application. This must be called when the thread is done using this Enhydra class. The current thread should not call getApplication() after this.


unRegister

public static void unRegister(java.lang.Thread thread)
Remove the association between the specified thread and it's Application. This must be called when the thread is done using this Enhydra class. The thread should not call getApplication() after this.

Parameters:
thread - the thread to operate on.

getApplication

public static com.lutris.appserver.server.Application getApplication()
Return the application object for current application. Returns null if there is no Application currently associated with the current thread.

Returns:
The application object.

getDatabaseManager

public static com.lutris.appserver.server.sql.DatabaseManager getDatabaseManager()
Return the database manager object for current application. Returns null if there is no database manager associated with the application or there is no application associated with the current thread.

Returns:
The database manager object if available else null.

getSessionManager

public static com.lutris.appserver.server.session.SessionManager getSessionManager()
Return the session manager object for current application. Returns null if there is no session manager associated with the application or there is no application associated with the current thread.

Returns:
The session manager object if available else null.

getLogChannel

public static com.lutris.logging.LogChannel getLogChannel()
Return the LogChannel in the current Application object, or a log channel to the facility "Enhydra" if there is no current Application set.

Returns:
The LogChannel for the current application, or a generic LogChannel.

EAF 7.4 Implementation