Пример #1
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);
 }
Пример #2
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);
     }
   }
 }
Пример #3
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);
      }
    }
  }