java.lang.Object
org.apache.derby.iapi.services.context.ContextService
- public final class ContextService
- extends java.lang.Object
A set of static methods to supply easier access to contexts.
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
factory
private static ContextService factory
errorStream
private org.apache.derby.iapi.services.stream.HeaderPrintWriter errorStream
threadContextList
final java.lang.ThreadLocal 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:
- null - the thread no affiliation with a context manager.
- ContextManager - the thread created and possibly was used to execute this context manager.
This is a strong reference as it can be disassociated from the thread when the context is closed.
- WeakReference containing a ContextManager - the thread was used to execute this context manager.
This is a weak reference to allow the context to be closed and garbage collected without having
to track every single thread that used it or having to modify this list when resetting the current
context manager.
- WeakHashMap (key = ContextManager, value = Integer) - the thread has created and possibly executed any number of context managers.
This thread local is used to find the current context manager. Basically it provides
fast access to a list of candidate contexts. If one of the contexts has its activeThread
equal to the current thread then it is the current context manager.
If the thread has pushed multiple contexts (e.g. open a new non-nested Cloudscape connection
from a server side method) then threadContextList will contain a WeakHashMap. The value for each cm
will be a push order, with higher numbers being more recently pushed.
To support the case where a single context manager is pushed twice (nested connection),
the context manager keeps track of the number of times it has been pushed (set). Note that
our synchronization requires that a single context can only be accessed by a single thread at a time.
In the JDBC layer this is enforced by the synchronization on the connection object.
There are two cases we are trying to optimise.
- Typical JDBC client program where there a Connection is always executed using a single thread.
In this case this variable will contain the Connection's context manager
- Typical application server pooled connection where a single thread may use a connection from a pool
for the lifetime of the request. In this case this varibale will contain a WeakReference.
Need to support
CM1 OPTIMIZE
CM1,CM1 OPTIMIZE
CM1,CM1,CM1,CM1 OPTIMIZE
CM1,CM1,CM2
CM1,CM2,CM1,CM2
CM1,CM2,CM3,CM1
etc.
STACK for last 3
allContexts
private final java.util.HashSet allContexts
ContextService
public ContextService()
stop
public static void stop()
- So it can be given to us and taken away...
getFactory
public static ContextService getFactory()
getContext
public static Context getContext(java.lang.String contextId)
- Find the context with the given name in the context service factory
loaded for the system.
getContextOrNull
public static Context getContextOrNull(java.lang.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
public ContextManager getCurrentContextManager()
- Get current Context Manager
resetCurrentContextManager
public void resetCurrentContextManager(ContextManager cm)
addToThreadList
private boolean addToThreadList(java.lang.Thread me,
ContextManager associateCM)
setCurrentContextManager
public void setCurrentContextManager(ContextManager cm)
newContextManager
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
public void notifyAllActiveThreads(Context c)
removeContext
void removeContext(ContextManager cm)