Dactor的配置和API說明-創(chuàng)新互聯(lián)

這篇文章主要講解了“Dactor的配置和API說明”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Dactor的配置和API說明”吧!

成都創(chuàng)新互聯(lián)公司堅(jiān)信:善待客戶,將會(huì)成為終身客戶。我們能堅(jiān)持多年,是因?yàn)槲覀円恢笨芍档眯刨?。我們從不忽悠初訪客戶,我們用心做好本職工作,不忘初心,方得始終。十年網(wǎng)站建設(shè)經(jīng)驗(yàn)成都創(chuàng)新互聯(lián)公司是成都老牌網(wǎng)站營(yíng)銷服務(wù)商,為您提供網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、H5高端網(wǎng)站建設(shè)、網(wǎng)站制作、品牌網(wǎng)站建設(shè)、微信小程序定制開發(fā)服務(wù),給眾多知名企業(yè)提供過好品質(zhì)的建站服務(wù)。

# **配置和API說明**  

## 配置說明

 通過在xml中的Step實(shí)現(xiàn)內(nèi)部Actor之間的流程跳轉(zhuǎn)

 在配置文件中包含

 Actor、chain、和global配置 。

 程序整個(gè)執(zhí)行順序?yàn)楦鶕?jù)交易碼找到對(duì)應(yīng)的Actor,然后執(zhí)行按照chain->parent->selft的順序進(jìn)行執(zhí)行。  

 chain執(zhí)行到placeholder處,調(diào)用parent交易繼續(xù)執(zhí)行,在parent交易中執(zhí)行到placeholder交易后,調(diào)用selft自身交易繼續(xù)執(zhí)行。

 自身交易執(zhí)行完畢,彈出parent的placeholder處交易繼續(xù)執(zhí)行.parent執(zhí)行完畢,彈出chain中代碼繼續(xù)執(zhí)行。

 global配置如下

``` 

  <actor:global id="actorglobal">

         <actor:param name="beginBeanId" value="beginActor"/>

         <actor:param name="endBeanId" value="endActor"/>

   </actor:global>

```   

beginBeanId為默認(rèn)的開始Actor,value中的值是在Spring中對(duì)應(yīng)的beanName,程序初始化時(shí)將會(huì)取得此值,對(duì)未指定beginBeanId或者endBeanId的Actor初始化全局配置。  

beginActor和endActor都需要繼承Actor接口。

actor配置如下

```   

    <actor:actor id="actorhttpcore"   parent="chainparent" chain="unLoginChain"  handleException="true"  endBeanId="FinishActor" >

        <actor:steps>

            <actor:step xpoint="" ypont="" fromBeanId="beginActor"  conditon="" toBeanId="placeholderActor"/>

            <actor:step xpoint="" ypont=""  fromBeanId="placeholderActor" conditon="context._SUFFIX=='json'"  toBeanId="JsonViewResolverActor"/>

            <actor:step xpoint="" ypont=""  fromBeanId="placeholderActor" conditon="exception==null" toBeanId="ViewResolveActor"/>

            <actor:step xpoint="" ypont=""   fromBeanId="placeholderActor" conditon="exception!=null"  toBeanId="ErrorViewResolveActor"/>

        </actor:steps>

             <results>

                    <result name="success">htmlstream:</result>

             </results>

    </actor:actor>

 ```

 屬性handleException如果不設(shè)置的話,遇到異常,程序?qū)?huì)認(rèn)為子類中已經(jīng)執(zhí)行完畢,跳到parent中PlaceHolder處執(zhí)行。設(shè)置為true,將不會(huì)直接跳轉(zhuǎn)到parent中,由子類進(jìn)行自我處理。  

 parent和chain為調(diào)用具體交易前需要調(diào)用的公共交易,由于大部分交易都有通用的前置交易和統(tǒng)一的后置交易。通過設(shè)置parent或者chain,可提高代碼復(fù)用度。  

 fromBeanId和toBeanId配置的是Actor或者實(shí)現(xiàn)Actor接口的beanId。

 parent和chain中的ref都需要是Actor.  

 results中可定義返回的state和需要處理的viewActor

chain配置

 ```

   <actor:chain id="unLoginChain">

        <actor:before>

            <actor:ref bean="actorhttpcore"></actor:ref>

        </actor:before>

    </actor:chain>

```  

chain可直觀展現(xiàn)Actor調(diào)用順序.    

在chain中可順序并列多個(gè)parent類。每個(gè)parent中的Step都需要有placeHolderActor,以調(diào)用子類。      

依次執(zhí)行before中的交易,再執(zhí)行自身交易。自身交易執(zhí)行完畢,再依次回溯責(zé)任鏈中的每個(gè)交易,直到無可用交易。  

## 重要類方法說明

cn.ymotel.dactor.core.MessageDispatcher是交易流轉(zhuǎn)的核心接口類   

    public void startMessage(Message message, ActorTransactionCfg actorcfg, boolean blocked) throws Exception  

方法,用于開始整個(gè)流程,其中message需要在執(zhí)行前進(jìn)行構(gòu)造,actorcfg可通過spring的getBean方法得到為Actor對(duì)象,如下  

```

<actor id="randomTxt1" parent="randomTxt" beginBeanId="randomTxtActor">

    </actor>

```

    通過getBean('randomTxt1')即可得到ActorTransactionCfg對(duì)象。  

    blocked為是否阻塞,一般在交易初次放入隊(duì)列是為false,表示如果隊(duì)列滿,則直接扔給客戶端進(jìn)行處理。為true則一般為內(nèi)部交易,必須提交給隊(duì)列進(jìn)行處理。

  sendMessage方法內(nèi)部調(diào)用,用于將處理完畢的Message重新放入隊(duì)列,繼續(xù)下一步流程。

 cn.ymotel.dactor.core.disruptor.MessageRingBufferDispatcher是MessageDispatcher的接口實(shí)現(xiàn)類。,在啟動(dòng)Spring是需要在配置中加上

 ```

  <bean id="MessageRingBufferDispatcher" class="cn.ymotel.dactor.core.disruptor.MessageRingBufferDispatcher">

    </bean>

 ```   

 MessageRingBufferDispatcher的strategy、bufferSize、threadNumber為三個(gè)可設(shè)置屬性.正常情況下使用默認(rèn)設(shè)置即可。  

 strategy默認(rèn)使用ringBuffer的BlockingWaitStrategy策略進(jìn)行調(diào)度,如果交易量比較大,可調(diào)整此策略。  

 bufferSize默認(rèn)使用1024。   

 threadNumber默認(rèn)使用CPU個(gè)數(shù)的線程數(shù)。   

 ## 其他默認(rèn)Actor說明

 cn.ymotel.dactor.message.Message.Actor,所有需要在執(zhí)行的交易都必須繼承此接口。   

 public Object HandleMessage(Message message) throws Exception;程序通過調(diào)用HandleMessage對(duì)象,如果返回的不是message對(duì)象或者為NULL,則認(rèn)為此交易是異步執(zhí)行,不再自行調(diào)度。由異步交易在收到請(qǐng)求后,自己調(diào)用將Message再此放入隊(duì)列中。  

 cn.ymotel.dactor.action.PlaceholderActor 交易為特殊交易,用來將當(dāng)前隊(duì)列暫存,并調(diào)用子交易。  

 cn.ymotel.dactor.action.BeginActor 為Actor中step的默認(rèn)開始交易。  

 cn.ymotel.dactor.action.EndActor 為Actor中step的默認(rèn)結(jié)束交易。

 cn.ymotel.dactor.action.JsonViewResolverActor為需要返回Json的J2EE view

  cn.ymotel.dactor.action.ViewResolveActor為需要返回J2EE view的統(tǒng)一處理Actor  

  cn.ymotel.dactor.action.httpclient.HttpClientActor 提供的異步調(diào)用httpClient的Actor  

cn.ymotel.dactor.action.netty.aysnsocket.TcpClientActor 提供的異步調(diào)用netty的Actor  

 ## 交易流程舉例說明

 ```

   <actor:actor id="actorhttpcore" handleException="true"  endBeanId="FinishActor" >

         <actor:steps>

             <actor:step xpoint="" ypont="" fromBeanId="beginActor"  conditon="" toBeanId="placeholderActor"/>

             <actor:step xpoint="" ypont=""  fromBeanId="placeholderActor" conditon="context._SUFFIX=='json'"  toBeanId="JsonViewResolverActor"/>

             <actor:step xpoint="" ypont=""  fromBeanId="placeholderActor" conditon="exception==null" toBeanId="ViewResolveActor"/>

             <actor:step xpoint="" ypont=""   fromBeanId="placeholderActor" conditon="exception!=null"  toBeanId="ErrorViewResolveActor"/>

         </actor:steps>

     </actor:actor>

  <actor id="randomTxt2" parent="actorhttpcore" beginBeanId="randomTxtActor">

     </actor>

 ```

 以上交易的交易流程圖如下

 Dactor的配置和API說明

以上的完整例子都可在example中得到

感謝各位的閱讀,以上就是“Dactor的配置和API說明”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)Dactor的配置和API說明這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

文章標(biāo)題:Dactor的配置和API說明-創(chuàng)新互聯(lián)
分享URL:http://muchs.cn/article36/djgipg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站排名、網(wǎng)站收錄品牌網(wǎng)站建設(shè)、網(wǎng)站制作、定制網(wǎng)站、Google

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名