本文整理汇总了Java中io.vertx.core.shareddata.Counter类的典型用法代码示例。如果您正苦于以下问题:Java Counter类的具体用法?Java Counter怎么用?Java Counter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Counter类属于io.vertx.core.shareddata包,在下文中一共展示了Counter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: openCircuitBreakerAndHandleError
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
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()));
});
}
示例2: openCircuitBreakerAndHandleError
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static <T> void openCircuitBreakerAndHandleError(
Future<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.isComplete()) {
_blockingHandler.complete(new ExecutionResult<>(result, true, true, null));
}
},
false,
res -> {});
});
}
示例3: openCircuitBreakerAndHandleError
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static <T> void openCircuitBreakerAndHandleError(
Future<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.isComplete()) {
_resultHandler.complete(new ExecutionResult<>(result, true, true, null));
}
},
false,
res -> {});
});
}
示例4: testAtomicSyncCounter3
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
@Test
public void testAtomicSyncCounter3() {
long max = 3;
vertx
.sharedData()
.getCounter(
"counter1",
resultHandler -> {
final Counter counter = resultHandler.result();
counter.get(
handler -> {
long val = handler.result();
if (val == 0) {
counter.addAndGet(
max,
hhh -> {
System.out.println("::::" + hhh.result());
});
} else {
}
});
});
}
示例5: getCounter
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
@Override
public void getCounter(final String name, final Handler<AsyncResult<Counter>> resultHandler) {
AtomicLong counter = new AtomicLong();
final AtomicLong prev = counters.putIfAbsent(name, counter);
if (prev != null) {
counter = prev;
}
final AtomicLong theCounter = counter;
final Context context = this.vertx.getOrCreateContext();
context.runOnContext(v -> resultHandler.handle(Future.succeededFuture(new AsynchronousCounter(this.vertx, theCounter))));
}
示例6: getCounter
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
@Override
public void getCounter(String name, Handler<AsyncResult<Counter>> resultHandler) {
vertx.executeBlocking(future -> {
try {
Objects.requireNonNull(name);
future.complete(new ZKCounter(name, retryPolicy));
} catch (Exception e) {
future.fail(new VertxException(e));
}
}, resultHandler);
}
示例7: executeInitialState
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static <T> void executeInitialState(
int _retry,
long _timeout,
ThrowableFutureConsumer<T> _userOperation,
VxmsShared vxmsShared,
Future<T> operationResult,
Lock lock,
Counter counter) {
final long initialRetryCounterValue = (long) (_retry + 1);
counter.addAndGet(
initialRetryCounterValue,
rHandler ->
executeDefaultState(_timeout, _userOperation, vxmsShared, operationResult, lock));
}
示例8: handleStatefulError
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
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, counter);
openCircuitBreakerAndHandleError(
errorHandler, onFailureRespond, errorMethodHandler, resultConsumer, event, lock, counter);
} else {
lock.release();
retry(
_methodId,
_retry,
_timeout,
_circuitBreakerTimeout,
_userOperation,
errorHandler,
onFailureRespond,
errorMethodHandler,
vxmsShared,
resultConsumer,
event);
}
}
示例9: executeInitialState
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static <T, V> void executeInitialState(
int _retry,
long _timeout,
ThrowableFutureBiConsumer<T, V> step,
T inputValue,
VxmsShared vxmsShared,
Future<V> operationResult,
Lock lock,
Counter counter) {
final long initialRetryCounterValue = (long) (_retry + 1);
counter.addAndGet(
initialRetryCounterValue,
rHandler ->
executeDefaultState(_timeout, step, inputValue, vxmsShared, operationResult, lock));
}
示例10: handleStatefulError
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
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, 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);
}
}
示例11: executeInitialState
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static <T> void executeInitialState(
String _methodId,
ThrowableSupplier<T> _supplier,
Future<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));
}
示例12: setCircuitBreakerReleaseTimer
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static void setCircuitBreakerReleaseTimer(
VxmsShared vxmsShared, int _retry, long _circuitBreakerTimeout, Counter counter) {
final long initialRetryCounterValue = (long) (_retry + 1);
final Vertx vertx = vxmsShared.getVertx();
vertx.setTimer(
_circuitBreakerTimeout, timer -> counter.addAndGet(initialRetryCounterValue, val -> {}));
}
示例13: executeInitialState
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static <T, V> void executeInitialState(
String _methodId,
ThrowableFunction<T, V> step,
T value,
Future<ExecutionResult<V>> _resultHandler,
Consumer<Throwable> _errorHandler,
ThrowableFunction<Throwable, V> _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,
step,
value,
_resultHandler,
_errorHandler,
_onFailureRespond,
_errorMethodHandler,
vxmsShared,
_t,
_retry,
_timeout,
_circuitBreakerTimeout,
_delay,
lock));
}
示例14: openCircuitAndHandleError
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
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);
});
}
示例15: resetLockTimer
import io.vertx.core.shareddata.Counter; //导入依赖的package包/类
private static void resetLockTimer(
VxmsShared vxmsShared, int retryCount, long circuitBreakerTimeout, Counter counter) {
final Vertx vertx = vxmsShared.getVertx();
vertx.setTimer(
circuitBreakerTimeout,
timer -> counter.addAndGet(Integer.valueOf(retryCount + 1).longValue(), val -> {}));
}