示例#1
0
 /**
  * @param array $resources
  */
 private function releaseResources(array $resources)
 {
     foreach ($resources as $resource) {
         $this->kv->delete($this->lockPath . $resource);
     }
     $this->session->destroy($this->sessionId);
 }
 /**
  * Determines if the given lock handle is currently valid for the given lock name. This method can be used to
  * verify if, for example, a particular lock session currently owns a given lock.
  *
  * @param string $lockName The name of the lock to check
  * @param mixed $lockHandle The opaque lock handle to validate against the lock
  *
  * @return bool True if the handle is valid for the lock, false otherwise
  */
 public function isValid($lockName, $lockHandle)
 {
     if ($lockName != $lockHandle['name']) {
         return false;
     }
     $result = (string) $this->kvClient->get($lockHandle['name'])->getBody();
     $result = json_decode($result, true);
     if (!is_array($result) || !array_key_exists(0, $result)) {
         return false;
     }
     $keyValue = $result[0];
     if (!array_key_exists('Session', $keyValue)) {
         return false;
     }
     if ($keyValue['Session'] != $lockHandle['sessionId']) {
         return false;
     }
     return true;
 }
示例#3
0
 /**
  * Release resources if they were aquired
  */
 public function release()
 {
     if ($this->sessionId) {
         foreach ($this->resources as $resource) {
             $this->kv->delete($this->getResourceKey($resource, $this->sessionId));
         }
         $this->session->destroy($this->sessionId);
         $this->sessionId = null;
     }
 }