final List<ErrorRecord> errors = new ArrayList<>(); final AsyncEvent<Void> consensusFound = new AsyncEvent<>(); final int checkConsensus = getNodes().size() / 3; if (itemResults.size() >= checkConsensus) if (itemResults.size() >= checkConsensus) { consensusFound.fire(); return; consensusFound.fire(); }); consensusFound.await(10000);
@Test public void fire() throws Exception { for(int n=0; n<500; n++) { AsyncEvent<Integer> event = new AsyncEvent<>(); int values[] = new int[] { 0, 0}; CountDownLatch latch = new CountDownLatch(2); event.addConsumer(i -> { values[0] = i; latch.countDown(); }); event.addConsumer(i -> { values[1] = i; latch.countDown(); }); event.fire(11); int res = event.waitFired(); assertEquals(11, res); latch.await(); assertEquals(11, values[0]); assertEquals(11, values[1]); } }
Timer timer = new Timer(); AsyncEvent<Void> ae = new AsyncEvent<>(); ae.await(5000); } catch (TimeoutException e) { System.out.println("time is up");
public void closeByTimeout() { resyncingState = ResyncingItemProcessingState.COMMIT_FAILED; finishEvent.fire(this); }
/** * For unit-tests. Blocks until the node is initialized. * * @throws InterruptedException for unexpected interrupt */ public void waitReady() throws InterruptedException { eventReady.await(); }
paymentProcessor.doneEvent.await(); payloadProcessor.doneEvent.await(); } else { payloadProcessor.doneEvent.await(); if(payloadProcessor != null) { payloadProcessor.emergencyBreak(); payloadProcessor.doneEvent.await(); DatagramAdapter.VerboseLevel.BASE); doneEvent.fire(); paymentProcessor.removedEvent.await(); payloadProcessor.removedEvent.await(); doneEvent.fire(); } catch (Exception e) { e.printStackTrace(); processingState = ParcelProcessingState.FINISHED; doneEvent.fire();
AsyncEvent done = new AsyncEvent(); a.asyncCommands(); a.start(command -> { b.send("wait").done((data) -> { waitDone[0] = true; done.fire(null); }); b.send("interrupt").waitSuccess(); done.waitFired(); assertTrue(waitDone[0]);
AsyncEvent ae = new AsyncEvent();
public ResyncProcessor(HashId itemId, Consumer<ResyncingItem> onComplete) { this.itemId = itemId; if (onComplete != null) finishEvent.addConsumer(onComplete); }
AsyncEvent ae = new AsyncEvent(); ae.await(5000); } catch (TimeoutException e) { timer.cancel(); ae.await(5000); } catch (TimeoutException e) { System.out.println("time is up");
public final void fire() { fire(null); } }
/** * Wait until the event is fired. If it is already fired, returns immediately the result passed to the {@link * #fire(Object)} call. Same as {@link #await()} * * @return the result passed to the {@link #fire(Object)} * * @throws InterruptedException */ @Deprecated public T waitFired() throws InterruptedException { return await(); }
AsyncEvent ae = new AsyncEvent();
public void startResync() { report(getLabel(), ()->"ResyncProcessor.startResync(itemId="+itemId+")", DatagramAdapter.VerboseLevel.BASE); resyncExpiresAt = Instant.now().plus(config.getMaxResyncTime()); executorService.schedule(()->resyncEnded(), config.getMaxResyncTime().getSeconds(), TimeUnit.SECONDS); resyncingItem = new ResyncingItem(itemId, ledger.getRecord(itemId)); resyncingItem.finishEvent.addConsumer((ri)->onFinishResync(ri)); List<Integer> periodsMillis = config.getResyncTime(); obtainedAnswersFromNodes.clear(); voteItself(); resyncer = new RunnableWithDynamicPeriod(() -> pulseResync(), periodsMillis, executorService); resyncer.run(); }
Timer timer = new Timer(); AsyncEvent<Void> ae = new AsyncEvent<>(); ae.await(5000); } catch (TimeoutException e) { System.out.println("time is up");
AtomicInteger sentCounter = new AtomicInteger(0); AtomicInteger doneCounter = new AtomicInteger(0); AsyncEvent eventReady = new AsyncEvent(); AtomicInteger peakFps = new AtomicInteger(0); if(done == BUNCHES_PER_NODE*PACKS_IN_BUNCH*NODES_COUNT) { end.set(System.currentTimeMillis()); eventReady.fire(); eventReady.await();
/** * Wait until the event is fired. If it is already fired, returns immediately the result passed to the {@link * #fire(Object)} call. * * @return the result passed to the {@link #fire(Object)} * * @throws InterruptedException */ public T await() throws InterruptedException { try { return await(0); } catch (TimeoutException e) { throw new RuntimeException("impossible: timeout can't be expired with 0 wait time"); } }
AsyncEvent ae = new AsyncEvent();
((ItemProcessor)x).doneEvent.addConsumer(i -> executorService.schedule( () -> itemSanitationDone(record),0,TimeUnit.SECONDS)); } else { throw new IllegalStateException("should never happen because ommitItemResult is true");