예제 #1
0
 @Override
 public void terminated(State from) {
   LOG.info("Terminated: " + from + " " + id);
   if (zkFailure) {
     return;
   }
   StateNode stateNode = new StateNode(ServiceController.State.TERMINATED);
   final OperationFuture<Stat> stateFuture =
       zkClient.setData(getZKPath("state"), encodeStateNode(stateNode));
   stateFuture.addListener(
       new Runnable() {
         @Override
         public void run() {
           final OperationFuture<String> removeFuture = removeLiveNode();
           removeFuture.addListener(
               new Runnable() {
                 @Override
                 public void run() {
                   try {
                     stateFuture.get();
                     removeFuture.get();
                     notifyStopped();
                   } catch (Exception e) {
                     notifyFailed(e.getCause() == null ? e : e.getCause());
                   }
                 }
               },
               Threads.SAME_THREAD_EXECUTOR);
         }
       },
       Threads.SAME_THREAD_EXECUTOR);
 }
예제 #2
0
 private <V> void stopOnFailure(final OperationFuture<V> future) {
   future.addListener(
       new Runnable() {
         @Override
         public void run() {
           try {
             future.get();
           } catch (final Exception e) {
             LOG.error("ZK operation failed", e);
             zkFailure = true;
             decoratedService
                 .stop()
                 .addListener(
                     new Runnable() {
                       @Override
                       public void run() {
                         notifyFailed(e);
                       }
                     },
                     Threads.SAME_THREAD_EXECUTOR);
           }
         }
       },
       Threads.SAME_THREAD_EXECUTOR);
 }
예제 #3
0
  private static <V> OperationFuture<V> listenFailure(final OperationFuture<V> operationFuture) {
    operationFuture.addListener(
        new Runnable() {

          @Override
          public void run() {
            try {
              if (!operationFuture.isCancelled()) {
                operationFuture.get();
              }
            } catch (Exception e) {
              // TODO: what could be done besides just logging?
              LOG.error("Operation execution failed for " + operationFuture.getRequestPath(), e);
            }
          }
        },
        Threads.SAME_THREAD_EXECUTOR);
    return operationFuture;
  }