Пример #1
0
 /**
  * Create a new receiver.
  * 
  * @param \Spawn\Process $process The process singleton.
  * @param string $class_name The class to instantiate.
  * @param array $arguments The arguments to pass to the class constructor.s
  * @param string The path of this process' FIFO input pipe.
  * @param string The path of this process' FIFO output pipe.
  */
 public function __construct(\Spawn\Process $process, \Spawn\Pipeline $pipeline, $class_name, $arguments)
 {
     $this->process = $process;
     $this->pipeline = $pipeline;
     // Create instance of passed class.
     $reflection = new \ReflectionClass($class_name);
     $this->instance = $reflection->newInstanceArgs($arguments);
     // Initialise I/O queues.
     $this->rpc_queue = array();
     $this->response_queue = array();
     // Initialise I/O watchers.
     $pipeline->openInChild();
     $loop = $this->process->loop;
     $this->watchers = array($loop->io($pipeline->request_fd, \Ev::READ, array($this, '_onReceiverInReadable')), $loop->io($pipeline->response_fd, \Ev::WRITE, array($this, '_onReceiverOutWritable')), $loop->idle(array($this, '_onIdle')));
 }
Пример #2
0
 /**
  * Create a new actor which represents an object running in another process.
  * 
  * @param \Spawn\Process $process The process this actor resides in.
  * @param integer $pid The PID of the process where the object resides.
  * @param string $input_fifo_path The path to the input pipe of the process the object resides in.
  * @param string $output_fifo_path The path to the output pipe of the process the object resides in.
  */
 public function __construct(\Spawn\Process $process, \Spawn\Pipeline $pipeline, $pid)
 {
     // Initialise actor state.
     $this->id = uniqid();
     $this->pid = $pid;
     $this->process = $process;
     $this->pipeline = $pipeline;
     $this->status = self::STATUS_ALIVE;
     // Initialise RPC queues.
     $this->inventory = new RpcInventory();
     // Initialise I/O watchers.
     $pipeline->openInParent();
     $loop = $this->process->loop;
     $this->watchers = array($loop->io($pipeline->request_fd, \Ev::WRITE, array($this, '_onReceiverInWritable')), $loop->io($pipeline->response_fd, \Ev::READ, array($this, '_onReceiverOutReadable')), $loop->child($this->pid, true, array($this, '_onChild')));
     // Stop the watchers before we do anything else.
     // This somehow prevents random race conditions happening.
     foreach ($this->watchers as $watcher) {
         $watcher->stop();
     }
 }