function release() { try { $this->zookeeper->delete($this->path); } catch (Scalr_Service_Zookeeper_Exception $e) { if ($e->getCode() != Scalr_Service_Zookeeper_Exception::NOT_FOUND) { throw $e; } } }
function clear() { $this->init(); $this->lock->acquire(); try { foreach ($this->itemNames() as $name) { $this->zookeeper->delete("{$this->path}/{$name}"); } $this->lock->release(); } catch (Exception $e) { $this->lock->release(); throw $e; } }
function peek() { $this->init(); do { // Fetch path child nodes if (!$this->children) { //$this->logger->debug("Getting queue path child nodes"); if ($this->blocking) { $start = microtime(true); try { do { $childData = $this->zookeeper->getChildren($this->path); $loop = !$childData->children && ($this->blockingTimeout && !Scalr_Util_Timeout::reached($this->blockingTimeout, $start) || !$this->blockingTimeout); } while ($loop); } catch (Scalr_Util_TimeoutException $e) { return null; } } else { $childData = $this->zookeeper->getChildren($this->path); } if ($childData->children) { sort($childData->children); $this->children = $childData->children; } else { $this->logger->debug("Queue is empty"); if (!$this->blocking) { return null; } } } $this->logger->debug("Children capacity: " . count($this->children)); while ($childName = array_shift($this->children)) { try { $statData = $this->zookeeper->get("{$this->path}/{$childName}"); $this->zookeeper->delete("{$this->path}/{$childName}"); $this->logger->info("Peeked {$this->path}/{$childName} from queue"); return base64_decode($statData->data64); } catch (Exception $wasDeleted) { // Continue loop $this->logger->debug(sprintf("Got error while delete node %s. " . "I think it was processed by another client", "{$this->path}/{$childName}")); } } } while (!$this->children); }
private function setStatus($status) { if ($status != self::STATUS_NOTSET) { try { $this->zookeeper->set("{$this->path}/status", serialize($status)); } catch (Scalr_Service_Zookeeper_Exception $e) { if ($e->getCode() == Scalr_Service_Zookeeper_Exception::NOT_FOUND) { $this->zookeeper->create("{$this->path}/status", serialize($status)); return; } throw $e; } } else { try { $this->zookeeper->delete("{$this->path}/status"); } catch (Scalr_Service_Zookeeper_Exception $ignore) { } } }
function remove($key) { $this->zookeeper->delete($this->formatKey($key)); }