Processor Chains and the Pipeline Manager

Processor Chains and the Pipeline Manager

A processor is a component that performs some functions and returns a status code. The status code determines which processor is executed next in the chain.

 

PipelineManager allows you to dynamically add or remove processors. Pipeline executes processors. You need to call runProcess(). He will first find the requested chain. If it is enabled, PipelineManager will call runProcess(), and if it is not enabled, an exception will be thrown.

 

The following sections describe how to create a processor pipeline:

 

Configure Pipeline Manager:

Each processor chain is controlled by a pipeline manager located in /atg/commerce/

PipelineManager. The PipelineManager属性:

$class=atg.commerce.pipeline.CommercePipelineManager

# The location of the XML configuration file in the classpath.
# Default: /atg/commerce/CommercePipeline.xml
definitionFile=/atg/commerce/commercepipeline.xml


# The transaction manager that the PipelineManager will use to coordinate its
# transactions.
transactionManager=/atg/dynamo/transaction/TransactionManager

# The amount of time in milliseconds that a thread will wait to execute a pipeline.
# Default: 15000 msec
chainLockWaitTimeout=15000

#
# The schedule to reinitialize the PipelineManager.
#
scheduler=/atg/dynamo/service/Scheduler
schedule=every 6 hours in 6 hours

 definitionFile defines processor chains.

 

Creating Processors:

The first thing to do is to implement the atg.service.pipeline.PipelineProcessor interface.

 

public abstract interface PipelineProcessor
{
  public static final String CLASS_VERSION = "$Id: //product/DAS/version/10.2/Java/atg/service/pipeline/PipelineProcessor.java#2 $$Change: 768621 $";
  public static final int STOP_CHAIN_EXECUTION_AND_COMMIT = 0;
  public static final int STOP_CHAIN_EXECUTION = 0;
  public static final int STOP_CHAIN_EXECUTION_AND_ROLLBACK = -1;
  
  public abstract int runProcess(Object paramObject, PipelineResult paramPipelineResult)
    throws Exception;
  
  public abstract int[] getRetCodes();
}

 

public abstract class ProcProcessPaymentGroup extends GenericService
  implements PipelineProcessor
{
  public static String CLASS_VERSION = "$Id: //product/DCS/version/10.2/Java/atg/commerce/payment/processor/ProcProcessPaymentGroup.java#2 $$Change: 768796 $";
  public static final int SUCCESS = 1;

  protected void invokeProcessorAction(PaymentManagerAction pProcessorAction, PaymentManagerPipelineArgs pParams)
    throws CommerceException
  {
    PaymentStatus status = null;

    if (isLoggingDebug()) {
      logDebug("Obtained processorAction with: " + pProcessorAction);
    }
    if (pProcessorAction == PaymentManagerAction.AUTHORIZE)
      status = authorizePaymentGroup(pParams);
    else if (pProcessorAction == PaymentManagerAction.DEBIT)
      status = debitPaymentGroup(pParams);
    else if (pProcessorAction == PaymentManagerAction.CREDIT)
      status = creditPaymentGroup(pParams);
    else if (pProcessorAction == PaymentManagerAction.DECREASE_AUTH_AMT)
      status = decreaseAuthorizationForPaymentGroup(pParams);
    else {
      throw new CommerceException("Invalid processor action specified: " + pProcessorAction);
    }
    pParams.setPaymentStatus(status);
  }

  public PaymentStatus decreaseAuthorizationForPaymentGroup(PaymentManagerPipelineArgs pParams)
    throws CommerceException
  {
    return null;
  }

  public abstract PaymentStatus authorizePaymentGroup(PaymentManagerPipelineArgs paramPaymentManagerPipelineArgs)
    throws CommerceException;

  public abstract PaymentStatus debitPaymentGroup(PaymentManagerPipelineArgs paramPaymentManagerPipelineArgs)
    throws CommerceException;

  public abstract PaymentStatus creditPaymentGroup(PaymentManagerPipelineArgs paramPaymentManagerPipelineArgs)
    throws CommerceException;

  public int runProcess(Object pParam, PipelineResult pResult)
    throws Exception
  {
    PaymentManagerPipelineArgs params = (PaymentManagerPipelineArgs)pParam;
    PaymentManagerAction action = params.getAction();
    try {
      invokeProcessorAction(action, params);
    }
    catch (CommerceException e) {
      logError (e);
      pResult.addError("ProcProcessPaymentGroupFailed", e);
      return 0;
    }

    return 1;
  }

  public int[] getRetCodes()
  {
    int[] retCodes = { 1 };
    return retCodes;
  }
}

 Pipeline Definition Files:

PipelineManager: Define the root node of the file

pipelinechain: define a processor chain

  • name: name
  • transaction: The transaction mode used by the processor by default
  • headlink: The first processor in the processor chain is executed
  • classname: will be instantiated and used for PipelineChain objects, the default is atg.service.pipeline.PipelineChain. And it must be his subclass
  • resultclassname:用于pipleineResult对象,The default is atg.service.pipeline.PipelineResult. The value must implement PipelineResult.

pipelinelink: Define the processor in the processor chain.

  • name: the name of the processor
  • transaction

processor:The name of the PipelineProcessor object.

  1. jndi : The referenced processor class, this object is resolved through JNDI

transition: Absolute return value determines the next reference to be executed

  1. returnvalue:An integer string that is used to define the next pipeline element.
  2. The next pipelineprocessor that will be executed if the current return value matches the return value
<?xml version="1.0"?>
<!DOCTYPE PipelineManager SYSTEM "PipelineManager.dtd">
<PipelineManager>
<pipelinechain name="AddToCart" transaction="TX_REQUIRED" headlink="proc1">
<pipelinelink name="proc1">
<processor class="atg.commerce.addA"/>
<transition returnvalue="1" link="proc2"/>
<transition returnvalue="2" link="proc3"/>
</pipelinelink>
<pipelinelink name="proc2" transaction="TX_REQUIRES_NEW">
<processor class="atg.commerce.addB"/>
<transition returnvalue="1" link="proc4"/>
<transition returnvalue="2" link="proc5"/>
</pipelinelink>
<pipelinelink name="proc3">
<processor class="atg.commerce.addE"/>
<transition returnvalue="1" link="proc6"/>
<transition returnvalue="2" link="proc7"/>
<transition returnvalue="3" link="proc2"/>
</pipelinelink>
<pipelinelink name="proc4">
<processor class="atg.commerce.addC"/>
</pipelinelink>
<pipelinelink name="proc5" transaction="TX_REQUIRES_NEW">
<processor class="atg.commerce.addD"/>
</pipelinelink>
<pipelinelink name="proc6" transaction="TX_NOT_SUPPORTED">
<processor class="atg.commerce.addF"/>
</pipelinelink>
<pipelinelink name="proc7" transaction="TX_SUPPORTS">
<processor jndi="/dynamo/atg/commerce/addG"/>
</pipelinelink>
</pipelinechain>
<pipelinechain name="RemoveFromCart" transaction="TX_REQUIRED"
headlink="proc99" classname="atg.service.pipeline.PipelineMonoChain">
<pipelinelink name="proc99">
<processor class="atg.commerce.removeA"/>
</pipelinelink>
</pipelinechain>
</PipelineManager>



 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327058594&siteId=291194637