com.ibm.websphere.fabric.da.context
Class InContextServiceInvoker

java.lang.Object
  extended by com.ibm.websphere.fabric.da.context.ContextComponentSupport
      extended by com.ibm.websphere.fabric.da.context.InContextServiceInvoker
All Implemented Interfaces:
ServiceProxy

public abstract class InContextServiceInvoker
extends ContextComponentSupport
implements ServiceProxy

A support class that combines ContextComponentSupport and ServiceProxy into one. Designed to be instantiated for each new service invocation (see sample usage below).

 public class CurrencyExchangeContextualizer {
 
     private class CurrencyExchangeInvoker extends InContextServiceInvoker {
 
         // The constructor should include the set of params needed to invoke the target service
         public CurrencyExchangeInvoker(DataObject exchangeRequest) {
             super(exchangeRequest, null); 
             // Passing null for header. If WSDL declares an explicit header, then it 
             // would be passed to this class's constructor, and be propagated to super.
         }
     
         public Object invoke() {
             // Get a reference to the target service using the auto-generated locateService_xxx method
             Service svc = locateService_CurrencyExchangePartner();
             
             // Invoke the target service and return the response
             return svc.invoke("doExchange", getBody());
         }
     }
     
     // Other SCA Java component methods
     // ...
     
     public DataObject doExchange(DataObject exchangeRequest) {
         CurrencyExchangeInvoker invoker = new CurrencyExchangeInvoker(exchangeRequest);
         return (DataObject)invoker.invokeInContext();
     }
 }
 

Since:
WBSF 6.0.2
Author:
msanchez@us.ibm.com, dilumr@us.ibm.com, pmschnei@us.ibm.com

Nested Class Summary
 
Nested classes/interfaces inherited from class com.ibm.websphere.fabric.da.context.ContextComponentSupport
ContextComponentSupport.InvocationParamBlock
 
Constructor Summary
InContextServiceInvoker()
          Default constructor that assumes no header.
InContextServiceInvoker(commonj.sdo.DataObject body, commonj.sdo.DataObject header)
          Constructor for supplying body, header.
 
Method Summary
 commonj.sdo.DataObject getBody()
           
protected  java.io.Serializable getExplicitParentId()
          Subclasses capable of supplying explicit context parents can overide this null implementation.
 commonj.sdo.DataObject getHeader()
           
 java.lang.Object invokeInContext()
          Execute method decorates the actual service invocation with the creation and completion of a context that contains all the properties specified using setSelectionProperty(...).
 java.lang.Object invokeInContext(long contextDurationInSeconds)
          Similar to invokeInContext() except that it allows the user to specify additionally the duration for which the Context should live.
 void setOtherProperty(java.lang.String name, java.lang.String value)
          Convenience for using new TypedValue(value).
 void setOtherProperty(java.lang.String name, TypedValue value)
          Adds or replaces the value associated with the supplied context property (name).
 void setSelectionProperty(java.lang.String name, java.lang.String value)
          Convenience for using new TypedValue(value).
 void setSelectionProperty(java.lang.String name, TypedValue value)
          Adds or replaces the value associated with the supplied endpoint selection context property (name).
 
Methods inherited from class com.ibm.websphere.fabric.da.context.ContextComponentSupport
invokeInContext, invokeInContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.ibm.websphere.fabric.da.context.ServiceProxy
invoke
 

Constructor Detail

InContextServiceInvoker

public InContextServiceInvoker()
Default constructor that assumes no header.

Since:
WBSF 6.0.2

InContextServiceInvoker

public InContextServiceInvoker(commonj.sdo.DataObject body,
                               commonj.sdo.DataObject header)
Constructor for supplying body, header. In cases where body is a simple type (not an SDO), supply null for body.

Since:
WBSF 6.1.0
Method Detail

getHeader

public commonj.sdo.DataObject getHeader()

getBody

public commonj.sdo.DataObject getBody()

getExplicitParentId

protected java.io.Serializable getExplicitParentId()
Description copied from class: ContextComponentSupport
Subclasses capable of supplying explicit context parents can overide this null implementation.

Overrides:
getExplicitParentId in class ContextComponentSupport
Returns:
possibly id of parent; null if no such parent is known or required.

setSelectionProperty

public void setSelectionProperty(java.lang.String name,
                                 java.lang.String value)
Convenience for using new TypedValue(value).


setSelectionProperty

public void setSelectionProperty(java.lang.String name,
                                 TypedValue value)
Adds or replaces the value associated with the supplied endpoint selection context property (name).


setOtherProperty

public void setOtherProperty(java.lang.String name,
                             java.lang.String value)
Convenience for using new TypedValue(value).


setOtherProperty

public void setOtherProperty(java.lang.String name,
                             TypedValue value)
Adds or replaces the value associated with the supplied context property (name).


invokeInContext

public java.lang.Object invokeInContext()
Execute method decorates the actual service invocation with the creation and completion of a context that contains all the properties specified using setSelectionProperty(...).

Returns:
the result returned by ServiceProxy.invoke().
See Also:
ServiceProxy.invoke(), setSelectionProperty(String, TypedValue)

invokeInContext

public java.lang.Object invokeInContext(long contextDurationInSeconds)
Similar to invokeInContext() except that it allows the user to specify additionally the duration for which the Context should live. This is especially useful when a downstream component is invoked asynchronously and attempts to create a sub-context.

Note that as of 6.2.1, this method behaves exactly as invokeInContext(). Specifically, the value of contextDurationInSeconds is effectively ignored due to underlying changes to the Context management system. Previously, Context data was stored using a centralized storage mechanism; during one-way and/or asynchronous requests that do not have a clear ending point, specifying a duration was essential so that Context data could be removed from the system. However, with the 6.2.1 release, Context management is handled on a per-invocation basis, and the Context lifecycle is tied to the invocation itself. Once the invocation is complete, the Context data ceases to exist, hence no duration value is required to "clean up" abandoned Contexts.

For clarity, it is recommended that invokeInContext() be used instead of this method.

Parameters:
contextDurationInSeconds - the number of seconds for which this Context should exist.
Returns:
the result returned by ServiceProxy.invoke().
See Also:
invokeInContext()


Copyright © 2002-2009 IBM. All Rights Reserved.