`

Processor Chains and the Pipeline Manager

阅读更多

Processor Chains and the Pipeline Manager

Processor 就是一个执行一些功能和返回状态码的一个组件,状态码决定chain中下一个是哪一个processor被执行。

 

PipelineManager 可以使你动态的添加或删除processor.Pipeline要执行processor。需要调用runProcess().他首先会找请求的链,如果is enable,PipelineManager 调用runProcess(),如果isn't enable,就会抛出一个异常。

 

The following sections describe how to create a processor pipeline:

 

配置Pipeline Manager:

每一个processor chain 都是有pipeline manager 控制的,它位于/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是定义processor chains的。

 

Creating Processors:

首先要实现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:定义文件根节点

pipelinechain: 定义一个procesor chain

  • name:名字
  • transaction:processor默认使用的事物模式
  • headlink:在processor chain中的第一个processor被执行
  • classname:将被实例化和用于PipelineChain对象,默认是atg.service.pipeline.PipelineChain.而且一定是他的子类
  • resultclassname:用于pipleineResult对象,The default is atg.service.pipeline.PipelineResult. The value must implement PipelineResult.

pipelinelink:在 processor chain中定义processor.

  • name:processor的名字
  • transaction

processor:The name of the PipelineProcessor object.

  1. jndi :所引用processor类,这个对象是通过JNDI来解决的e

transition:根绝返回值决定下一个将要被执行的引用

  1. returnvalue:An integer string that is used to define the next pipeline element.
  2. 下一个将会被执行的pipelineprocessor,如果当前的返回值匹配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>



 

分享到:
评论

相关推荐

    Markov Chains and Monte–Carlo Simulation.pdf

    Markov chains – are a fundamental class of stochastic models for sequences of non–independent random variables, i.e. of random variables possessing a specific dependency structure. – have numerous ...

    Markov Chains And Stochastic Stability

    马尔科夫链的电子书《马尔科夫链与随机稳定性》(Markov Chains and Stochastic Stability) 第二版由Meyn和Tweedie撰写,是这一领域的经典之作。本书对马尔科夫链的理论做了深入的探讨,并介绍了自1996年第一版出版...

    Markov Chains and Stochastic Stability compiled ver

    ### 马尔可夫链与随机稳定性概览 #### 标题理解 标题“马尔可夫链与随机稳定性编译版”明确指出本文档的主题是关于**马尔可夫链**及其在**随机稳定性**方面的应用。马尔可夫链是一种统计模型,它描述了一个系统...

    Haggstrom O. Finite Markov chains and algorithmic applications

    标题和描述中提到了奥利·哈格斯特罗姆的著作《有限马尔可夫链和算法应用》,这本书由剑桥大学出版社在2002年出版。书中讨论了马尔可夫链的理论及其在算法中的应用,特别是随机过程。马尔可夫链是随机过程中的一种...

    马尔可夫链和随机稳定性Markov Chains and Stochastic Stability

    本书描述了一般状态空间马尔可夫链的现代理论,并将其应用于运筹学,时间序列分析以及系统和控制理论。

    A Randomized Quasi-Monte Carlo Simulation Method for Markov Chains

    《A Randomized Quasi-Monte Carlo Simulation Method for Markov Chains》是一篇发表在《Operations Research》期刊上的经典论文,该论文提出了一种新的模拟方法,即随机准蒙特卡洛模拟方法(Randomized Quasi-...

    Markov Chains and Random Walks-计算机科学

    princeton university F’02 cos 597D: a theorist’s toolkitLecture 7: Markov Chains and Random WalksLecturer: Sanjeev Arora Scribe:Elena Nabieva1 BasicsA Markov chain is a discrete-time stochastic ...

    Markov Chains Theory and Applications

    ### 马尔科夫链理论与应用 #### 标题和描述中的知识点详细解析 **马尔科夫链(Markov Chain)**是一种在概率论和统计学中广泛使用的数学模型,它用来描述一系列随机事件的状态转移过程,其中每个事件的概率只依赖...

    Markov chains, Gibbs Fields Monte Carlo Simulation, and Queues.pdf

    根据提供的文件信息,本书《Markov chains, Gibbs Fields Monte Carlo Simulation, and Queues》由Pierre Bremaud撰写,被广泛认为是学习随机过程的重要教材之一。以下将根据标题、描述以及部分目录信息来总结书中的...

    Queueing Networks and Markov Chains Modeling 第二版

    Queueing Networks and Markov Chains Modeling and Performance Evaluation with Computer Science Application第二版,排队网络的经典书籍,Gunter Bolch,Stefan Greiner, Hermann de Meer, Kishor S....

    Advanced Planning and Scheduling in Manufacturing and Supply Chains

    This book is a guide to modern production planning methods based on new scientific achievements and various practical planning rules of thumb. Various batch computation methods are described in detail...

    Markov Chains and Mixing Times

    ### 马尔可夫链与混合时间 #### 前言 《马尔可夫链与混合时间》是一本由David A. Levin、Yuval Peres和Elizabeth L. Wilmer三位作者共同编写的专著,该书深入探讨了马尔可夫链的基本理论以及混合时间的相关概念。...

    Probability, Markov chains, queues and simulation

    首先,“Probability, Markov chains, queues and simulation” 这个标题暗示了书中将探讨几个关键的数学和计算机科学领域,它们对于性能建模至关重要。 **概率论**: - **概率试验**:这是研究随机现象的基础,...

    Markov Chains_ Analytic and Monte Carlo Computations .pdf

    The basic analytical tool is the maximum principle, which is natural in this setting. It is superfcially compared to martingale methods in some instances. The basic probabilistic tool is the Markov ...

    SUMS85 Understanding Markov Chains -- Examples and Applications

    SUMS85 Understanding Markov Chains -- Examples and Applications, 2nd Edition, Nicolas Privault (2018).zip

    微软内部资料-SQL性能优化3

    In our example, if one transaction (T1) holds an exclusive lock at the table level, and another transaction (T2) holds an exclusive lock at the row level, each of the transactions believe they have ...

    06-algorithm-chains-and-pipelines.ipynb

    06-algorithm-chains-and-pipelines

Global site tag (gtag.js) - Google Analytics