Java Code Examples for io.vertx.core.shareddata.Counter#addAndGet()

The following examples show how to use io.vertx.core.shareddata.Counter#addAndGet() . 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: 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 2
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 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>> _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 4
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 5
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 6
Source File: StepExecution.java    From vxms with Apache License 2.0 5 votes vote down vote up
private static <T, V> void executeInitialState(
        int _retry,
        long _timeout,
        ThrowableFutureBiConsumer<T, V> step,
        T inputValue,
        VxmsShared vxmsShared,
        Promise<V> operationResult,
        Lock lock,
        Counter counter) {
    final long initialRetryCounterValue = (long) (_retry + 1);
    counter.addAndGet(
            initialRetryCounterValue,
            rHandler ->
                    executeDefaultState(_timeout, step, inputValue, vxmsShared, operationResult, lock));
}
 
Example 7
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 8
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 9
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 10
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 11
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 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, V> void executeInitialState(
        int retry,
        long timeout,
        ThrowableFutureBiConsumer<T, V> _step,
        T _inputValue,
        VxmsShared vxmsShared,
        Promise<V> operationResult,
        Lock lock,
        Counter counter) {
    final long initialRetryCounterValue = (long) (retry + 1);
    counter.addAndGet(
            initialRetryCounterValue,
            rHandler ->
                    executeDefaultState(timeout, _step, _inputValue, vxmsShared, operationResult, lock));
}
 
Example 14
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 4 votes vote down vote up
private static <T> void executeInitialState(
    String methodId,
    String targetId,
    Object message,
    ThrowableFunction<AsyncResult<Message<Object>>, T> byteFunction,
    DeliveryOptions deliveryOptions,
    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,
    RetryExecutor<T> retry,
    Lock lock,
    Counter counter) {
  int incrementCounter = retryCount + 1;
  counter.addAndGet(
      Integer.valueOf(incrementCounter).longValue(),
      rHandler ->
          executeDefaultState(
              methodId, targetId,
              message,
              byteFunction,
              deliveryOptions,
              vxmsShared,
              errorMethodHandler,
              requestMessage,
              encoder,
              errorHandler,
              onFailureRespond,
              responseDeliveryOptions,
              retryCount,
              timeout,
              delay,
              circuitBreakerTimeout,
              executor,
              retry,
              lock));
}
 
Example 15
Source File: EventbusExecution.java    From vxms with Apache License 2.0 4 votes vote down vote up
private static <T> void executeInitialState(
    String methodId,
    String id,
    Object message,
    ThrowableFunction<AsyncResult<Message<Object>>, T> function,
    DeliveryOptions deliveryOptions,
    VxmsShared vxmsShared,
    Throwable t,
    Consumer<Throwable> errorMethodHandler,
    RoutingContext context,
    Map<String, String> headers,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableFunction<Throwable, T> onFailureRespond,
    int httpStatusCode,
    int httpErrorCode,
    int retryCount,
    long timeout,
    long delay,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    RetryExecutor<T> retry,
    Lock lock,
    Counter counter) {
  counter.addAndGet(
      Integer.valueOf(retryCount + 1).longValue(),
      rHandler ->
          executeDefaultState(
              methodId,
              id,
              message,
              function,
              deliveryOptions,
              vxmsShared,
              t,
              errorMethodHandler,
              context,
              headers,
              encoder,
              errorHandler,
              onFailureRespond,
              httpStatusCode,
              httpErrorCode,
              retryCount,
              timeout,
              delay,
              circuitBreakerTimeout,
              executor,
              retry,
              lock));
}
 
Example 16
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 4 votes vote down vote up
private static void lockAndHandle(
    Counter counter, Handler<AsyncResult<Long>> asyncResultHandler) {
  counter.addAndGet(LOCK_VALUE, asyncResultHandler);
}
 
Example 17
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 4 votes vote down vote up
private static void lockAndHandle(
    Counter counter, Handler<AsyncResult<Long>> asyncResultHandler) {
  counter.addAndGet(LOCK_VALUE, asyncResultHandler);
}
 
Example 18
Source File: EventbusBridgeExecution.java    From vxms with Apache License 2.0 4 votes vote down vote up
private static <T> void executeInitialState(
    String methodId,
    String targetId,
    Object message,
    ThrowableFutureBiConsumer<AsyncResult<Message<Object>>, T> objectFunction,
    DeliveryOptions requestDeliveryOptions,
    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,
    RetryExecutor<T> retry,
    Lock lock,
    Counter counter) {
  int incrementCounter = retryCount + 1;
  counter.addAndGet(
      Integer.valueOf(incrementCounter).longValue(),
      rHandler ->
          executeDefaultState(
              methodId,
              targetId,
              message,
              objectFunction,
              requestDeliveryOptions,
              vxmsShared,
              errorMethodHandler,
              requestMessage,
              encoder,
              errorHandler,
              onFailureRespond,
              responseDeliveryOptions,
              retryCount,
              timeout,
              circuitBreakerTimeout,
              executor,
              retry,
              lock));
}
 
Example 19
Source File: EventbusExecution.java    From vxms with Apache License 2.0 4 votes vote down vote up
private static <T> void openCircuitAndHandleError(
    String methodId,
    VxmsShared vxmsShared,
    Consumer<Throwable> errorMethodHandler,
    RoutingContext context,
    Map<String, String> headers,
    Encoder encoder,
    Consumer<Throwable> errorHandler,
    ThrowableFunction<Throwable, T> onFailureRespond,
    int httpStatusCode,
    int httpErrorCode,
    int retryCount,
    long timeout,
    long delay,
    long circuitBreakerTimeout,
    RecursiveExecutor<T> executor,
    AsyncResult<Message<Object>> event,
    Lock lock,
    Counter counter) {
  final Vertx vertx = vxmsShared.getVertx();
  vertx.setTimer(
      circuitBreakerTimeout,
      timer -> counter.addAndGet(Integer.valueOf(retryCount + 1).longValue(), val -> {}));
  counter.addAndGet(
      LOCK_VALUE,
      val -> {
        final Throwable cause = event.cause();
        handleError(
            methodId,
            vxmsShared,
            errorMethodHandler,
            context,
            headers,
            encoder,
            errorHandler,
            onFailureRespond,
            httpStatusCode,
            httpErrorCode,
            retryCount,
            timeout,
            delay,
            circuitBreakerTimeout,
            executor,
            lock,
            cause);
      });
}
 
Example 20
Source File: EventbusExecution.java    From vxms with Apache License 2.0 4 votes vote down vote up
private static <T> void executeInitialState(
    String methodId,
    String id,
    Object message,
    ThrowableFutureBiConsumer<AsyncResult<Message<Object>>, T> stringFunction,
    DeliveryOptions deliveryOptions,
    VxmsShared vxmsShared,
    Throwable t,
    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,
    RetryExecutor<T> retry,
    Lock lock,
    Counter counter) {
  counter.addAndGet(
      Integer.valueOf(retryCount + 1).longValue(),
      rHandler ->
          executeDefaultState(
              methodId,
              id,
              message,
              stringFunction,
              deliveryOptions,
              vxmsShared,
              t,
              errorMethodHandler,
              context,
              headers,
              encoder,
              errorHandler,
              onFailureRespond,
              httpStatusCode,
              httpErrorCode,
              retryCount,
              timeout,
              circuitBreakerTimeout,
              executor,
              retry,
              lock));
}