Class MethodContext
- All Implemented Interfaces:
Serializable,Cloneable,Map<Object,Object>
This class extends java.util.Hashtable so it can be used to maintain thread
local storage that pertains to a particular method invocation. Methods are free to store
whatever values they need under unique keys with confidence that the references will be
freed when this context is unregistered.
For RMI calls, it is created immediately before argument unmarshalling begins and is
unregistered after the reply has been marshaled back to the client. For non-RMI contexts,
the context must be explicitly constructed and unregistered.
Supported API: true
Extendable: false
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAutoCloseableimplementation for by-passing access control for a clearly delimited scope, restoring the previous access control enforcement state upon leaving this scope. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal MethodContextMBeanJMX management interface object for this context
Supported API: true -
Constructor Summary
ConstructorsConstructorDescriptionMethodContext(String client_host, Object authentication) Public constructor for use by non-RMI threads. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd aPropertyChangeListenerto the listener list.Get detail message describing this method context; primarily used in logging.Object[]Get the argument array for the method invoked by this context.Class[]Get the argument class array for the method invoked by this context.Get the authentication object associated with this context.Get the client host name for this context.static MethodContextGet the current thread's method context.static MethodContextgetContext(Thread thread) Get the method context for the given thread.Returns the exception that occurred during process of the method context.RetrieveSessionContextassociated with this MethodContext, if any, else simply returns null.Get the name of the target class invoked by this context.Get the name of the target method invoked by this context.Get the target object of the method invoked by this context.OverrideHashtable.putto add property change support.booleanReturns false when the method context has a database connection but it is in the middle of a transaction (or LOB streaming) and thus cannot safely be released; otherwise returns true.static booleanReturns false when the method context has a database connection but it is in the middle of a transaction (or LOB streaming) and thus cannot safely be released; otherwise returns true.OverrideHashtable.removeto add property change support.voidRemove aPropertyChangeListenerfrom the listener list.booleansendFeedback(MethodFeedback feedback) Send feedback objects to RMI client while call is being processed A return value of false indicates that the client has disconnected.voidsetAccessLogDetail(String detailMessage) Set detail message describing this method context; primarily used in logging.voidsetAuthentication(Object auth) Set the authentication object associated with this context.voidsetExceptionIfUnset(Throwable server_exception) Sets exception associated with this MethodContext except where a non-null exception is already set in the MethodContext in which case the existing exception will not be overwritten/replaced.voidsetParentMethodContext(MethodContext parentMethodContext) Allows one to associate this method context with a parent method context for purposes of performance and troubleshooting instrumentation and logging.voidSet the thread associated with this context.voidUnregisters this method context.voidunregister(Throwable server_exception) Unregisters this method context.Methods inherited from class java.util.Hashtable
clear, clone, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, size, toString, values
-
Field Details
-
mbean
JMX management interface object for this context
Supported API: true
-
-
Constructor Details
-
MethodContext
Public constructor for use by non-RMI threads.Associates the current thread with a new method context. The thread is responsible for unregistering itself via
unregister()or, preferably,unregister(java.lang.Throwable)before termination.One should also be certain that a method context is not already associated with the thread in question before creating a new one.
Supported API: true- Parameters:
client_host- calling client hostname - may be needed to validate authenticationauthentication- opaque authentication object- See Also:
-
-
Method Details
-
setParentMethodContext
Allows one to associate this method context with a parent method context for purposes of performance and troubleshooting instrumentation and logging. For instance, if this method context is within a background thread and doing work solely on behalf of another method context, then it would be appropriate to call this method to establish this relationship. This method should be called from the thread this MethodContext is associated with and with a non-null parentMethodContext.
Supported API: true- Parameters:
parentMethodContext- Method context to associate as the parent of this method context
-
unregister
Unregisters this method context. Active database connection is automatically released.One must be certain to unregister each MethodContext one creates even if an exception or error is thrown. One must therefore use a try/finally pattern as in the following code example.
Throwable throwable = null; final MethodContext methodContext = new MethodContext(); try { // call Windchill APIs } catch ( Throwable t ) // catch all exceptions and errors { throwable = t; throw t; // rethrow whatever we caught } finally { methodContext.unregister( throwable ); }This method is preferred to
unregister(java.lang.Throwable)because it allows one to easily associate any error occurring within the try block with the method context and therefore its completion status and logging.
Supported API: true- Parameters:
server_exception- Throwable to associate with method context status (viasetExceptionIfUnset(java.lang.Throwable))
-
unregister
public void unregister()Unregisters this method context. Active database connection is automatically released.One must be certain to unregister each MethodContext one creates even if an exception or error is thrown and must therefore use a try/finally pattern as in the following code example.
final MethodContext methodContext = new MethodContext( ... ); try { // call various Windchill APIs } finally { methodContext.unregister(); }Also note that
unregister(java.lang.Throwable)is preferred to this method as it allows one to associate any error occurring within the try block with the method context and therefore its completion status and logging.
Supported API: true- See Also:
-
setThread
Set the thread associated with this context. This can be used to hand control of this operation to another thread. The current thread will no longer have an associated method context. Thread priorities are not changed.
Supported API: true- Parameters:
thread- the thread for this context
-
getContext
Get the current thread's method context. Throws a runtime exception if there is no active context.
Supported API: true- Throws:
RuntimeException- if there is no active context for the current thread
-
getException
Returns the exception that occurred during process of the method context. This is available only after this has been caught during various points in the method context lifecycle and stored in the method context and is provided primarily to obtain this information upon method context completion.
Supported API: true -
setExceptionIfUnset
Sets exception associated with this MethodContext except where a non-null exception is already set in the MethodContext in which case the existing exception will not be overwritten/replaced.
Supported API: true- See Also:
-
getContext
Get the method context for the given thread.
Supported API: true- Returns:
- null if no context is registered for the thread
-
getTargetMethodName
Get the name of the target method invoked by this context. Returns null if this context is not associated with a client call.
Supported API: true -
getTargetClassName
Get the name of the target class invoked by this context. Returns null if this context is not associated with a client call.
Supported API: true -
getTargetObject
Get the target object of the method invoked by this context. Returns null if this context is not associated with a client call. Throws a NullPointerException if called before the object is completely unmarshaled from the caller.
Supported API: true -
getArgObjects
Get the argument array for the method invoked by this context. Returns null if this context is not associated with a client call or there were no arguments. If called during argument unmarshaling, the array will exist but all elements may not have been set.
Supported API: true -
getArgTypes
Get the argument class array for the method invoked by this context. Returns null if this context is not associated with a client call or there were no arguments. If called during argument unmarshaling, the array will exist but all elements may not have been set.
Supported API: true -
getClientHost
Get the client host name for this context. Returns null if this is not a client call (internal context).
Supported API: true -
getAuthentication
Get the authentication object associated with this context. Returns null if no authentication is associated with this call.
Supported API: true -
setAuthentication
Set the authentication object associated with this context.
Supported API: true -
sendFeedback
Send feedback objects to RMI client while call is being processed A return value of false indicates that the client has disconnected. Operations may wish to abort if the client is no longer waiting for a response.
Supported API: true- Parameters:
feedback- the feedback object- Returns:
- true if successfully written, false if an IOException was caught
-
getAccessLogDetail
Get detail message describing this method context; primarily used in logging.
Supported API:true -
setAccessLogDetail
Set detail message describing this method context; primarily used in logging.
Supported API:true -
releaseInactiveConnectionStatic
public static boolean releaseInactiveConnectionStatic()Returns false when the method context has a database connection but it is in the middle of a transaction (or LOB streaming) and thus cannot safely be released; otherwise returns true.
Supported API: true -
releaseInactiveConnection
public boolean releaseInactiveConnection()Returns false when the method context has a database connection but it is in the middle of a transaction (or LOB streaming) and thus cannot safely be released; otherwise returns true.
Supported API: true -
addPropertyChangeListener
Add aPropertyChangeListenerto the listener list. Property change events will be fired to all registered listeners whenever a value in this hashtable is added, changed, or removed.
Supported API: true- Parameters:
listener- thePropertyChangeListenerto be added
-
removePropertyChangeListener
Remove aPropertyChangeListenerfrom the listener list.
Supported API: true- Parameters:
listener- thePropertyChangeListenerto be removed
-
put
OverrideHashtable.putto add property change support.
Supported API: true -
remove
OverrideHashtable.removeto add property change support.
Supported API: true -
getSessionContext
RetrieveSessionContextassociated with this MethodContext, if any, else simply returns null.
Supported API: true
-