use of dev.failsafe.spi.Scheduler in project failsafe by jhalterman.
the class VertxExample method main.
/**
* A Vert.x sender and retryable receiver example.
*/
public static void main(String... args) throws Throwable {
// Receiver that fails 2 times then succeeds
AtomicInteger failures = new AtomicInteger();
vertx.eventBus().consumer("ping-address", message -> {
if (failures.getAndIncrement() < 2)
message.fail(1, "Failed");
else {
message.reply("pong!");
}
});
// Retryable sender
Failsafe.with(retryPolicy).with(scheduler).getAsyncExecution(execution -> vertx.eventBus().send("ping-address", "ping!", reply -> {
if (reply.succeeded())
execution.recordResult(reply.result());
else
execution.recordFailure(reply.cause());
}));
Thread.sleep(5000);
System.exit(0);
}
use of dev.failsafe.spi.Scheduler in project failsafe by jhalterman.
the class DelegatingSchedulerTest method shouldClearInterruptFlagInForkJoinPoolThreads.
/**
* Asserts that ForkJoinPool clears interrupt flags.
*/
public void shouldClearInterruptFlagInForkJoinPoolThreads() throws Throwable {
Scheduler scheduler = new DelegatingScheduler(new ForkJoinPool(1));
AtomicReference<Thread> threadRef = new AtomicReference<>();
Waiter waiter = new Waiter();
// Create interruptable execution
scheduler.schedule(() -> {
threadRef.set(Thread.currentThread());
waiter.resume();
Thread.sleep(10000);
return null;
}, 0, TimeUnit.MILLISECONDS);
waiter.await(1000);
threadRef.get().interrupt();
// Check for interrupt flag
scheduler.schedule(() -> {
waiter.assertFalse(Thread.currentThread().isInterrupted());
waiter.resume();
return null;
}, 0, TimeUnit.MILLISECONDS);
waiter.await(1000);
}
Aggregations