Class ContextManager
- java.lang.Object
-
- org.apache.derby.iapi.services.context.ContextManager
-
public class ContextManager extends java.lang.Object
The ContextManager collects contexts as they are created. It maintains stacks of contexts by named ids, so that the top context of a given type can be returned. It also maintains a global stack so that contexts can be traversed in the order they were created.The first implementation of the context manager assumes there is only one thread to worry about and that the user(s) of the class only create one instance of ContextManager.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ContextManager.CtxStack
The CtxStack implement a stack on top of an ArrayList (to avoid the inherent overhead associated with java.util.Stack which is built on top of java.util.Vector, which is fully synchronized).
-
Field Summary
Fields Modifier and Type Field Description (package private) int
activeCount
Count of the number of setCurrentContextManager calls by a single thread, for nesting situations with a single active Contextmanager.(package private) java.lang.Thread
activeThread
The thread that owns this ContextManager, set by ContextService.setCurrentContextManager and reset by resetCurrentContextManager.private java.util.HashMap<java.lang.String,ContextManager.CtxStack>
ctxTable
HashMap that holds the Context objects.private HeaderPrintWriter
errorStream
private ErrorStringBuilder
errorStringBuilder
private int
extDiagSeverityLevel
private LocaleFinder
finder
private java.util.ArrayList<Context>
holder
List of all Contextsprivate int
logSeverityLevel
private java.util.Locale
messageLocale
(package private) ContextService
owningCsf
private boolean
shutdown
private java.lang.String
threadDump
-
Constructor Summary
Constructors Constructor Description ContextManager(ContextService csf, HeaderPrintWriter stream)
Constructs a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkInterrupt()
Check to see if we have been interrupted.boolean
cleanupOnError(java.lang.Throwable error, boolean diagActive)
clean up error and print it to derby.log.private void
flushErrorString()
Flush the built up error string to whereever it is supposed to go, and reset the error stringContext
getContext(java.lang.String contextId)
Obtain the last pushed Context object of the type indicated by the contextId argument.java.util.List<Context>
getContextStack(java.lang.String contextId)
Return an unmodifiable list reference to the ArrayList backing CtxStack object for this type of Contexts.int
getErrorSeverity(java.lang.Throwable error)
return the severity of the exception.java.util.Locale
getMessageLocale()
(package private) boolean
isEmpty()
Is the ContextManager empty containing no Contexts.void
popContext()
Remove the last pushed Context object, regardless of type.(package private) void
popContext(Context theContext)
Removes the specified Context object.void
pushContext(Context newContext)
Add a Context object to the ContextManager.private boolean
reportError(java.lang.Throwable t)
(package private) boolean
setInterrupted(Context c)
void
setLocaleFinder(LocaleFinder finder)
Set the locale for this context.void
setMessageLocale(java.lang.String localeID)
-
-
-
Field Detail
-
ctxTable
private final java.util.HashMap<java.lang.String,ContextManager.CtxStack> ctxTable
HashMap that holds the Context objects. The Contexts are stored with a String key.- See Also:
pushContext(Context)
-
holder
private final java.util.ArrayList<Context> holder
List of all Contexts
-
messageLocale
private java.util.Locale messageLocale
-
owningCsf
final ContextService owningCsf
-
logSeverityLevel
private int logSeverityLevel
-
extDiagSeverityLevel
private int extDiagSeverityLevel
-
errorStream
private HeaderPrintWriter errorStream
-
errorStringBuilder
private ErrorStringBuilder errorStringBuilder
-
threadDump
private java.lang.String threadDump
-
shutdown
private boolean shutdown
-
finder
private LocaleFinder finder
-
activeThread
java.lang.Thread activeThread
The thread that owns this ContextManager, set by ContextService.setCurrentContextManager and reset by resetCurrentContextManager. Only a single thread can be active in a ContextManager at any time, and the thread only "owns" the ContextManager while it is executing code within Derby. In the JDBC case setCurrentContextManager is called at the start of a JBDC method and resetCurrentContextManager on completion. Nesting within the same thread is supported, such as server-side JDBC calls in a Java routine or procedure. In that case the activeCount will represent the level of nesting, in some situations.
-
activeCount
int activeCount
Count of the number of setCurrentContextManager calls by a single thread, for nesting situations with a single active Contextmanager. If nesting is occuring with multiple different ContextManagers then this value is set to -1 and nesting is represented by entries in a stack in the ThreadLocal variable, threadContextList.- See Also:
ContextService.threadContextList
-
-
Constructor Detail
-
ContextManager
ContextManager(ContextService csf, HeaderPrintWriter stream)
Constructs a new instance. No CtxStacks are inserted into the hashMap as they will be allocated on demand.- Parameters:
csf
- the ContextService owning this ContextManagerstream
- error stream for reporting errors
-
-
Method Detail
-
pushContext
public void pushContext(Context newContext)
Add a Context object to the ContextManager. The object is added both to the holder list and to a stack for the specific type of Context.- Parameters:
newContext
- the new Context object
-
getContext
public Context getContext(java.lang.String contextId)
Obtain the last pushed Context object of the type indicated by the contextId argument.- Parameters:
contextId
- a String identifying the type of Context- Returns:
- The Context object with the corresponding contextId, or null if not found
-
popContext
public void popContext()
Remove the last pushed Context object, regardless of type. If there are no Context objects, no action is taken.
-
popContext
void popContext(Context theContext)
Removes the specified Context object. If the specified Context object does not exist, the call will fail.- Parameters:
theContext
- the Context object to remove.
-
isEmpty
final boolean isEmpty()
Is the ContextManager empty containing no Contexts.
-
getContextStack
public final java.util.List<Context> getContextStack(java.lang.String contextId)
Return an unmodifiable list reference to the ArrayList backing CtxStack object for this type of Contexts. This method allows fast traversal of all Contexts on that stack. The first element in the List corresponds to the bottom of the stack. The assumption is that the Stack will not be modified while it is being traversed.- Parameters:
contextId
- the type of Context stack to return.- Returns:
- an unmodifiable "view" of the ArrayList backing the stack
- See Also:
GenericLanguageConnectionContext.resetSavepoints()
,StatementContext.resetSavePoint()
-
cleanupOnError
public boolean cleanupOnError(java.lang.Throwable error, boolean diagActive)
clean up error and print it to derby.log. Extended diagnosis including thread dump to derby.log and javaDump if available, will print if the database is active and severity is greater than or equals to SESSTION_SEVERITY or as configured by derby.stream.error.extendedDiagSeverityLevel property- Parameters:
error
- the error we want to clean updiagActive
- true if extended diagnostics should be considered, false not interested of extended diagnostic information- Returns:
- true if the context manager is shutdown, false otherwise.
-
setInterrupted
boolean setInterrupted(Context c)
-
checkInterrupt
private void checkInterrupt()
Check to see if we have been interrupted. If we have then a ShutdownException will be thrown. This will be either the one passed to interrupt or a generic one if some outside source interrupted the thread.
-
setLocaleFinder
public void setLocaleFinder(LocaleFinder finder)
Set the locale for this context.
-
setMessageLocale
public void setMessageLocale(java.lang.String localeID) throws StandardException
- Throws:
StandardException
-
getMessageLocale
public java.util.Locale getMessageLocale()
-
flushErrorString
private void flushErrorString()
Flush the built up error string to whereever it is supposed to go, and reset the error string
-
reportError
private boolean reportError(java.lang.Throwable t)
-
getErrorSeverity
public int getErrorSeverity(java.lang.Throwable error)
return the severity of the exception. Currently, this method does not determine a severity that is not StandardException or SQLException.- Parameters:
error
- - Throwable error- Returns:
- int vendorcode/severity for the Throwable error - error/exception to extract vendorcode/severity. For error that we can not get severity, NO_APPLICABLE_SEVERITY will return.
-
-