基於Pipe的PureMVC FLEX框架的多核共享消息技術

pipes utilities,也就是所謂的通道(管道),爲何要使用通道呢?模塊的結構都是一個單獨的puremvc結構,模塊和模塊,shell和模塊之間的通訊 不能使用puremvc中的消息進行,由於消息是在一個puremvc中使用的,在多個puremvc中消息是不能跨越的。因此引進了pipes utility。在兩個puremvc中須要進行數據交互的時候,須要創建兩個puremvc之間的通道(pipes)。假如是模塊A和模塊B之間須要傳遞一個數據C,首先創建兩個之間的pipe,在模塊A的view中的A.mediator,發送一個puremvc的消息,如sendNotification( AFacade.SEND_MESSAGE_TO_B, C );模塊A的view的A.JunctionMediator,接收AFacade.SEND_MESSAGE_TO_B這個消息,而後將這個消息發向A和B的通道html

 1 override public function handleNotification( note:INotification ):void
 2   {
 3    
 4    switch( note.getName() )
 5    {       
 6     case ApplicationFacade.SEND_MESSAGE_TO_B:
 7      junction.sendMessage( PipeAwareModuleConstants.MODULE_TO_B_PIPE,
 8            new Message( PipeAwareModuleConstants.MODULE_TO_B_MESSAGE,
 9                null,
10                note.getBody() ));
11      break;    
12     // Let super handle the rest (ACCEPT_OUTPUT_PIPE, ACCEPT_INPUT_PIPE, SEND_TO_LOG)        
13     default:
14      super.handleNotification(note);     
15    } 
16   }

一樣在B的view的JunctionMediator中,會有接收他們之間通道的函數:shell

 1 override public function handlePipeMessage( message:IPipeMessage ):void
 2   {
 3    switch ( Message(message).getType() )
 4    {
 5     case PipeAwareModuleConstants.MODULE_TO_B_PIPE:
 6      sendNotification( ApplicationFacade.MESSAGE_FROM_A_RECEIVED, 
 7           Message(message).getBody() );
 8      break;
 9 
10    }
11   }

在B中的Mediator去接收ApplicationFacade.MESSAGE_FROM_A_RECEIVED,這個消息,獲得通道傳過來的數據。

數據的流動是:A->A的puremvc中的通知->A,B 的pipes->B 的 puremvc 的通知->B。mvc

 

參考:http://bbs.9ria.com/thread-101062-1-1.htmlide

相關文章
相關標籤/搜索