Package wt.method

Class MethodContext

All Implemented Interfaces:
Serializable, Cloneable, Map<Object,Object>

public final class MethodContext extends Hashtable<Object,Object>
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 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:
  • Field Details

    • mbean

      public final MethodContextMBean mbean
      JMX management interface object for this context

      Supported API: true
  • Constructor Details

  • Method Details

    • setParentMethodContext

      public void setParentMethodContext(MethodContext parentMethodContext)
      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

      public void unregister(Throwable server_exception)
      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 (via setExceptionIfUnset(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

      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
      Throws:
      RuntimeException - if there is no active context for the current thread
    • getException

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

      public void setExceptionIfUnset(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.

      Supported API: true
      See Also:
    • getContext

      public static MethodContext getContext(Thread thread)
      Get the method context for the given thread.

      Supported API: true
      Returns:
      null if no context is registered for the thread
    • 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
    • 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
    • getAccessLogDetail

      public String getAccessLogDetail()
      Get detail message describing this method context; primarily used in logging.

      Supported API:true
    • setAccessLogDetail

      public void setAccessLogDetail(String detailMessage)
      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

      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
      Specified by:
      put in interface Map<Object,Object>
      Overrides:
      put in class Hashtable<Object,Object>
      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:
    • remove

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

      Supported API: true
      Specified by:
      remove in interface Map<Object,Object>
      Overrides:
      remove in class Hashtable<Object,Object>
      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:
    • getSessionContext

      public Object getSessionContext()
      Retrieve SessionContext associated with this MethodContext, if any, else simply returns null.

      Supported API: true