コード例 #1
0
    final CheckedListenableFuture<Boolean> dispatch() {
      try {
        final CheckedListenableFuture<Boolean> future = Futures.newGenericeFuture();
        dispatchInternal(
            new Callback.Checked<TM>() {
              @Override
              public void fireException(final Throwable throwable) {
                try {
                  dispatchFailure(throwable);
                } finally {
                  future.set(false);
                }
              }

              @Override
              public void fire(final TM response) {
                try {
                  dispatchSuccess(response);
                } finally {
                  future.set(true);
                }
              }
            });
        dispatched = true;
        return future;
      } catch (Exception e) {
        LOG.error(e, e);
      }
      return Futures.predestinedFuture(false);
    }
コード例 #2
0
  final CheckedListenableFuture<Boolean> dispatch(final ClientContext<TM, TC> context) {
    try {
      final CheckedListenableFuture<Boolean> future = Futures.newGenericeFuture();
      dispatchInternal(
          context,
          new Callback.Checked<TM>() {
            @Override
            public void fireException(final Throwable throwable) {
              boolean result = false;
              try {
                result = dispatchFailure(context, throwable);
              } finally {
                future.set(result);
              }
            }

            @Override
            public void fire(final TM response) {
              try {
                dispatchSuccess(context, response);
              } finally {
                future.set(true);
              }
            }
          });
      return future;
    } catch (Exception e) {
      LOG.error("Got error", e);
    }
    return Futures.predestinedFuture(false);
  }
コード例 #3
0
  private static void runDbStateChange(Function<String, Runnable> runnableFunction) {
    Logs.extreme().info("DB STATE CHANGE: " + runnableFunction);
    try {
      Logs.extreme().info("Attempting to acquire db state lock: " + runnableFunction);
      if (canHas.writeLock().tryLock(5, TimeUnit.MINUTES)) {

        try {
          Logs.extreme().info("Acquired db state lock: " + runnableFunction);
          Map<Runnable, Future<Runnable>> runnables = Maps.newHashMap();
          for (final String ctx : listDatabases()) {
            Runnable run = runnableFunction.apply(ctx);
            runnables.put(run, ExecuteRunnable.INSTANCE.apply(run));
          }
          Map<Runnable, Future<Runnable>> succeeded = Futures.waitAll(runnables);
          MapDifference<Runnable, Future<Runnable>> failed = Maps.difference(runnables, succeeded);
          StringBuilder builder = new StringBuilder();
          builder.append(Joiner.on("\nSUCCESS: ").join(succeeded.keySet()));
          builder.append(Joiner.on("\nFAILED:  ").join(failed.entriesOnlyOnLeft().keySet()));
          Logs.extreme().debug(builder.toString());
          if (!failed.entriesOnlyOnLeft().isEmpty()) {
            throw Exceptions.toUndeclared(builder.toString());
          }
        } finally {
          canHas.writeLock().unlock();
        }
      } else {
        throw new LockTimeoutException(
            "DB STATE CHANGE ABORTED (failed to get lock): " + runnableFunction);
      }
    } catch (RuntimeException ex) {
      LOG.error(ex);
      Logs.extreme().error(ex, ex);
      throw ex;
    } catch (InterruptedException ex) {
      Exceptions.maybeInterrupted(ex);
      throw Exceptions.toUndeclared(ex);
    }
  }