function enter($data = null) { // who will be first? $iAmFirst = false; try { $this->zookeeper->create($this->path); $iAmFirst = true; } catch (Scalr_Service_Zookeeper_Exception $e) { if ($e->getCode() != Scalr_Service_Zookeeper_Exception::CONFLICT) { throw $e; } } // create child node $this->zookeeper->create("{$this->path}/n", $data ? serialize($data) : null, array(Scalr_Service_Zookeeper::OPT_SEQUENCE => true)); // wait while all nodes will enter barrier try { while ($this->timeout && !$this->timeout->reached() || !$this->timeout) { if ($iAmFirst && $this->capacity() >= $this->quorum || !$iAmFirst && !$this->zookeeper->exists($this->path)) { break; } else { Scalr_Util_Timeout::sleep(100); } } } catch (Exception $e) { // Finally delete barrier znode if ($this->autoDelete) { $this->delete(); } throw $e; } if ($this->autoDelete) { $this->delete(); } }
protected function init() { if (!$this->initialized) { if (!$this->zookeeper->exists($this->path)) { $this->zookeeper->create($this->path); } $this->initialized = true; } }
protected function init() { if (!$this->initialized) { if (!$this->zookeeper->exists($this->path)) { $this->zookeeper->setOrCreate($this->path, "", false); } $this->initialized = true; } }