Exemplo n.º 1
0
 private void notifyListenerOfStateChanged(final ConnectionState newState) {
   listeners.forEach(
       new Function<SharedValueListener, Void>() {
         @Override
         public Void apply(SharedValueListener listener) {
           listener.stateChanged(client, newState);
           return null;
         }
       });
 }
Exemplo n.º 2
0
  @Override
  public void close() {
    log.debug("Closing");
    if (state.compareAndSet(CuratorFrameworkState.STARTED, CuratorFrameworkState.STOPPED)) {
      listeners.forEach(
          new Function<CuratorListener, Void>() {
            @Override
            public Void apply(CuratorListener listener) {
              CuratorEvent event =
                  new CuratorEventImpl(
                      CuratorFrameworkImpl.this,
                      CuratorEventType.CLOSING,
                      0,
                      null,
                      null,
                      null,
                      null,
                      null,
                      null,
                      null,
                      null);
              try {
                listener.eventReceived(CuratorFrameworkImpl.this, event);
              } catch (Exception e) {
                log.error("Exception while sending Closing event", e);
              }
              return null;
            }
          });

      listeners.clear();
      unhandledErrorListeners.clear();
      connectionStateManager.close();
      client.close();
      namespaceWatcherMap.close();
      executorService.shutdownNow();
    }
  }
Exemplo n.º 3
0
 private void notifyListeners() {
   listeners.forEach(
       new Function<SharedValueListener, Void>() {
         @Override
         public Void apply(SharedValueListener listener) {
           try {
             listener.valueHasChanged(SharedValue.this, value);
           } catch (Exception e) {
             log.error("From SharedValue listener", e);
           }
           return null;
         }
       });
 }
Exemplo n.º 4
0
  private void processEvent(final CuratorEvent curatorEvent) {
    validateConnection(curatorEvent);

    listeners.forEach(
        new Function<CuratorListener, Void>() {
          @Override
          public Void apply(CuratorListener listener) {
            try {
              TimeTrace trace = client.startTracer("EventListener");
              listener.eventReceived(CuratorFrameworkImpl.this, curatorEvent);
              trace.commit();
            } catch (Exception e) {
              logError("Event listener threw exception", e);
            }
            return null;
          }
        });
  }
Exemplo n.º 5
0
  void logError(String reason, final Throwable e) {
    if ((reason == null) || (reason.length() == 0)) {
      reason = "n/a";
    }

    if (!Boolean.getBoolean(DebugUtils.PROPERTY_DONT_LOG_CONNECTION_ISSUES)
        || !(e instanceof KeeperException)) {
      log.error(reason, e);
    }

    if (e instanceof KeeperException.ConnectionLossException) {
      connectionStateManager.addStateChange(ConnectionState.LOST);
    }

    final String localReason = reason;
    unhandledErrorListeners.forEach(
        new Function<UnhandledErrorListener, Void>() {
          @Override
          public Void apply(UnhandledErrorListener listener) {
            listener.unhandledError(localReason, e);
            return null;
          }
        });
  }
Exemplo n.º 6
0
 @Override
 public void close() throws IOException {
   client.getConnectionStateListenable().removeListener(connectionStateListener);
   state.set(State.CLOSED);
   listeners.clear();
 }