Esempio n. 1
0
  /**
   * Creates the serialized value of the object and stores this in ZooKeeper under the path. It
   * updates the lastStatusVersion. It does not set a watcher for the path.
   */
  private void updateCoordinateData() throws CoordinateMissingException, CloudnameException {
    if (!started.get()) {
      throw new IllegalStateException("Not started.");
    }

    if (!zkClient.isConnected()) {
      throw new CloudnameException("No proper connection with zookeeper.");
    }

    synchronized (lastStatusVersionMonitor) {
      try {
        Stat stat =
            zkClient
                .getZookeeper()
                .setData(
                    path,
                    zkCoordinateData.snapshot().serialize().getBytes(Util.CHARSET_NAME),
                    lastStatusVersion);
        LOG.fine("Updated coordinate, latest version is " + stat.getVersion());
        lastStatusVersion = stat.getVersion();
      } catch (KeeperException.NoNodeException e) {
        throw new CoordinateMissingException("Coordinate does not exist " + path);
      } catch (KeeperException e) {
        throw new CloudnameException(
            "ZooKeeper errror in updateCoordinateData: " + e.getMessage(), e);
      } catch (UnsupportedEncodingException e) {
        throw new CloudnameException(e);
      } catch (InterruptedException e) {
        throw new CloudnameException(e);
      } catch (IOException e) {
        throw new CloudnameException(e);
      }
    }
  }
Esempio n. 2
0
 private void tryClaim() {
   try {
     zkClient
         .getZookeeper()
         .create(
             path,
             zkCoordinateData.snapshot().serialize().getBytes(Util.CHARSET_NAME),
             ZooDefs.Ids.OPEN_ACL_UNSAFE,
             CreateMode.EPHEMERAL,
             new ClaimCallback(),
             this);
   } catch (IOException e) {
     LOG.info("Got IO exception on claim with new ZooKeeper instance " + e.getMessage());
   }
 }
Esempio n. 3
0
 /**
  * Creates a string for debugging etc
  *
  * @return serialized version of the instance data.
  */
 public synchronized String toString() {
   return zkCoordinateData.snapshot().toString();
 }