org.apache.derby.iapi.services.context
Class ContextService

java.lang.Object
  extended byorg.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.


Field Summary
private  java.util.HashSet allContexts
           
private  HeaderPrintWriter errorStream
           
private static ContextService factory
           
(package private)  java.lang.ThreadLocal threadContextList
          Maintains a list of all the contexts that this thread has created and/or used.
 
Constructor Summary
ContextService()
           
 
Method Summary
private  boolean addToThreadList(java.lang.Thread me, ContextManager associateCM)
           
static Context getContext(java.lang.String contextId)
          Find the context with the given name in the context service factory loaded for the system.
static Context getContextOrNull(java.lang.String contextId)
          Find the context with the given name in the context service factory loaded for the system.
 ContextManager getCurrentContextManager()
          Get current Context Manager
static ContextService getFactory()
           
 ContextManager newContextManager()
          It's up to the caller to track this context manager and set it in the context manager list using setCurrentContextManager.
 void notifyAllActiveThreads(Context c)
           
(package private)  void removeContext(ContextManager cm)
           
 void resetCurrentContextManager(ContextManager cm)
           
 void setCurrentContextManager(ContextManager cm)
           
static void stop()
          So it can be given to us and taken away...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

factory

private static ContextService factory

errorStream

private 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: 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.

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
Constructor Detail

ContextService

public ContextService()
Method Detail

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.

Returns:
The requested context, null if it doesn't exist.

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.

Returns:
The requested context, null if it doesn't exist.

getCurrentContextManager

public ContextManager getCurrentContextManager()
Get current Context Manager

Returns:
ContextManager 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)

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.