wt.method
Class MethodContext

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended bywt.method.MethodContext
All Implemented Interfaces:
Cloneable, Map, Serializable

public class MethodContext
extends Hashtable

Context corresponding to an active method invocation in the method server. This class maintains an association between threads and resources currently assigned to the threads such as a database connections.

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 unmarshaling begins and is unregisted after the reply has been marshaled back to the client. For non-RMI contexts (CORBA or internal), the context must be explicitly constructed and unregistered.

Supported API: true
Extendable: false

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Hashtable
 
Field Summary
private  String accessLogDetail
           
private  MethodArgs args
           
private  Object authentication
           
private static int boostedCount
           
private  PropertyChangeSupport changeSupport
           
private  String clientHost
           
private  Object connection
           
private static Hashtable contexts
           
private static POMHandlerIfc defaultPomHandler
           
 Object effectivePrincipal
          Convenience slot for efficient per-thread retrieval of effective principal.
private static MethodContext head
           
private  long id
           
private static MethodContext lastBoosted
           
private static boolean MANAGE_THREAD_PRIORITIES
           
private  MethodContext next
           
private static long nextId
           
private static boolean NOT_UNREGISTERED_TRACEBACK
           
private static int NUMBER_PRIORITY_THREADS
           
private static String POM_HANDLER
           
private static Object POM_HANDLER_KEY
           
private  POMHandlerIfc pomHandler
           
private  MethodContext prev
           
private static MethodContext previous
           
static String REGISTERED
          Key for property reflecting whether the context is registered (active).
private  Exception registerTraceback
           
private static String RESOURCE
           
private  ObjectOutput resultOutputStream
           
 Object sessionContext
          Convenience slot for efficient per-thread retrieval of session context.
private static int SYNCH_VERBOSE_THRESHOLD
           
private static MethodContext tail
           
(package private)  Thread thread
           
private static int total
           
private static String USER_NAME_KEY
           
private static boolean VERBOSE
           
 
Fields inherited from class java.util.Hashtable
 
Constructor Summary
private MethodContext()
           
(package private) MethodContext(MethodArgs method_args)
          Constructor used while RMI method arguments are being unmarshaled.
  MethodContext(String client_host, Object authentication)
          Public constructor for use by non-RMI threads Associates the current thread with a new context.
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener listener)
          Add a PropertyChangeListener to the listener list.
 void clearConnection()
          Clear datastore connection associated with this context without returning it to free pool.
 void freeConnection()
          Free datastore connection associated with this context, making it available for other threads.
 String getAccessLogDetail()
          Get detail message for access log.
static int getActiveCount()
          Get the total number of currently active method contexts.
 Object[] getArgObjects()
          Get the argument array for the method invoked by this context.
 Class[] getArgTypes()
          Get the argument class array for the method invoked by this context.
 Object getAuthentication()
          Get the authentication object associated with this context.
 String getClientHost()
          Get the client host name for this context.
 Object getConnection()
          Get datastore connection associated with this method context.
static MethodContext getContext()
          Get the current thread's method context.
static MethodContext getContext(long id)
          Get the method context with the given id.
static MethodContext getContext(Thread thread)
          Get the method context for the given thread.
private  POMHandlerIfc getCurrentPomHandler()
           
static POMHandlerIfc getDefaultPomHandler()
          Get default POM handler.
 long getId()
          Get the id of this context.
static Enumeration getKeys()
          Get an Enumeration of all MethodContext keys.
 MethodArgs getMethodArgs()
          Get the RMI method arguments associated with this context.
 Object getPom()
          Get PersistentObjectManager associated with this context.
static POMHandlerIfc getPomHandler()
          Get POM handler for the current WTContext.
(package private)  ObjectOutput getResultOutputStream()
          Get the result marshalling object output stream.
 String getTargetClassName()
          Get the name of the target class invoked by this context.
 String getTargetMethodName()
          Get the name of the target method invoked by this context.
 Object getTargetObject()
          Get the target object of the method invoked by this context.
static int getTotalConnections()
          Get the total number of datastore connections associated with the POM handler for the current WTContext.
static int getTotalCount()
          Get the total number of method contexts that have existed.
 String getUserName()
           
 void interrupt()
          Interrupt thread corresponding to this context

Supported API: false
 Object put(Object key, Object value)
          Override Hashtable.put to add property change support.
private  void register()
           
 Object remove(Object key)
          Override Hashtable.remove to add property change support.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Remove a PropertyChangeListener from the listener list.
 boolean sendFeedback(MethodFeedback feedback)
          Send feedback objects to RMI client while call is being processed A return value of false indicates that the client has disconnected.
 void setAccessLogDetail(String detail)
          Set detail message for access log.
 void setAllowRedirect(boolean flag)
          Set whether or not the call corresponding to this context can be redirected for load leveling purposes.
 void setAuthentication(Object auth)
          Set the authentication object associated with this context.
 void setConnection(Object connection)
          Set datastore connection associated with this context.
static void setDefaultPomHandler(POMHandlerIfc pom_handler)
          Set default POM handler that applies to all WTContext.
static void setPomHandler(POMHandlerIfc pom_handler)
          Set POM handler for the current WTContext.
private static void setPriority(Thread thread, int priority)
           
(package private)  void setResultOutputStream(ObjectOutput output_stream)
          Set the result marshalling object output stream for use when sending feedback.
 void setThread(Thread thread)
          Set the thread associated with this context.
 void unregister()
          Unregister this method context.
static void unregisterDeadContexts()
          Unregister any method contexts corresponding to terminated threads.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, putAll, rehash, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

VERBOSE

private static final boolean VERBOSE

MANAGE_THREAD_PRIORITIES

private static final boolean MANAGE_THREAD_PRIORITIES

NUMBER_PRIORITY_THREADS

private static final int NUMBER_PRIORITY_THREADS

POM_HANDLER

private static final String POM_HANDLER

NOT_UNREGISTERED_TRACEBACK

private static final boolean NOT_UNREGISTERED_TRACEBACK

head

private static final MethodContext head

tail

private static final MethodContext tail

lastBoosted

private static MethodContext lastBoosted

boostedCount

private static int boostedCount

USER_NAME_KEY

private static final String USER_NAME_KEY
See Also:
Constant Field Values

SYNCH_VERBOSE_THRESHOLD

private static int SYNCH_VERBOSE_THRESHOLD

REGISTERED

public static String REGISTERED
Key for property reflecting whether the context is registered (active). Property change listeners can use this property key to be informed when a context goes out of scope. When the context is unregistered, a property change is fired for this property going from Boolean.TRUE to Boolean.FALSE.


POM_HANDLER_KEY

private static final Object POM_HANDLER_KEY

defaultPomHandler

private static POMHandlerIfc defaultPomHandler

contexts

private static final Hashtable contexts

total

private static int total

previous

private static MethodContext previous

nextId

private static long nextId

id

private long id

thread

Thread thread

args

private MethodArgs args

clientHost

private String clientHost

authentication

private Object authentication

resultOutputStream

private ObjectOutput resultOutputStream

pomHandler

private POMHandlerIfc pomHandler

connection

private Object connection

changeSupport

private PropertyChangeSupport changeSupport

accessLogDetail

private String accessLogDetail

prev

private MethodContext prev

next

private MethodContext next

registerTraceback

private Exception registerTraceback

sessionContext

public Object sessionContext
Convenience slot for efficient per-thread retrieval of session context. This is a public field that is logically owned by the wt.session package.


effectivePrincipal

public Object effectivePrincipal
Convenience slot for efficient per-thread retrieval of effective principal. This is a public field that is logically owned by the wt.session package.

Constructor Detail

MethodContext

private MethodContext()

MethodContext

MethodContext(MethodArgs method_args)
        throws ServerNotActiveException
Constructor used while RMI method arguments are being unmarshaled. Assumes the current thread is the RMI dispatch thread for current call.

Supported API: false

Parameters:
method_args - the RMI MethodArgs object being unmarshalled

MethodContext

public MethodContext(String client_host,
                     Object authentication)
Public constructor for use by non-RMI threads Associates the current thread with a new context. The thread is responsible for unregistering itself before termination.

Supported API: true

Parameters:
client_host - calling client hostname - may be needed to validate authentication
authentication - opaque authentication object
See Also:
Authenticator
Method Detail

register

private void register()

unregister

public void unregister()
Unregister this method context. Active database connection is automatically freed.

Supported API: true


setPriority

private static void setPriority(Thread thread,
                                int priority)

unregisterDeadContexts

public static void unregisterDeadContexts()
Unregister any method contexts corresponding to terminated threads. Should be called occassionally if there is any chance that registered contexts are not being unregistered in finally blocks.

Supported API: false


setThread

public void setThread(Thread thread)
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

public static MethodContext getContext()
Get the current thread's method context. Throws a runtime exception if there is no active context.

Supported API: true


getContext

public static MethodContext getContext(long id)
Get the method context with the given id. Returns null if the identified context no longer exists.

Supported API: false


getContext

public static MethodContext getContext(Thread thread)
Get the method context for the given thread. Returns null if no context is registered for the thread.

Supported API: false


getId

public long getId()
Get the id of this context.

Supported API: false


getMethodArgs

public MethodArgs getMethodArgs()
Get the RMI method arguments associated with this context. Returns null if this context is not associated with an RMI call.

Supported API: false


getTargetMethodName

public String 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

public String 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

public Object 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

public Object[] 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

public Class[] 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

public String getClientHost()
Get the client host name for this context. Returns null if this is not a client call (internal context).

Supported API: true


getAuthentication

public Object getAuthentication()
Get the authentication object associated with this context. Returns null if no authentication is associated with this call.

Supported API: true


setAuthentication

public void setAuthentication(Object auth)
Set the authentication object associated with this context.

Supported API: true


setResultOutputStream

void setResultOutputStream(ObjectOutput output_stream)
Set the result marshalling object output stream for use when sending feedback. This is called when result marshalling begins.


getResultOutputStream

ObjectOutput getResultOutputStream()
Get the result marshalling object output stream.


getActiveCount

public static int getActiveCount()
Get the total number of currently active method contexts. Active contexts exist for calls that are currently executing.

Supported API: false


getTotalCount

public static int getTotalCount()
Get the total number of method contexts that have existed. This represents the total number of method invocations that have been processed.

Supported API: false


sendFeedback

public boolean sendFeedback(MethodFeedback feedback)
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

interrupt

public void interrupt()
Interrupt thread corresponding to this context

Supported API: false


setAllowRedirect

public void setAllowRedirect(boolean flag)
Set whether or not the call corresponding to this context can be redirected for load leveling purposes. This method must be called prior to the target method being dispatched, so it must occur while arguments are still being unmarshaled. The default is true, allowing the call to be redirected before the target method is invoked. Calls whose arguments consume a stream of data during marshaling should call this method to prevent any redirection attempts.

Supported API: false


getAccessLogDetail

public String getAccessLogDetail()
Get detail message for access log. Returns empty string if not set.

Supported API: false


setAccessLogDetail

public void setAccessLogDetail(String detail)
Set detail message for access log. If an access log is being written, the detail message may be included.

Supported API: false

Parameters:
detail - message

getPomHandler

public static POMHandlerIfc getPomHandler()
Get POM handler for the current WTContext. The POM handler is responsible for getting and freeing database connections on behalf of a WTContext. If not explicitly set for the current WTContext, the default handler is returned.

Supported API: false


setPomHandler

public static void setPomHandler(POMHandlerIfc pom_handler)
Set POM handler for the current WTContext. The POM handler is responsible for getting and freeing database connections. Setting to null causes use of default POM handler.

Supported API: false


getDefaultPomHandler

public static POMHandlerIfc getDefaultPomHandler()
Get default POM handler.

Supported API: false


setDefaultPomHandler

public static void setDefaultPomHandler(POMHandlerIfc pom_handler)
Set default POM handler that applies to all WTContext. Setting to null causes class default to be used.

Supported API: false


getCurrentPomHandler

private POMHandlerIfc getCurrentPomHandler()

getPom

public Object getPom()
              throws Exception
Get PersistentObjectManager associated with this context.

Supported API: false

Throws:
Exception - any exception thrown by POMHandler.getPom

getConnection

public Object getConnection()
                     throws Exception
Get datastore connection associated with this method context. If one is not currently assigned to this context, a free connection will be acquired.

Supported API: false

Throws:
Exception - any exception thrown by POMHandler.getConnection

freeConnection

public void freeConnection()
Free datastore connection associated with this context, making it available for other threads.

Supported API: false


setConnection

public void setConnection(Object connection)
Set datastore connection associated with this context.

Supported API: false


clearConnection

public void clearConnection()
Clear datastore connection associated with this context without returning it to free pool.

Supported API: false


getTotalConnections

public static int getTotalConnections()
Get the total number of datastore connections associated with the POM handler for the current WTContext.

Supported API: false


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Add a PropertyChangeListener to 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 - the PropertyChangeListener to be added

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Remove a PropertyChangeListener from the listener list.

Supported API: true

Parameters:
listener - the PropertyChangeListener to be removed

put

public Object put(Object key,
                  Object value)
Override Hashtable.put to add property change support.

Supported API: true

Parameters:
key - the hashtable key
value - the value
Returns:
the previous value of the specified key in this hashtable, or null if it did not have one.
See Also:
Hashtable

remove

public Object remove(Object key)
Override Hashtable.remove to add property change support.

Supported API: true

Parameters:
key - the key that needs to be removed
Returns:
the value to which the key had been mapped in this hashtable, or null if the key did not have a mapping.
See Also:
Hashtable

getUserName

public String getUserName()

getKeys

public static Enumeration getKeys()
Get an Enumeration of all MethodContext keys.

Supported API: false