private void markAsDone( WorkUnit<Material,W> batch ) { while ( batch != stackEnd ) { batch.complete(); batch = batch.next; } }
@Override public void await() throws ExecutionException { checkFailure( throwable ); int tryCount = 0; while ( !unit.isDone() ) { tryCount++; checkFailure( throwable = tryDoWork( unit, tryCount, true ) ); } } };
@Override public void release() { latchMap.setLatch( index, null ); super.release(); } }
public void awaitStartup() { startupLatch.await(); }
/** * Construct a new {@code AsyncEvents} instance, that will use the given consumer to process the events. * * @param eventConsumer The {@link Consumer} used for processing the events that are sent in. */ public AsyncEvents( Consumer<T> eventConsumer, Monitor monitor ) { this.eventConsumer = eventConsumer; this.monitor = monitor; this.startupLatch = new BinaryLatch(); this.shutdownLatch = new BinaryLatch(); this.stack = END_SENTINEL; }
@Test void mustApplyWorkAsync() throws Exception { AsyncApply a = sync.applyAsync( new AddWork( 10 ) ); a.await(); assertThat( sum.sum(), is( 10L ) ); AsyncApply b = sync.applyAsync( new AddWork( 20 ) ); AsyncApply c = sync.applyAsync( new AddWork( 30 ) ); b.await(); c.await(); assertThat( sum.sum(), is( 60L ) ); }
@Override public Void call() throws ExecutionException { sync.apply( addWork ); return null; } }
@Override public void apply( Adder adder ) { super.apply( adder ); throw boo; } } );
boolean isDone() { return get() == STATE_DONE; }
public void flag( Key key ) { // We dynamically size this up as needed if ( key.index >= flags.length ) { resize( key.index ); } int flag = flags[key.index]; if ( flag < keepalive ) { flags[key.index] = flag + 1; } }
@Override public void apply( Adder adder ) { usleep( 50 ); adder.add( delta ); } }
public void increment() { add( 1 ); }
public void awaitTermination() { shutdownLatch.await(); }
@Test void mustCombineWorkAsync() throws Exception { makeWorkStuckAtSemaphore( 1 ); AsyncApply a = sync.applyAsync( new AddWork( 1 ) ); AsyncApply b = sync.applyAsync( new AddWork( 1 ) ); AsyncApply c = sync.applyAsync( new AddWork( 1 ) ); semaphore.release( 2 ); a.await(); b.await(); c.await(); assertThat( sum.sum(), is( 4L ) ); assertThat( count.sum(), is( 2L ) ); }
@Override public void apply( Adder adder ) { super.apply( adder ); throw boo; } } );