|
EAF 7.4 Implementation | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lutris.appserver.server.Enhydra
public class Enhydra
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.
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 |
---|
protected Enhydra()
Method Detail |
---|
public static void register(com.lutris.appserver.server.Application app)
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()
.
app
- The Application object to associate with the
current thread. This Application will be returned by calls made
by this thread to getApplication()
.public static void register(java.lang.Thread thread, com.lutris.appserver.server.Application app)
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()
.
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()
.public static void unRegister()
getApplication()
after this.
public static void unRegister(java.lang.Thread thread)
getApplication()
after this.
thread
- the thread to operate on.public static com.lutris.appserver.server.Application getApplication()
public static com.lutris.appserver.server.sql.DatabaseManager getDatabaseManager()
public static com.lutris.appserver.server.session.SessionManager getSessionManager()
public static com.lutris.logging.LogChannel getLogChannel()
|
EAF 7.4 Implementation | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |