io.vertx.core.shareddata.Lock Java Examples

The following examples show how to use io.vertx.core.shareddata.Lock. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IgniteClusterManager.java    From vertx-ignite with Apache License 2.0 7 votes vote down vote up
@Override
public void getLockWithTimeout(String name, long timeout, Promise<Lock> promise) {
  vertx.executeBlocking(prom -> {
    IgniteSemaphore semaphore = ignite.semaphore(LOCK_SEMAPHORE_PREFIX + name, 1, true, true);
    boolean locked;
    long remaining = timeout;
    do {
      long start = System.nanoTime();
      locked = semaphore.tryAcquire(remaining, TimeUnit.MILLISECONDS);
      remaining = remaining - TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, NANOSECONDS);
    } while (!locked && remaining > 0);
    if (locked) {
      prom.complete(new LockImpl(semaphore, lockReleaseExec));
    } else {
      throw new VertxException("Timed out waiting to get lock " + name);
    }
  }, false, promise);
}
 
Example #2
Source File: ResponseExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T> void executeDefaultState(
    long _timeout,
    ThrowableFutureConsumer<T> _userOperation,
    VxmsShared vxmsShared,
    Promise<T> operationResult,
    Lock lock) {
  lock.release();
  if (_timeout > DEFAULT_LONG_VALUE) {
    addTimeoutHandler(
        _timeout,
        vxmsShared,
        (l) -> {
          if (!operationResult.future().isComplete()) {
            operationResult.fail(new TimeoutException("operation timeout"));
          }
        });
  }
  executeAndCompleate(_userOperation, operationResult);
}
 
Example #3
Source File: StepExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T> void openCircuitBreakerAndHandleError(
        Promise<ExecutionResult<T>> _blockingHandler,
        Consumer<Throwable> _errorHandler,
        ThrowableFunction<Throwable, T> _onFailureRespond,
        Consumer<Throwable> _errorMethodHandler,
        VxmsShared vxmsShared,
        Throwable e,
        Lock lck,
        Counter counter) {
    counter.addAndGet(
            LOCK_VALUE,
            val -> {
                lck.release();
                final Vertx vertx = vxmsShared.getVertx();
                vertx.executeBlocking(
                        bhandler -> {
                            T result = handleError(_errorHandler, _onFailureRespond, _errorMethodHandler, e);
                            if (!_blockingHandler.future().isComplete()) {
                                _blockingHandler.complete(new ExecutionResult<>(result, true, true, null));
                            }
                        },
                        false,
                        res -> {
                        });
            });
}
 
Example #4
Source File: ResponseExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T> void openCircuitBreakerAndHandleError(
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    Consumer<Throwable> errorMethodHandler,
    Consumer<ExecutionResult<T>> resultConsumer,
    AsyncResult<T> event,
    Lock lock,
    Counter counter) {
  counter.addAndGet(
      LOCK_VALUE,
      val -> {
        lock.release();
        errorHandling(
            errorHandler,
            onFailureRespond,
            errorMethodHandler,
            resultConsumer,
            Future.failedFuture(event.cause()));
      });
}
 
Example #5
Source File: StepExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T> void openCircuitBreakerAndHandleError(
        Promise<ExecutionResult<T>> _resultHandler,
    Consumer<Throwable> _errorHandler,
    ThrowableFunction<Throwable, T> _onFailureRespond,
    Consumer<Throwable> _errorMethodHandler,
    VxmsShared vxmsShared,
    Throwable e,
    Lock lck,
    Counter counter) {
  counter.addAndGet(
      LOCK_VALUE,
      val -> {
        lck.release();
        final Vertx vertx = vxmsShared.getVertx();
        vertx.executeBlocking(
            bhandler -> {
              T result = handleError(_errorHandler, _onFailureRespond, _errorMethodHandler, e);
              if (!_resultHandler.future().isComplete()) {
                _resultHandler.complete(new ExecutionResult<>(result, true, true, null));
              }
            },
            false,
            res -> {});
      });
}
 
Example #6
Source File: StepExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T> void openCircuitBreakerAndHandleError(
        Consumer<Throwable> errorHandler,
        ThrowableErrorConsumer<Throwable, T> onFailureRespond,
        Consumer<Throwable> errorMethodHandler,
        Consumer<ExecutionResult<T>> resultConsumer,
        AsyncResult<T> event,
        Lock lock,
        Counter counter) {
    counter.addAndGet(
            LOCK_VALUE,
            val -> {
                lock.release();
                errorHandling(
                        errorHandler,
                        onFailureRespond,
                        errorMethodHandler,
                        resultConsumer,
                        Future.failedFuture(event.cause()));
            });
}
 
Example #7
Source File: StepExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T> void openCircuitBreakerAndHandleError(
        Consumer<Throwable> errorHandler,
        ThrowableErrorConsumer<Throwable, T> onFailureRespond,
        Consumer<Throwable> errorMethodHandler,
        Consumer<ExecutionResult<T>> resultConsumer,
        AsyncResult<T> event,
        Lock lock,
        Counter counter) {
    counter.addAndGet(
            LOCK_VALUE,
            val -> {
                lock.release();
                errorHandling(
                        errorHandler,
                        onFailureRespond,
                        errorMethodHandler,
                        resultConsumer,
                        Future.failedFuture(event.cause()));
            });
}
 
Example #8
Source File: StepExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T, V> void executeDefaultState(
        long _timeout,
        ThrowableFutureBiConsumer<T, V> step,
        T inputValue,
        VxmsShared vxmsShared,
        Promise<V> operationResult,
        Lock lock) {
    lock.release();
    if (_timeout > DEFAULT_LONG_VALUE) {
        addTimeoutHandler(
                _timeout,
                vxmsShared,
                (l) -> {
                    if (!operationResult.future().isComplete()) {
                        operationResult.fail(new TimeoutException("operation timeout"));
                    }
                });
    }
    executeAndCompleate(step, inputValue, operationResult);
}
 
Example #9
Source File: StepExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T, V> void executeDefaultState(
        long _timeout,
        ThrowableFutureBiConsumer<T, V> _step,
        T _inputValue,
        VxmsShared vxmsShared,
        Promise<V> operationResult,
        Lock lock) {
    lock.release();
    if (_timeout > DEFAULT_LONG_VALUE) {
        addTimeoutHandler(
                _timeout,
                vxmsShared.getVertx(),
                (l) -> {
                    if (!operationResult.future().isComplete()) {
                        operationResult.fail(new TimeoutException("operation timeout"));
                    }
                });
    }
    executeAndCompleate(_step, _inputValue, operationResult);
}
 
Example #10
Source File: AtomixClusterManager.java    From atomix-vertx with Apache License 2.0 6 votes vote down vote up
@Override
public void getLockWithTimeout(String name, long timeout, Handler<AsyncResult<Lock>> handler) {
  Context context = vertx.getOrCreateContext();
  lockCache.getUnchecked(name).whenComplete((lock, error) -> {
    if (error == null) {
      lock.async().tryLock(Duration.ofMillis(timeout)).whenComplete((lockResult, lockError) -> {
        if (lockError == null) {
          if (lockResult.isPresent()) {
            context.runOnContext(v -> Future.<Lock>succeededFuture(new AtomixLock(vertx, lock)).setHandler(handler));
          } else {
            context.runOnContext(v -> Future.<Lock>failedFuture(new VertxException("Timed out waiting to get lock " + name)).setHandler(handler));
          }
        } else {
          context.runOnContext(v -> Future.<Lock>failedFuture(lockError).setHandler(handler));
        }
      });
    } else {
      context.runOnContext(v -> Future.<Lock>failedFuture(error).setHandler(handler));
    }
  });
}
 
Example #11
Source File: ResponseExecution.java    From vxms with Apache License 2.0 6 votes vote down vote up
private static <T> void executeDefaultState(
    long _timeout,
    ThrowableFutureConsumer<T> _userOperation,
    VxmsShared vxmsShared,
    Promise<T> operationResult,
    Lock lock) {
  lock.release();
  if (_timeout > DEFAULT_LONG_VALUE) {
    addTimeoutHandler(
        _timeout,
        vxmsShared.getVertx(),
        (l) -> {
          if (!operationResult.future().isComplete()) {
            operationResult.fail(new TimeoutException("operation timeout"));
          }
        });
  }
  executeAndCompleate(_userOperation, operationResult);
}
 
Example #12
Source File: ResponseExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void executeInitialState(
    int retry,
    long timeout,
    ThrowableFutureConsumer<T> _userOperation,
    VxmsShared vxmsShared,
    Promise<T> operationResult,
    Lock lock,
    Counter counter) {
  final long initialRetryCounterValue = (long) (retry + 1);
  counter.addAndGet(
      initialRetryCounterValue,
      rHandler ->
          executeDefaultState(timeout, _userOperation, vxmsShared, operationResult, lock));
}
 
Example #13
Source File: StepExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void releaseLockAndHandleError(
        Consumer<Throwable> errorHandler,
        ThrowableErrorConsumer<Throwable, T> onFailureRespond,
        Consumer<Throwable> errorMethodHandler,
        Consumer<ExecutionResult<T>> resultConsumer,
        Lock lock,
        Throwable cause) {
    Optional.ofNullable(lock).ifPresent(Lock::release);
    errorHandling(
            errorHandler,
            onFailureRespond,
            errorMethodHandler,
            resultConsumer,
            Future.failedFuture(cause));
}
 
Example #14
Source File: EventbusExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void handleError(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    RoutingContext context,
    Map<String, String> headers,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    int httpStatusCode,
    int httpErrorCode,
    int retryCount,
    long timeout,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    Lock lock,
    Throwable cause) {
  Optional.ofNullable(lock).ifPresent(Lock::release);
  final ThrowableFutureConsumer<T> failConsumer = (future) -> future.fail(cause);
  executor.execute(
      methodId,
      vxmsShared,
      cause,
      errorMethodHandler,
      context,
      headers,
      failConsumer,
      null,
      encoder,
      errorHandler,
      onFailureRespond,
      httpStatusCode,
      httpErrorCode,
      retryCount,
      timeout,
      circuitBreakerTimeout);
}
 
Example #15
Source File: StepExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void executeErrorState(
        Promise<ExecutionResult<T>> _blockingHandler,
        Consumer<Throwable> _errorHandler,
        ThrowableFunction<Throwable, T> _onFailureRespond,
        Consumer<Throwable> _errorMethodHandler,
        Throwable t,
        Lock lock) {
    Optional.ofNullable(lock).ifPresent(Lock::release);
    handleErrorExecution(
            _blockingHandler,
            _errorHandler,
            _onFailureRespond,
            _errorMethodHandler,
            Optional.ofNullable(t).orElse(Future.failedFuture("circuit open").cause()));
}
 
Example #16
Source File: ResponseExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void openCircuitBreakerAndHandleError(
        Promise<ExecutionResult<T>> _blockingHandler,
    Consumer<Throwable> _errorHandler,
    ThrowableFunction<Throwable, T> _onFailureRespond,
    Consumer<Throwable> _errorMethodHandler,
    VxmsShared vxmsShared,
    Throwable e,
    Lock lck,
    Counter counter) {
  counter.addAndGet(
      LOCK_VALUE,
      val -> {
        lck.release();
        final Vertx vertx = vxmsShared.getVertx();
        vertx.executeBlocking(
            bhandler -> {
              T result =
                  handleError(
                      _errorHandler, _onFailureRespond, _errorMethodHandler, _blockingHandler, e);
              if (!_blockingHandler.future().isComplete()) {
                _blockingHandler.complete(new ExecutionResult<>(result, true, true, null));
              }
            },
            false,
            res -> {});
      });
}
 
Example #17
Source File: ResponseExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void releaseLockAndHandleError(
        Promise<ExecutionResult<T>> _blockingHandler,
    Consumer<Throwable> _errorHandler,
    ThrowableFunction<Throwable, T> _onFailureRespond,
    Consumer<Throwable> _errorMethodHandler,
    Throwable cause,
    Lock lock) {
  Optional.ofNullable(lock).ifPresent(Lock::release);
  handleErrorExecution(
      _blockingHandler, _errorHandler, _onFailureRespond, _errorMethodHandler, cause);
}
 
Example #18
Source File: ResponseExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void executeErrorState(
        Promise<ExecutionResult<T>> _blockingHandler,
    Consumer<Throwable> _errorHandler,
    ThrowableFunction<Throwable, T> _onFailureRespond,
    Consumer<Throwable> _errorMethodHandler,
    Throwable t,
    Lock lock) {
  Optional.ofNullable(lock).ifPresent(Lock::release);
  handleErrorExecution(
      _blockingHandler,
      _errorHandler,
      _onFailureRespond,
      _errorMethodHandler,
      Optional.ofNullable(t).orElse(Future.failedFuture("circuit open").cause()));
}
 
Example #19
Source File: ResponseExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void executeInitialState(
    String _methodId,
    ThrowableSupplier<T> _supplier,
    Promise<ExecutionResult<T>> _blockingHandler,
    Consumer<Throwable> _errorHandler,
    ThrowableFunction<Throwable, T> _onFailureRespond,
    Consumer<Throwable> _errorMethodHandler,
    VxmsShared vxmsShared,
    Throwable _t,
    int _retry,
    long _timeout,
    long _circuitBreakerTimeout,
    long _delay,
    Lock lock,
    Counter counter) {
  final long initialRetryCounterValue = (long) (_retry + 1);
  counter.addAndGet(
      initialRetryCounterValue,
      rHandler ->
          executeDefault(
              _methodId,
              _supplier,
              _blockingHandler,
              _errorHandler,
              _onFailureRespond,
              _errorMethodHandler,
              vxmsShared,
              _t,
              _retry,
              _timeout,
              _circuitBreakerTimeout,
              _delay,
              lock));
}
 
Example #20
Source File: StepExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T, V> void handleStatefulError(
        String methodId,
        int retry,
        long timeout,
        long circuitBreakerTimeout,
        ThrowableFutureBiConsumer<T, V> _step,
        T _inputValue,
        Consumer<Throwable> errorHandler,
        ThrowableErrorConsumer<Throwable, V> onFailureRespond,
        Consumer<Throwable> errorMethodHandler,
        VxmsShared vxmsShared,
        Consumer<ExecutionResult<V>> resultConsumer,
        AsyncResult<V> event,
        Lock lock,
        Counter counter,
        AsyncResult<Long> valHandler) {
    long count = valHandler.result();
    if (count <= DEFAULT_LONG_VALUE) {
        setCircuitBreakerReleaseTimer(retry, circuitBreakerTimeout, vxmsShared.getVertx(), counter);
        openCircuitBreakerAndHandleError(
                errorHandler, onFailureRespond, errorMethodHandler, resultConsumer, event, lock, counter);
    } else {
        lock.release();
        retry(
                methodId,
                retry,
                timeout,
                circuitBreakerTimeout,
                _step,
                _inputValue,
                errorHandler,
                onFailureRespond,
                errorMethodHandler,
                vxmsShared,
                resultConsumer,
                event);
    }
}
 
Example #21
Source File: ResponseExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void releaseLockAndHandleError(
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    Consumer<Throwable> errorMethodHandler,
    Consumer<ExecutionResult<T>> resultConsumer,
    Lock lock,
    Throwable cause) {
  Optional.ofNullable(lock).ifPresent(Lock::release);
  errorHandling(
      errorHandler,
      onFailureRespond,
      errorMethodHandler,
      resultConsumer,
      Future.failedFuture(cause));
}
 
Example #22
Source File: LocalData.java    From vxms with Apache License 2.0 5 votes vote down vote up
/**
 * Get a local lock with the specified name with specifying a timeout. The lock will be passed to
 * the handler when it is available.  If the lock is not obtained within the timeout a failure
 * will be sent to the handler
 *
 * @param name the name of the lock
 * @param timeout the timeout in ms
 * @param resultHandler the handler
 */
public void getLockWithTimeout(String name, long timeout,
    Handler<AsyncResult<Lock>> resultHandler) {
  Objects.requireNonNull(name, "name");
  Objects.requireNonNull(resultHandler, "resultHandler");
  Arguments.require(timeout >= 0L, "timeout must be >= 0");
  LocalAsyncLocks lock = this.localLocks
      .computeIfAbsent(name, (n) -> new LocalAsyncLocks());
  lock.acquire(this.vertx.getOrCreateContext(),name,timeout, resultHandler);

}
 
Example #23
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void handleError(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    Message<Object> requestMessage,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableFunction<Throwable, T> onFailureRespond,
    DeliveryOptions responseDeliveryOptions,
    int retryCount,
    long timeout,
    long delay,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    Lock lock,
    Throwable cause) {
  Optional.ofNullable(lock).ifPresent(Lock::release);
  final ThrowableSupplier<T> failConsumer =
      () -> {
        assert cause != null;
        throw cause;
      };
  executor.execute(
      methodId,
      vxmsShared,
      cause,
      errorMethodHandler,
      requestMessage,
      failConsumer,
      encoder,
      errorHandler,
      onFailureRespond,
      responseDeliveryOptions,
      retryCount,
      timeout,
      delay,
      circuitBreakerTimeout);
}
 
Example #24
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void openCircuitAndHandleError(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    Message<Object> requestMessage,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableFunction<Throwable, T> onFailureRespond,
    DeliveryOptions responseDeliveryOptions,
    int retryCount,
    long timeout,
    long delay,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    AsyncResult<Message<Object>> event,
    Lock lock,
    Counter counter) {
  resetLockTimer(vxmsShared, retryCount, circuitBreakerTimeout, counter);
  lockAndHandle(
      counter,
      val -> {
        final Throwable cause = event.cause();
        handleError(
            methodId,
            vxmsShared,
            errorMethodHandler,
            requestMessage,
            encoder,
            errorHandler,
            onFailureRespond,
            responseDeliveryOptions,
            retryCount,
            timeout,
            delay,
            circuitBreakerTimeout,
            executor,
            lock,
            cause);
      });
}
 
Example #25
Source File: AbstractOperator.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
/**
 * Acquire the lock for the resource implied by the {@code reconciliation}
 * and call the given {@code callable} with the lock held.
 * Once the callable returns (or if it throws) release the lock and complete the returned Future.
 * If the lock cannot be acquired the given {@code callable} is not called and the returned Future is completed with {@link UnableToAcquireLockException}.
 * @param reconciliation
 * @param callable
 * @param <T>
 * @return
 */
protected final <T> Future<T> withLock(Reconciliation reconciliation, long lockTimeoutMs, Callable<Future<T>> callable) {
    Promise<T> handler = Promise.promise();
    String namespace = reconciliation.namespace();
    String name = reconciliation.name();
    final String lockName = getLockName(namespace, name);
    log.debug("{}: Try to acquire lock {}", reconciliation, lockName);
    vertx.sharedData().getLockWithTimeout(lockName, lockTimeoutMs, res -> {
        if (res.succeeded()) {
            log.debug("{}: Lock {} acquired", reconciliation, lockName);
            Lock lock = res.result();
            try {
                callable.call().onComplete(callableRes -> {
                    if (callableRes.succeeded()) {
                        handler.complete(callableRes.result());
                    } else {
                        handler.fail(callableRes.cause());
                    }

                    lock.release();
                    log.debug("{}: Lock {} released", reconciliation, lockName);
                });
            } catch (Throwable ex) {
                lock.release();
                log.debug("{}: Lock {} released", reconciliation, lockName);
                log.error("{}: Reconciliation failed", reconciliation, ex);
                handler.fail(ex);
            }
        } else {
            log.warn("{}: Failed to acquire lock {} within {}ms.", reconciliation, lockName, lockTimeoutMs);
            handler.fail(new UnableToAcquireLockException());
        }
    });
    return handler.future();
}
 
Example #26
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void handleError(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    Message<Object> requestMessage,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    DeliveryOptions responseDeliveryOptions,
    int retryCount,
    long timeout,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    Lock lock,
    Throwable cause) {
  Optional.ofNullable(lock).ifPresent(Lock::release);
  final ThrowableFutureConsumer<T> failConsumer = (future) -> future.fail(cause);
  executor.execute(
      methodId,
      vxmsShared,
      cause,
      errorMethodHandler,
      requestMessage,
      failConsumer,
      encoder,
      errorHandler,
      onFailureRespond,
      responseDeliveryOptions,
      retryCount,
      timeout,
      circuitBreakerTimeout);
}
 
Example #27
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void openCircuitAndHandleError(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    Message<Object> requestMessage,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    DeliveryOptions responseDeliveryOptions,
    int retryCount,
    long timeout,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    AsyncResult<Message<Object>> event,
    Lock lock,
    Counter counter) {
  resetLockTimer(vxmsShared, retryCount, circuitBreakerTimeout, counter);
  lockAndHandle(
      counter,
      val -> {
        final Throwable cause = event.cause();
        handleError(
            methodId,
            vxmsShared,
            errorMethodHandler,
            requestMessage,
            encoder,
            errorHandler,
            onFailureRespond,
            responseDeliveryOptions,
            retryCount,
            timeout,
            circuitBreakerTimeout,
            executor,
            lock,
            cause);
      });
}
 
Example #28
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void executeErrorState(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    Message<Object> requestMessage,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    DeliveryOptions responseDeliveryOptions,
    int retryCount,
    long timeout,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    Lock lock) {
  final Throwable cause = Future.failedFuture("circuit open").cause();
  handleError(
      methodId,
      vxmsShared,
      errorMethodHandler,
      requestMessage,
      encoder,
      errorHandler,
      onFailureRespond,
      responseDeliveryOptions,
      retryCount,
      timeout,
      circuitBreakerTimeout,
      executor,
      lock,
      cause);
}
 
Example #29
Source File: EventbusExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void executeErrorState(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    RoutingContext context,
    Map<String, String> headers,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    int httpStatusCode,
    int httpErrorCode,
    int retryCount,
    long timeout,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    Lock lock) {
  final Throwable cause = Future.failedFuture("circuit open").cause();
  handleError(
      methodId,
      vxmsShared,
      errorMethodHandler,
      context,
      headers,
      encoder,
      errorHandler,
      onFailureRespond,
      httpStatusCode,
      httpErrorCode,
      retryCount,
      timeout,
      circuitBreakerTimeout,
      executor,
      lock,
      cause);
}
 
Example #30
Source File: ResponseExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T> void handleStatefulError(
    String methodId,
    int retry,
    long timeout,
    long circuitBreakerTimeout,
    ThrowableFutureConsumer<T> _userOperation,
    Consumer<Throwable> errorHandler,
    ThrowableErrorConsumer<Throwable, T> onFailureRespond,
    Consumer<Throwable> errorMethodHandler,
    VxmsShared vxmsShared,
    Consumer<ExecutionResult<T>> resultConsumer,
    AsyncResult<T> event,
    Lock lock,
    Counter counter,
    AsyncResult<Long> valHandler) {
  long count = valHandler.result();
  if (count <= DEFAULT_LONG_VALUE) {
    setCircuitBreakerReleaseTimer(retry, circuitBreakerTimeout, vxmsShared.getVertx(), counter);
    openCircuitBreakerAndHandleError(
        errorHandler, onFailureRespond, errorMethodHandler, resultConsumer, event, lock, counter);
  } else {
    lock.release();
    retry(
        methodId,
        retry,
        timeout,
        circuitBreakerTimeout,
        _userOperation,
        errorHandler,
        onFailureRespond,
        errorMethodHandler,
        vxmsShared,
        resultConsumer,
        event);
  }
}