本文整理汇总了Java中com.github.phantomthief.util.ThrowableConsumer类的典型用法代码示例。如果您正苦于以下问题:Java ThrowableConsumer类的具体用法?Java ThrowableConsumer怎么用?Java ThrowableConsumer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThrowableConsumer类属于com.github.phantomthief.util包,在下文中一共展示了ThrowableConsumer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unregister
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public V unregister(K key, ThrowableConsumer<V, Throwable> cleanup) {
synchronized (lock) {
AtomicInteger counter = counters.get(key);
if (counter == null) {
throw new IllegalStateException("non paired unregister call for key:" + key);
}
int count = counter.decrementAndGet();
if (count < 0) { // impossible run into here
throw new IllegalStateException("INVALID INTERNAL STATE:" + key);
} else if (count > 0) { // wait others to unregister
return resources.get(key);
} else { // count == 0
V removed = resources.remove(key);
counters.remove(key);
try {
cleanup.accept(removed);
logger.info("cleanup resource:{}->{}", key, removed);
} catch (Throwable e) {
throwIfUnchecked(e);
throw new RuntimeException(e);
}
return removed;
}
}
}
示例2: SimpleBufferTrigger
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
SimpleBufferTrigger(Supplier<Object> bufferFactory, ToIntBiFunction<Object, E> queueAdder,
ScheduledExecutorService scheduledExecutorService,
ThrowableConsumer<Object, Throwable> consumer,
TriggerStrategy triggerStrategy, BiConsumer<Throwable, Object> exceptionHandler,
long maxBufferCount, Consumer<E> rejectHandler) {
this.queueAdder = queueAdder;
this.bufferFactory = bufferFactory;
this.consumer = consumer;
this.exceptionHandler = exceptionHandler;
this.maxBufferCount = maxBufferCount;
this.rejectHandler = rejectHandler;
this.buffer.set(this.bufferFactory.get());
ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
readLock = lock.readLock();
writeLock = lock.writeLock();
scheduledExecutorService.schedule(
new TriggerRunnable(scheduledExecutorService, triggerStrategy),
DEFAULT_NEXT_TRIGGER_PERIOD, MILLISECONDS);
}
示例3: ZkBasedNodeResource
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
private ZkBasedNodeResource(Builder<T> builder) {
this.factory = builder.factory;
this.refreshFactory = builder.refreshFactory;
this.cleanup = builder.cleanup;
this.waitStopPeriod = builder.waitStopPeriod;
this.emptyObject = builder.emptyObject;
this.onResourceChange = builder.onResourceChange;
this.nodeCacheShutdown = builder.nodeCacheShutdown;
this.nodeCache = lazy(builder.cacheFactory);
this.factoryFailedListener = t -> {
for (ThrowableConsumer<Throwable, ?> failedListener : builder.factoryFailedListeners) {
try {
failedListener.accept(t);
} catch (Throwable e) {
logger.error("", e);
}
}
};
}
示例4: runWithRetry
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public static <T, X extends Throwable> void runWithRetry(int maxRetryTimes,
long sleepBetweenRetryMs, Failover<T> failover, ThrowableConsumer<T, X> func) throws X {
supplyWithRetry(maxRetryTimes, sleepBetweenRetryMs, failover, t -> {
func.accept(t);
return null;
}, alwaysTrue());
}
示例5: run
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public static <T, X extends Throwable> void run(Failover<T> failover,
ThrowableConsumer<T, X> func, Predicate<Throwable> failChecker) throws X {
supply(failover, t -> {
func.accept(t);
return null;
}, failChecker);
}
示例6: run
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public <X extends Throwable> void run(Collection<T> candidates,
ThrowableConsumer<T, X> function) throws X {
supply(candidates, t -> {
function.accept(t);
return null;
});
}
示例7: BatchConsumeBlockingQueueTrigger
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
BatchConsumeBlockingQueueTrigger(long lingerMs, int batchSize, int bufferSize,
BiConsumer<Throwable, List<E>> exceptionHandler,
ThrowableConsumer<List<E>, Exception> consumer,
ScheduledExecutorService scheduledExecutorService) {
this.lingerMs = lingerMs;
this.batchSize = batchSize;
this.queue = new LinkedBlockingQueue<>(max(bufferSize, batchSize));
this.consumer = consumer;
this.exceptionHandler = exceptionHandler;
this.scheduledExecutorService = scheduledExecutorService;
this.scheduledExecutorService.schedule(new BatchConsumerRunnable(), this.lingerMs,
MILLISECONDS);
}
示例8: build
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public <E1> BufferTrigger<E1> build() {
return new LazyBufferTrigger<>(() -> {
ensure();
return new SimpleBufferTrigger<>((Supplier<Object>) bufferFactory,
(ToIntBiFunction<Object, E1>) queueAdder, scheduledExecutorService,
(ThrowableConsumer<Object, Throwable>) consumer, triggerStrategy,
(BiConsumer<Throwable, Object>) exceptionHandler, maxBufferCount,
(Consumer<E1>) rejectHandler);
});
}
示例9: withCleanupConsumer
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
@CheckReturnValue
public <E1> Builder<E1>
withCleanupConsumer(ThrowableConsumer<? super E1, Throwable> cleanup) {
Builder<E1> thisBuilder = (Builder<E1>) this;
thisBuilder.cleanup = t -> {
try {
cleanup.accept(t);
return true;
} catch (Throwable e) {
logger.error("Ops. fail to close, path:{}", t, e);
return false;
}
};
return thisBuilder;
}
示例10: runWithRetry
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
/**
* @see FailoverUtils#runWithRetry
*/
default <X extends Throwable> void runWithRetry(ThrowableConsumer<T, X> func) throws X {
FailoverUtils.runWithRetry(getAll().size(), 0, this, func);
}
示例11: setConsumerEx
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public GenericBatchConsumerTriggerBuilder<E>
setConsumerEx(ThrowableConsumer<? super List<E>, Exception> consumer) {
builder.setConsumerEx(consumer);
return this;
}
示例12: setConsumerEx
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public <E1> BatchConsumerTriggerBuilder<E1>
setConsumerEx(ThrowableConsumer<? super List<E1>, Exception> consumer) {
BatchConsumerTriggerBuilder<E1> thisBuilder = (BatchConsumerTriggerBuilder<E1>) this;
thisBuilder.consumer = consumer::accept;
return thisBuilder;
}
示例13: addFactoryFailedListener
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
@CheckReturnValue
public GenericZkBasedNodeBuilder<T>
addFactoryFailedListener(@Nonnull ThrowableConsumer<Throwable, Throwable> listener) {
builder.addFactoryFailedListener(listener);
return this;
}
示例14: withCleanupConsumer
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
@CheckReturnValue
public GenericZkBasedNodeBuilder<T>
withCleanupConsumer(ThrowableConsumer<? super T, Throwable> cleanup) {
builder.withCleanupConsumer(cleanup);
return this;
}
示例15: addFactoryFailedListener
import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
@CheckReturnValue
public <E1> Builder<E1> addFactoryFailedListener(
@Nonnull ThrowableConsumer<Throwable, Throwable> listener) {
factoryFailedListeners.add(checkNotNull(listener));
return (Builder<E1>) this;
}