| Modifier and Type | Class and Description |
|---|---|
| private static class | ContextService.
Specialized stack class that contains context managers. |
| Modifier and Type | Field and Description |
|---|---|
| private HashSet | allContexts
Collection of all ContextManagers that are open in the complete Derby system. |
| private HeaderPrintWriter | |
| private static ContextService | |
| private ThreadLocal | threadContextList
Maintains a list of all the contexts that this thread has created and/or used. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | Returns: True if the nesting level is to be represented in the ContextManager.activeCount field. False if not.The current thread (passed in a me) is setting associateCM to be its current context manager. |
| public static Context | Returns: The requested context, null if it doesn't exist.The handle on the context contextId)Find the context with the given name in the context service factory loaded for the system. |
| public static Context | Returns: The requested context, null if it doesn't exist.The handle on the context contextId)Find the context with the given name in the context service factory loaded for the system. |
| public ContextManager | Returns: ContextManager current Context ManagerGet current Context Manager linked to the current Thread. |
| public static ContextService | |
| public ContextManager | Returns: a new context managerIt's up to the caller to track this context manager and set it in the context manager list using setCurrentContextManager. |
| public void | |
| pack-priv synchronized void | removeContext(ContextManager cm)
Remove a ContextManager from the list of all active contexts managers. |
| public void | resetCurrentContextManager(ContextManager
The context manager cm)Break the link between the current Thread and the passed in ContextManager. |
| public void | setCurrentContextManager(ContextManager
The context manager cm)Link the current thread to the passed in Contextmanager so that a subsequent call to getCurrentContextManager by the current Thread will return cm. |
| public static void |
| allContexts | back to summary |
|---|---|
| private HashSet<ContextManager> allContexts Collection of all ContextManagers that are open in the complete Derby system. A ContextManager is added when it is created with newContextManager and removed when the session is closed. | |
| errorStream | back to summary |
|---|---|
| private HeaderPrintWriter errorStream | |
| factory | back to summary |
|---|---|
| private static ContextService factory | |
| threadContextList | back to summary |
|---|---|
| private ThreadLocal<Object> threadContextList Maintains a list of all the contexts that this thread has created and/or used. The object stored in the thread local varys according how this thread has been used and will be one of:
There are two cases we are trying to optimise.
Single thread for Connection execution.
threadContextList.get() == cm
// while in JDBC engine code
cm.activeThread == Thread.currentThread();
cm.activeCount = 1;
J2EE single thread for lifetime of execution.
// thread executing request
threadContextList.get() == cm
// while in JDBC engine code
cm.activeThread == Thread.currentThread();
cm.activeCount = 1;
// other threads that have recently executed
// the same connection can have
threadContextList.get() == cm
cm.activeThread != Thread.currentThread();
Nested routine calls within single connection
threadContextList.get() == cm
// Within server-side JDBC code in a
// function called from another function/procedure
// called from an applications's statement
// (three levels of nesting)
cm.activeThread == Thread.currentThread();
cm.activeCount = 3;
Nested routine calls with the inner routine using a different connection to access a Derby database. Note nesting of orignal Contextmanager cm is changed from an activeCount of 2 to nesting within the stack once multiple ContextManagers are involved.
threadContextList.get() == stack {cm2,cm,cm}
cm.activeThread == Thread.currentThread();
cm.activeCount = -1; // nesting in stack
cm2.activeThread == Thread.currentThread();
cm2.activeCount = -1; // nesting in stack
Nested multiple ContextManagers, the code supports this, though it may not be possible currently to have a stack like this from SQL/JDBC.
threadContextList.get() == stack {cm3,cm2,cm,cm2,cm,cm}
cm.activeThread == Thread.currentThread();
cm.activeCount = -1; // nesting in stack
cm2.activeThread == Thread.currentThread();
cm2.activeCount = -1; // nesting in stack
cm3.activeThread == Thread.currentThread();
cm3.activeCount = -1; // nesting in stack
| |
| ContextService | back to summary |
|---|---|
| public ContextService() Create a new ContextService for a Derby system. Only a single system is active at any time. | |
| addToThreadList | back to summary |
|---|---|
| private boolean addToThreadList(Thread me, ContextManager associateCM) The current thread (passed in a me) is setting associateCM to be its current context manager. Sets the thread local variable threadContextList to reflect associateCM being the current ContextManager.
| |
| getContext | back to summary |
|---|---|
| public static Context getContext(String contextId) Find the context with the given name in the context service factory loaded for the system. | |
| getContextOrNull | back to summary |
|---|---|
| public static Context getContextOrNull(String contextId) Find the context with the given name in the context service factory loaded for the system. This version will not do any debug checking, but return null quietly if it runs into any problems. | |
| getCurrentContextManager | back to summary |
|---|---|
| public ContextManager getCurrentContextManager() Get current Context Manager linked to the current Thread. See setCurrentContextManager for details. Note that this call can be expensive and is only intended to be used in "stateless" situations. Ideally code has a reference to the correct ContextManager from another Object, such as a pushed Context.
| |
| getFactory | back to summary |
|---|---|
| public static ContextService getFactory() | |
| newContextManager | back to summary |
|---|---|
| public ContextManager newContextManager() It's up to the caller to track this context manager and set it in the context manager list using setCurrentContextManager. We don't keep track of it due to this call being made.
| |
| notifyAllActiveThreads | back to summary |
|---|---|
| public void notifyAllActiveThreads(Context c) | |
| removeContext | back to summary |
|---|---|
| pack-priv synchronized void removeContext(ContextManager cm) Remove a ContextManager from the list of all active contexts managers. | |
| resetCurrentContextManager | back to summary |
|---|---|
| public void resetCurrentContextManager(ContextManager cm) Break the link between the current Thread and the passed in ContextManager. Called in a pair with setCurrentContextManager, see that method for details.
| |
| setCurrentContextManager | back to summary |
|---|---|
| public void setCurrentContextManager(ContextManager cm) Link the current thread to the passed in Contextmanager
so that a subsequent call to getCurrentContextManager by
the current Thread will return cm.
ContextManagers are tied to a Thread while the thread
is executing Derby code. For example on most JDBC method
calls the ContextManager backing the Connection object
is tied to the current Thread at the start of the method
and reset at the end of the method. Once the Thread
has completed its Derby work the method resetCurrentContextManager
must be called with the same ContextManager to break the link.
Note that a subsquent use of the ContextManager may be on
a separate Thread, the Thread is only linked to the ContextManager
between the setCurrentContextManager and resetCurrentContextManager calls.
| |
| stop | back to summary |
|---|---|
| public static void stop() So it can be given to us and taken away... | |
| Access | Constructor and Description |
|---|---|
| private |
| ContextManagerStack | back to summary |
|---|---|
| private ContextManagerStack() | |