Packagejp.co.fujitsu.reffi.client.flex.model.messaging
Classpublic class ConsumerCore
InheritanceConsumerCore Inheritance BaseModel Inheritance flash.events.EventDispatcher

[概 要]

発行されているサーバメッセージデスティネーションをクライアントで購読する為の機能モデルクラスです.

[詳 細]

サーバ側(LCDS及びBlazeDS)のmessaging-config.xmlで定義されているdestinationを購読開始、停止します。
subscribeプロパティがtrueの場合は購読開始、falseの場合は停止します。

この機能モデルを拡張したモデルを作成する場合、onSuccessメソッドとonFailureメソッドをオーバーライド することで、メッセージ受信成功処理、失敗処理を実装することが出来ます。

[備 考]



指定回数subscribeしたらunsubscribeする
        public class SubscribeStartAction extends BaseAction {

            // ① subscribeを行うConsumerCore機能モデルを登録します    
            override protected function reserveModels(models:Array):void {
                models.push(Class(ConsumerCore));
            }
        
            // ② ConsumerCoreインスタンスの設定を行います。このケースではpublishDemoデスティネーションを購読します 
            override public function nextModel(index:int, prev:ModelProcessEvent, next:BaseModel):Boolean {
                switch (index) {
                    case 0:
                        ConsumerCore(next).destination = "publishDemo";
                        break;                
                }
                return true;
            }
        
            // ③ メッセージ購読成功時の処理を実装します
            //    ConsumerCoreは継続的にSUCCESSイベントを返却する為、subscribe停止するまで
            //    このメソッドへのコールバックが継続します
            //    ConsumerCoreManagerを使用することで任意のタイミングでsubscribe停止可能です
            override public function successForward(index:int, model:BaseModel, resultEvent:Event):void {
                var list:ArrayCollection = getObjectById("serverPushArrayCollection") as ArrayCollection;
                list.list = MessageEvent(resultEvent).message.body as ArrayCollection;
                 
                if(model.successCount == 3) {
                    ConsumerCoreManager.getInstance().unsubscribe("publishDemo");
                }
            }
            
            // ④ 登録モデルが完全に完了した時に呼ばれるメソッドを実装します
            //    継続的に値を返却するモデルの完了タイミングをハンドルします 
            override public function complete():void {
                trace("subscribe is done.");
            }
        }
  
既に実行中のdestination購読を停止する
        public class SubscribeStopAction extends BaseAction {

            // ① subscribe停止を行うConsumerCore機能モデルを登録します    
            override protected function reserveModels(models:Array):void {
                models.push(Class(ConsumerCore));
            }
            
            // ② subscribeモードをfalseに設定したConsumerCoreが実行されることでsubscribe停止します
            //    同一destinationをsubscribeしているConsumerCoreが複数存在するケースで、任意のConsumerCore
            //    だけsubscribeを停止する場合、開始時に設定しておいたidentifierを指定することが出来ます
            //    identifierが指定されなかった場合は同一destinationをsubscribe中の全ConsumerCoreがsubscribe停止します    
            override public function nextModel(index:int, prev:ModelProcessEvent, next:BaseModel):Boolean {
                switch (index) {
                    case 0:                
                        ConsumerCore(next).destination = "publishDemo";
                        ConsumerCore(next).subscribe = false;
                        ConsumerCore(next).identifier = "client1";
                        break;                    
                }
                return true;
            }
        }
  

Copyright (c) 2008-2009 FUJITSU Japan All rights reserved.

関連項目

jp.co.fujitsu.reffi.client.flex.manager.ConsumerCoreManager


Public Properties
 PropertyDefined by
  channelSet : ChannelSet

[概 要]

任意設定可能な通信チャンネルセットです.
ConsumerCore
 Inheritedcontroller : BaseController

[概 要]

このモデルを起動したコントローラインスタンスです.
BaseModel
  destination : String

[概 要]

メッセージ受信を行う対象のdestinationです.
ConsumerCore
 InheritedexecuteIndex : int

[概 要]

実行インデックス設定.
BaseModel
  identifier : String

[概 要]

購読中のConsumerCoreを特定する為の識別子です.
ConsumerCore
 InheritedparameterMapping : ParameterMapping

[概 要]

MVC各レイヤを伝播するパラメータオブジェクトです.
BaseModel
 Inheritedskip : Boolean

[概 要]

このモデルを実行するか、コントローラが判断する為のフラグです.
BaseModel
  subscribe : Boolean

[概 要]

購読開始/購読停止を示すフラグです.
ConsumerCore
 InheritedsuccessCount : int

[概 要]

モデルインスタンス生存中に、何回モデル処理が成功したかを保持します.
BaseModel
Public Methods
 MethodDefined by
 Inherited

[概 要]

モデル処理失敗イベントを発行するメソッドです.
BaseModel
 Inherited

[概 要]

モデル処理完了イベントを発行するメソッドです.
BaseModel
 Inherited

[概 要]

モデル処理成功イベントを発行するメソッドです.
BaseModel
  
faultHandler(event:MessageFaultEvent):void

[概 要]

subscribe受信失敗時にコールバックされるメソッドです.
ConsumerCore
 Inherited

[概 要]

ModelProcessEvent.SUCCESS発行回数を1増加させます.
BaseModel
  
resultHandler(event:MessageEvent):void

[概 要]

subscribe受信時にコールバックされるメソッドです.
ConsumerCore
 Inherited
run():void

[概 要]

コントローラにコールされるモデルの主幹メソッドです.
BaseModel
Protected Methods
 MethodDefined by
 Inherited
finallyProc():void

[概 要]

run()が終了したタイミングでテンプレートコールされるメソッドです.
BaseModel
  
mainProc():void

[概 要]

サーバに対して購読の開始、停止処理を行います.
ConsumerCore
  
onFailure(event:MessageFaultEvent):void

[概 要]

subscribe受信失敗オーバーライド用メソッドです.
ConsumerCore
  
onSuccess(event:MessageEvent):void

[概 要]

subscribe結果受信オーバーライド用メソッドです.
ConsumerCore
 Inherited
postProc():void

[概 要]

後処理テンプレートメソッドです.
BaseModel
 Inherited
preProc():Boolean

[概 要]

前処理テンプレートメソッドです.
BaseModel
 Inherited
trap(e:Error):Error

[概 要]

run()内で発生した全例外をハンドリングするメソッドです.
BaseModel
Property detail
channelSetproperty
channelSet:ChannelSet  [read-write]

[概 要]

任意設定可能な通信チャンネルセットです.

[詳 細]

[備 考]

実装
    public function get channelSet():ChannelSet
    public function set channelSet(value:ChannelSet):void
destinationproperty 
destination:String  [read-write]

[概 要]

メッセージ受信を行う対象のdestinationです.

[詳 細]

LCDS及びBlazeDSのmessaging-config.xmlで定義されているdestinationを設定します。

[備 考]

実装
    public function get destination():String
    public function set destination(value:String):void
identifierproperty 
identifier:String  [read-write]

[概 要]

購読中のConsumerCoreを特定する為の識別子です.

[詳 細]

同一destinationを購読するConsumerCoreが複数有る場合、 任意のConsumerCoreを特定する為に使用するプロパティです。
subscribe開始時に指定することが出来ます。

[備 考]

実装
    public function get identifier():String
    public function set identifier(value:String):void


同一チャンネルに入っているチャットクライアントの内、任意のクライアントを終了する

開始

            override public function nextModel(index:int, prev:ModelProcessEvent, next:BaseModel):Boolean {
                switch (index) {
                    case 0:
                        ConsumerCore(next).destination = "chatRoom";
                        ConsumerCore(next).identifier = "yamada";
                        break;                
                }
                return true;
            }
   
停止
            override public function nextModel(index:int, prev:ModelProcessEvent, next:BaseModel):Boolean {
                switch (index) {
                    case 0:
                        ConsumerCore(next).destination = "chatRoom";
                        ConsumerCore(next).subscribe = false;
                        ConsumerCore(next).identifier = "yamada";
                        break;                
                }
                return true;
            }
   

subscribeproperty 
subscribe:Boolean  [read-write]

[概 要]

購読開始/購読停止を示すフラグです.

[詳 細]

true:購読開始
false:購読停止

[備 考]

The default value is true.

実装
    public function get subscribe():Boolean
    public function set subscribe(value:Boolean):void
Method detail
faultHandler()method
public function faultHandler(event:MessageFaultEvent):void

[概 要]

subscribe受信失敗時にコールバックされるメソッドです.

[詳 細]

ConsumerCoreManagerに管理されているConsumerのMessageFaultEvent.FAULTイベントハンドラ からコールバックされます。
subscribe受信失敗処理用オーバーライドメソッドであるonFailureを テンプレートコールします。
onFailureメソッドが正常終了した後、Model処理失敗イベントを発火します。

[備 考]

このメソッドはオーバーライド出来ません。
メッセージ受信失敗処理を記述する場合はonFailureメソッドをオーバーライドして下さい。

パラメータ

event:MessageFaultEvent — メッセージ受信失敗イベント
mainProc()method 
protected override function mainProc():void

[概 要]

サーバに対して購読の開始、停止処理を行います.

[詳 細]

subscribe管理オブジェクト(ConsumerCoreManager)を取得し、購読の開始、中止を委譲します。
対象となるdestination名は「destination」プロパティから、購読開始、中止の判断を行うフラグは 「subscribe」プロパティから取得します。

購読中止(subscribeプロパティ == false)時、ConsumerCoreManager#unsubscribeメソッド処理が 例外をスローしなかった場合は、その時点でModel処理成功イベントを発火します。

[備 考]

購読中止時のModel処理成功イベント内結果オブジェクトはnullです。 利用することは出来ません。

onFailure()method 
protected function onFailure(event:MessageFaultEvent):void

[概 要]

subscribe受信失敗オーバーライド用メソッドです.

[詳 細]

[備 考]

パラメータ
event:MessageFaultEvent — メッセージ受信失敗イベント
onSuccess()method 
protected function onSuccess(event:MessageEvent):void

[概 要]

subscribe結果受信オーバーライド用メソッドです.

[詳 細]

[備 考]

パラメータ
event:MessageEvent — メッセージ受信イベント
resultHandler()method 
public final function resultHandler(event:MessageEvent):void

[概 要]

subscribe受信時にコールバックされるメソッドです.

[詳 細]

ConsumerCoreManagerに管理されているConsumerのMessageEvent.MESSAGEイベントハンドラ からコールバックされます。
subscribe受信データ取得用オーバーライドメソッドであるonSuccessを テンプレートコールします。
onSuccessメソッドが正常終了した後、Model処理成功イベントを発火します。

[備 考]

このメソッドはオーバーライド出来ません。
subscribe受信データをモデルレイヤで取得したい場合は、 onSuccessメソッドをオーバーライドして下さい。

パラメータ

event:MessageEvent — メッセージ受信イベント