Пример #1
0
 /**
  * Add a response to the registry.
  * 
  * @param Response $response     The response to add. The caller of this
  *     function is responsible for ensuring that the ownership tag and the
  *     original tag are separated, so that only the original one remains in
  *     the response.
  * @param string   $ownershipTag The ownership tag that the response had.
  * 
  * @return bool TRUE if the request was added to its buffer, FALSE if
  *     this instance owns the response, and therefore doesn't need to add
  *     the response to its buffer.
  */
 public function add(Response $response, $ownershipTag)
 {
     if ($this->getOwnershipTag() === $ownershipTag || $this->isTaglessModeOwner() && $response->getType() !== Response::TYPE_FATAL) {
         return false;
     }
     if (null === $ownershipTag) {
         $this->shm->lock('taglessModeOwner');
         if ($this->shm->exists('taglessModeOwner') && $response->getType() !== Response::TYPE_FATAL) {
             $ownershipTag = $this->shm->get('taglessModeOwner');
             $this->shm->unlock('taglessModeOwner');
         } else {
             $this->shm->unlock('taglessModeOwner');
             foreach ($this->shm->getIterator('/^(responseBuffer\\_)/', true) as $targetBufferName) {
                 $this->_add($response, $targetBufferName);
             }
             return true;
         }
     }
     $this->_add($response, 'responseBuffer_' . $ownershipTag);
     return true;
 }
Пример #2
0
 public function testTaglessModePassing()
 {
     $com1 = new Communicator(\HOSTNAME, PORT, true);
     Client::login($com1, USERNAME, PASSWORD);
     $reg1 = new Registry('dummy');
     $com2 = new Communicator(\HOSTNAME, PORT, true);
     $reg2 = new Registry('dummy');
     $this->assertNotEquals($reg1->getOwnershipTag(), $reg2->getOwnershipTag());
     $pingRequest1 = new Request('/ping address=' . HOSTNAME, null, 'ping');
     $pingRequest1->send($com1, $reg1);
     $response1_1 = new Response($com1, false, null, null, $reg1);
     $cancelRequest = new Request('/cancel');
     $reg1->setTaglessMode(true);
     $cancelRequest->setArgument('tag', $reg1->getOwnershipTag() . 'ping');
     $cancelRequest->send($com1, $reg1);
     $pingRequest2 = new Request('/ping count=2 address=' . HOSTNAME, null, 'ping');
     $pingRequest2->send($com2, $reg2);
     $response2_1 = new Response($com2, false, null, null, $reg2);
     $response2_2 = new Response($com2, false, null, null, $reg2);
     $response2_3 = new Response($com2, false, null, null, $reg2);
     $reg1->setTaglessMode(false);
     $com1->close();
     $com2->close();
     $this->assertEquals(Response::TYPE_DATA, $response2_1->getType());
     $this->assertEquals(Response::TYPE_DATA, $response2_2->getType());
     $this->assertEquals(Response::TYPE_FINAL, $response2_3->getType());
     $response1_2 = new Response($com1, false, null, null, $reg1);
     $response1_3 = new Response($com1, false, null, null, $reg1);
     $this->assertEquals(Response::TYPE_DATA, $response1_1->getType());
     $this->assertEquals(Response::TYPE_ERROR, $response1_2->getType());
     $this->assertEquals(Response::TYPE_FINAL, $response1_3->getType());
     $reg1->close();
     $this->assertStringStartsWith('-1_', $reg2->getOwnershipTag());
 }
Пример #3
0
 /**
  * Dispatches the next response in queue.
  * 
  * Dispatches the next response in queue, i.e. it executes the associated
  * callback if there is one, or places the response in the response buffer.
  * 
  * @param int $sTimeout  If a response is not immediatly available, wait
  *     this many seconds. If NULL, wait indefinetly.
  * @param int $usTimeout Microseconds to add to the waiting time.
  * 
  * @throws SocketException When there's no response within the time limit.
  * @return Response The dispatched response.
  */
 protected function dispatchNextResponse($sTimeout = 0, $usTimeout = 0)
 {
     $response = new Response($this->com, $this->_streamingResponses, $sTimeout, $usTimeout, $this->registry);
     if ($response->getType() === Response::TYPE_FATAL) {
         $this->pendingRequestsCount = 0;
         $this->com->close();
         return $response;
     }
     $tag = $response->getTag();
     $isLastForRequest = $response->getType() === Response::TYPE_FINAL;
     if ($isLastForRequest) {
         $this->pendingRequestsCount--;
     }
     if ('' != $tag) {
         if ($this->isRequestActive($tag, self::FILTER_CALLBACK)) {
             if ($this->callbacks[$tag]($response, $this)) {
                 $this->cancelRequest($tag);
             } elseif ($isLastForRequest) {
                 unset($this->callbacks[$tag]);
             }
         } else {
             $this->responseBuffer[$tag][] = $response;
         }
     }
     return $response;
 }