예제 #1
0
 private void validateConnection(CuratorEvent curatorEvent) {
   if (curatorEvent.getType() == CuratorEventType.WATCHED) {
     if (curatorEvent.getWatchedEvent().getState() == Watcher.Event.KeeperState.Disconnected) {
       connectionStateManager.addStateChange(ConnectionState.SUSPENDED);
       internalSync(
           this, "/",
           null); // we appear to have disconnected, force a new ZK event and see if we can connect
                  // to another server
     } else if (curatorEvent.getWatchedEvent().getState() == Watcher.Event.KeeperState.Expired) {
       connectionStateManager.addStateChange(ConnectionState.LOST);
     } else if (curatorEvent.getWatchedEvent().getState()
         == Watcher.Event.KeeperState.SyncConnected) {
       connectionStateManager.addStateChange(ConnectionState.RECONNECTED);
     } else if (curatorEvent.getWatchedEvent().getState()
         == Watcher.Event.KeeperState.ConnectedReadOnly) {
       connectionStateManager.addStateChange(ConnectionState.READ_ONLY);
     }
   }
 }
예제 #2
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;
          }
        });
  }