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

java.lang.Object
  extended by com.ibm.websphere.fabric.da.context.ContextComponentSupport
Direct Known Subclasses:
InContextServiceInvoker

public abstract class ContextComponentSupport
extends java.lang.Object

Support class that gives component developers a convenient mechanism for executing tasks using a context. A common task is to call one or more services using a context to pass context properties in a message header for downstream processing. A sample implementation:

 public class CurrencyExchangeContextualizerImpl extends ContextComponentSupport  {
 
     public CurrencyExchangeContextualizerImpl() {
         super();
     }
     
     // Other SCA Java component methods
     // ...
     
     public DataObject doExchange(final DataObject exchangeRequest) {
         // Propagate the userId from the exchange request in the context
         String userId = exchangeRequest.getString("userId");
         
         final Map props = new HashMap();
         props.put("userId", userId);
         
         return (DataObject) invokeInContext(null, props, new ServiceProxy() {
             public Object invoke() {
                Service svc = locateService_CurrencyExchangePartner();
                DataObject response = (DataObject) svc.invoke("doExchange", exchangeRequest);
                DataObject rv = (DataObject) response.get(0);
                trace("response from invoke: " + rv);
                return rv;
            }
        });
    }
 }
 

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

Nested Class Summary
static class ContextComponentSupport.InvocationParamBlock
          Encapsulates parameters needed for invocations.
 
Constructor Summary
ContextComponentSupport()
           
 
Method Summary
protected  java.io.Serializable getExplicitParentId()
          Subclasses capable of supplying explicit context parents can overide this null implementation.
protected  java.lang.Object invokeInContext(ContextComponentSupport.InvocationParamBlock paramBlock)
          Runs the specified runnable ensuring that a new context is established before the task executes and closed after it completes.
protected  java.lang.Object invokeInContext(java.util.Map selectionProperties, java.util.Map otherProperties, ServiceProxy proxy)
          Deprecated. Use invokeInContext(InvocationParamBlock).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextComponentSupport

public ContextComponentSupport()
Method Detail

getExplicitParentId

protected java.io.Serializable getExplicitParentId()
Subclasses capable of supplying explicit context parents can overide this null implementation.

Returns:
possibly id of parent; null if no such parent is known or required.
Since:
WBSF 6.1.0

invokeInContext

protected java.lang.Object invokeInContext(java.util.Map selectionProperties,
                                           java.util.Map otherProperties,
                                           ServiceProxy proxy)
Deprecated. Use invokeInContext(InvocationParamBlock).

Runs the specified runnable ensuring that a new context is established before the task executes and closed after it completes. If a context is currently established, a new child context is created. Adds the specified context properties to the new context and ensures that the new context is propagated.

Parameters:
selectionProperties - the selection properties to add to the context
otherProperties - the other (non-selection) properties to add to the context
proxy - invokes a service using the established context
Returns:
Object the result of the service invocation

invokeInContext

protected java.lang.Object invokeInContext(ContextComponentSupport.InvocationParamBlock paramBlock)
Runs the specified runnable ensuring that a new context is established before the task executes and closed after it completes. If a context is currently established, a new child context is created. Adds the specified context properties to the new context and ensures that the new context is propagated.

Parameters:
paramBlock - properties under which this invocation is taking place.
Returns:
Object the result of the service invocation


Copyright © 2002-2009 IBM. All Rights Reserved.