Ejemplo n.º 1
0
  /**
   * Release the tryClaim of the coordinate. It means that nobody owns the coordinate anymore.
   * Requires that that this instance owns the tryClaim to the coordinate.
   */
  public void releaseClaim() throws CloudnameException {
    scheduler.shutdown();
    zkClient.deregisterListener(this);

    while (true) {
      final TrackedConfig config;
      synchronized (trackedConfigList) {
        if (trackedConfigList.isEmpty()) {
          break;
        }
        config = trackedConfigList.remove(0);
      }
      config.stop();
    }

    sendEventToCoordinateListener(
        CoordinateListener.Event.NOT_OWNER, "Released claim of coordinate");

    synchronized (lastStatusVersionMonitor) {
      try {
        zkClient.getZookeeper().delete(path, lastStatusVersion);
      } catch (InterruptedException e) {
        throw new CloudnameException(e);
      } catch (KeeperException e) {
        throw new CloudnameException(e);
      }
    }
  }
Ejemplo n.º 2
0
 /** Callbacks from zkClient */
 @Override
 public void connectionDown() {
   List<CoordinateListener> coordinateListenerListCopy = new ArrayList<CoordinateListener>();
   synchronized (coordinateListenerList) {
     coordinateListenerListCopy.addAll(coordinateListenerList);
   }
   for (CoordinateListener coordinateListener : coordinateListenerListCopy) {
     coordinateListener.onCoordinateEvent(
         CoordinateListener.Event.NO_CONNECTION_TO_STORAGE, "down");
   }
   isSynchronizedWithZooKeeper.set(false);
 }
Ejemplo n.º 3
0
 /**
  * Sends an event too all coordinate listeners. Note that the event is sent from this thread so if
  * the callback code does the wrong calls, deadlocks might occur.
  *
  * @param event
  * @param message
  */
 private void sendEventToCoordinateListener(
     final CoordinateListener.Event event, final String message) {
   synchronized (callbacksMonitor) {
     LOG.fine("Event " + event.name() + " " + message);
     List<CoordinateListener> coordinateListenerListCopy = new ArrayList<CoordinateListener>();
     synchronized (coordinateListenerList) {
       coordinateListenerListCopy.addAll(coordinateListenerList);
     }
     for (CoordinateListener listener : coordinateListenerListCopy) {
       listener.onCoordinateEvent(event, message);
     }
   }
 }
Ejemplo n.º 4
0
  /**
   * Registers a coordinatelistener that will receive events when there are changes to the status
   * node. Don't do any heavy lifting in the callback and don't call cloudname from the callback as
   * this might create a deadlock.
   *
   * @param coordinateListener
   */
  public void registerCoordinateListener(final CoordinateListener coordinateListener) {

    String message = "New listener added, resending current state.";
    synchronized (callbacksMonitor) {
      coordinateListenerList.add(coordinateListener);
      if (isSynchronizedWithZooKeeper.get()) {
        coordinateListener.onCoordinateEvent(CoordinateListener.Event.COORDINATE_OK, message);
      }
    }
  }
Ejemplo n.º 5
0
 /**
  * Registers a configlistener that will receive events when there are changes to the config node.
  * Don't do any heavy lifting in the callback and don't call cloudname from the callback as this
  * might create a deadlock.
  *
  * @param trackedConfig
  */
 public void registerTrackedConfig(final TrackedConfig trackedConfig) {
   trackedConfigList.add(trackedConfig);
 }
Ejemplo n.º 6
0
 public void deregisterCoordinateListener(final CoordinateListener coordinateListener) {
   coordinateListenerList.remove(coordinateListener);
 }