当前位置: 首页>>代码示例>>Java>>正文


Java ThrowableConsumer类代码示例

本文整理汇总了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;
        }
    }
}
 
开发者ID:PhantomThief,项目名称:simple-failover-java,代码行数:27,代码来源:SharedResource.java

示例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);
}
 
开发者ID:PhantomThief,项目名称:buffer-trigger,代码行数:20,代码来源:SimpleBufferTrigger.java

示例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);
            }
        }
    };
}
 
开发者ID:PhantomThief,项目名称:zkconfig-resources,代码行数:20,代码来源:ZkBasedNodeResource.java

示例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());
}
 
开发者ID:PhantomThief,项目名称:simple-failover-java,代码行数:8,代码来源:FailoverUtils.java

示例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);
}
 
开发者ID:PhantomThief,项目名称:simple-failover-java,代码行数:8,代码来源:FailoverUtils.java

示例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;
    });
}
 
开发者ID:PhantomThief,项目名称:simple-failover-java,代码行数:8,代码来源:LatencyAware.java

示例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);
}
 
开发者ID:PhantomThief,项目名称:buffer-trigger,代码行数:14,代码来源:BatchConsumeBlockingQueueTrigger.java

示例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);
    });
}
 
开发者ID:PhantomThief,项目名称:buffer-trigger,代码行数:11,代码来源:SimpleBufferTriggerBuilder.java

示例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;
}
 
开发者ID:PhantomThief,项目名称:zkconfig-resources,代码行数:16,代码来源:ZkBasedNodeResource.java

示例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);
}
 
开发者ID:PhantomThief,项目名称:simple-failover-java,代码行数:7,代码来源:Failover.java

示例11: setConsumerEx

import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
public GenericBatchConsumerTriggerBuilder<E>
        setConsumerEx(ThrowableConsumer<? super List<E>, Exception> consumer) {
    builder.setConsumerEx(consumer);
    return this;
}
 
开发者ID:PhantomThief,项目名称:buffer-trigger,代码行数:6,代码来源:GenericBatchConsumerTriggerBuilder.java

示例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;
}
 
开发者ID:PhantomThief,项目名称:buffer-trigger,代码行数:7,代码来源:BatchConsumerTriggerBuilder.java

示例13: addFactoryFailedListener

import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
@CheckReturnValue
public GenericZkBasedNodeBuilder<T>
        addFactoryFailedListener(@Nonnull ThrowableConsumer<Throwable, Throwable> listener) {
    builder.addFactoryFailedListener(listener);
    return this;
}
 
开发者ID:PhantomThief,项目名称:zkconfig-resources,代码行数:7,代码来源:GenericZkBasedNodeBuilder.java

示例14: withCleanupConsumer

import com.github.phantomthief.util.ThrowableConsumer; //导入依赖的package包/类
@CheckReturnValue
public GenericZkBasedNodeBuilder<T>
        withCleanupConsumer(ThrowableConsumer<? super T, Throwable> cleanup) {
    builder.withCleanupConsumer(cleanup);
    return this;
}
 
开发者ID:PhantomThief,项目名称:zkconfig-resources,代码行数:7,代码来源:GenericZkBasedNodeBuilder.java

示例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;
}
 
开发者ID:PhantomThief,项目名称:zkconfig-resources,代码行数:7,代码来源:ZkBasedNodeResource.java


注:本文中的com.github.phantomthief.util.ThrowableConsumer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。