Ejemplo 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);
      }
    }
  }
Ejemplo 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());
   }
 }
Ejemplo n.º 3
0
 /**
  * Creates a string for debugging etc
  *
  * @return serialized version of the instance data.
  */
 public synchronized String toString() {
   return zkCoordinateData.snapshot().toString();
 }
Ejemplo n.º 4
0
 /**
  * Remove endpoints and persist it. Requires that this instance owns the tryClaim to the
  * coordinate.
  *
  * @param names names of endpoints to be removed.
  */
 public void removeEndpoints(final List<String> names)
     throws CloudnameException, CoordinateMissingException {
   zkCoordinateData.removeEndpoints(names);
   updateCoordinateData();
 }
Ejemplo n.º 5
0
 /**
  * Adds new endpoints and persist them. Requires that this instance owns the tryClaim to the
  * coordinate.
  *
  * @param newEndpoints endpoints to be added.
  */
 public void putEndpoints(final List<Endpoint> newEndpoints)
     throws CloudnameException, CoordinateMissingException {
   zkCoordinateData.putEndpoints(newEndpoints);
   updateCoordinateData();
 }
Ejemplo n.º 6
0
 /**
  * Updates the ServiceStatus and persists it. Only allowed if we claimed the coordinate.
  *
  * @param status The new value for serviceStatus.
  */
 public void updateStatus(final ServiceStatus status)
     throws CloudnameException, CoordinateMissingException {
   zkCoordinateData.setStatus(status);
   updateCoordinateData();
 }