@Test() public void testReady() throws InterruptedException { ShoppingCart<Integer,String,String> c = new ShoppingCart<>(1,"v1","l",100,TimeUnit.MILLISECONDS); BuildingSite<Integer, String, Cart<Integer,?,String>, User> bs = new BuildingSite<> ( c, () -> { return new UserBuilder();}, (label,value,builder)-> { }, (state,builder)->{return true;}, null, 100, TimeUnit.MILLISECONDS,false,false,false,0,false,null,null,(a)->{}); assertEquals(0, bs.getAcceptCount()); assertEquals(Status.WAITING_DATA, bs.getStatus()); bs.accept(new ShoppingCart<>(1,"XXX","l",100,TimeUnit.MILLISECONDS)); assertNotNull(bs.getLastCart()); User u = bs.build(); assertNotNull(u); assertEquals(1, bs.getAcceptCount()); Thread.sleep(110); assertEquals(Status.READY, bs.getStatus()); assertEquals(0, bs.getAcceptedCarts().size()); assertFalse(bs.getAcknowledge().isAcknowledged()); bs.getAcknowledge().ack(); assertNotNull(bs.getBuilder()); assertNotNull(bs.getLock()); assertNotNull(bs.getCreatingCart()); }
public boolean ready() { boolean res = false; State<K,L> state = getState(); lock.lock(); try { res = readiness.test(state, builder); } finally { lock.unlock(); } if( res ) { status = Status.READY; } return res; }
BuildingSite implements Expireable, Interruptable { public boolean ready() { boolean res = false; State<K,L> state = getState(); lock.lock(); try { res = readiness.test(state, builder); } finally { lock.unlock(); } if( res ) { status = Status.READY; } return res; } }
BuildingSite implements Expireable, Interruptable { public boolean ready() { boolean res = false; State<K,L> state = getState(); lock.lock(); try { res = readiness.test(state, builder); } finally { lock.unlock(); } if( res ) { status = Status.READY; } return res; } @SuppressWarnings("unchecked")  BuildingSite( 
			C cart, 
			Supplier<Supplier<? extends OUT>> builderSupplier, 
			LabeledValueConsumer<L, ?, Supplier<? extends OUT>> cartConsumer, 
			BiPredicate<State<K,L>, Supplier<? extends OUT>> readiness, 
			Consumer<Supplier<? extends OUT>> timeoutAction,
			long ttl,
			TimeUnit unit,
			boolean synchronizeBuilder, 
			boolean saveCarts, 
			boolean postponeExpirationEnabled, 
			long addExpirationTimeMsec, 
			boolean postponeExpirationOnTimeoutEnabled,
			Map<L,C> staticValues,
			ResultConsumer<K,OUT> resultConsumer,
			Consumer<AcknowledgeStatus<K>> ackAction
			); }
BuildingSite implements Expireable, Interruptable { public boolean ready() { boolean res = false; State<K,L> state = getState(); lock.lock(); try { res = readiness.test(state, builder); } finally { lock.unlock(); } if( res ) { status = Status.READY; } return res; } @SuppressWarnings("unchecked")  BuildingSite( 
			C cart, 
			Supplier<Supplier<? extends OUT>> builderSupplier, 
			LabeledValueConsumer<L, ?, Supplier<? extends OUT>> cartConsumer, 
			BiPredicate<State<K,L>, Supplier<? extends OUT>> readiness, 
			Consumer<Supplier<? extends OUT>> timeoutAction,
			long ttl,
			TimeUnit unit,
			boolean synchronizeBuilder, 
			boolean saveCarts, 
			boolean postponeExpirationEnabled, 
			long addExpirationTimeMsec, 
			boolean postponeExpirationOnTimeoutEnabled,
			Map<L,C> staticValues,
			ResultConsumer<K,OUT> resultConsumer,
			Consumer<AcknowledgeStatus<K>> ackAction
			); void accept(C cart); void timeout(C cart); OUT build(); OUT unsafeBuild(); Supplier<? extends OUT> getProductSupplier(); State<K,L> getState(); boolean ready(); int getAcceptCount(); long getDelayMsec(); @Override long getExpirationTime(); C getCreatingCart(); List<C> getAcceptedCarts(); K getKey(); Throwable getLastError(); void setLastError(Throwable lastError); @Override String toString(); Status getStatus(); void setStatus(Status status); C getLastCart(); void setLastCart(C lastCart); void addFuture(final CompletableFuture<OUT> resultFuture); Supplier<? extends OUT> getBuilder(); Lock getLock(); Consumer<Supplier<? extends OUT>> getTimeoutAction(); Map<String,Object> getProperties(); void addProperties(Map<String,Object> properties); Acknowledge getAcknowledge(); Memento getMemento(); void restore(Memento memento); @Override void interrupt(Thread conveyorThread); }
BuildingSite implements Expireable, Interruptable { public boolean ready() { boolean res = false; State<K,L> state = getState(); lock.lock(); try { res = readiness.test(state, builder); } finally { lock.unlock(); } if( res ) { status = Status.READY; } return res; } @SuppressWarnings("unchecked")  BuildingSite( 
			C cart, 
			Supplier<Supplier<? extends OUT>> builderSupplier, 
			LabeledValueConsumer<L, ?, Supplier<? extends OUT>> cartConsumer, 
			BiPredicate<State<K,L>, Supplier<? extends OUT>> readiness, 
			Consumer<Supplier<? extends OUT>> timeoutAction,
			long ttl,
			TimeUnit unit,
			boolean synchronizeBuilder, 
			boolean saveCarts, 
			boolean postponeExpirationEnabled, 
			long addExpirationTimeMsec, 
			boolean postponeExpirationOnTimeoutEnabled,
			Map<L,C> staticValues,
			ResultConsumer<K,OUT> resultConsumer,
			Consumer<AcknowledgeStatus<K>> ackAction
			); void accept(C cart); void timeout(C cart); OUT build(); OUT unsafeBuild(); Supplier<? extends OUT> getProductSupplier(); State<K,L> getState(); boolean ready(); int getAcceptCount(); long getDelayMsec(); @Override long getExpirationTime(); C getCreatingCart(); List<C> getAcceptedCarts(); K getKey(); Throwable getLastError(); void setLastError(Throwable lastError); @Override String toString(); Status getStatus(); void setStatus(Status status); C getLastCart(); void setLastCart(C lastCart); void addFuture(final CompletableFuture<OUT> resultFuture); Supplier<? extends OUT> getBuilder(); Lock getLock(); Consumer<Supplier<? extends OUT>> getTimeoutAction(); Map<String,Object> getProperties(); void addProperties(Map<String,Object> properties); Acknowledge getAcknowledge(); Memento getMemento(); void restore(Memento memento); @Override void interrupt(Thread conveyorThread); final static Lock NON_LOCKING_LOCK; }