PEIP_Pollable_Channel.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * This file is part of the PEIP package.
00005  * (c) 2010 Timo Michna <timomichna/yahoo.de>
00006  * 
00007  * For the full copyright and license information, please view the LICENSE
00008  * file that was distributed with this source code.
00009  */
00010 
00024 class PEIP_Pollable_Channel  
00025     extends PEIP_ABS_Interceptable_Message_Channel 
00026     implements PEIP_INF_Pollable_Channel {
00027 
00028     protected 
00029         $messages = array();
00030         
00031     
00037     protected function doSend(PEIP_INF_Message $message){
00038         $this->messages[] = $message;        
00039     }
00040     
00041     
00047     public function receive($timeout = -1){
00048         $this->getInterceptorDispatcher()->notify('preReceive', array($this));
00049         $this->doFireEvent('preReceive');
00050         $message = NULL;
00051         if($timeout == 0){
00052             $message = $this->getMessage(); 
00053         }elseif($timeout < 0){
00054             while(!$message = $this->getMessage()){
00055                                 
00056             }
00057         }else{
00058             $time = time() + $timeout;
00059             while(($time > time()) && !$message = $this->getMessage()){
00060                 
00061             }       
00062         }
00063         $this->getInterceptorDispatcher()->notify('postReceive', array($this));
00064         $this->doFireEvent('postReceive', array('MESSAGE'=>$message));
00065         return $message;
00066     }
00067 
00068     
00073     protected function getMessage(){
00074         return array_shift($this->messages);
00075     }
00076     
00077     
00082     public function clear(){
00083         $this->messages = array();
00084     }
00085     
00086     
00092     public function purge(PEIP_INF_Message_Selector $selector){
00093         foreach($this->messages as $key=>$message){
00094             if(!$selector->acceptMessage($message)){
00095                 unset($this->messages[$key]);   
00096             }
00097         }
00098         return $this->messages;
00099     }
00100         
00101     
00102 }

Generated on Mon Apr 12 11:39:00 2010 for PEIP by  doxygen 1.5.1