Fork me on GitHub Fork me on Gitee

基于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的通道

 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中,会有接收他们之间通道的函数:

 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。

 

参考:http://bbs.9ria.com/thread-101062-1-1.html

posted @ 2016-02-01 17:23  伴途の永远  阅读(491)  评论(0编辑  收藏  举报