@Test public void mementoTest() { CompletableFuture<Boolean> canceled = new CompletableFuture<>(); canceled.cancel(true); MultiKeyCommandLoader cl1 = new MultiKeyCommandLoader(cmd->canceled); CompletableFuture memento1 = cl1.memento(); try { memento1.get(1, TimeUnit.MILLISECONDS); } catch (Exception e) { } CompletableFuture<Boolean> exceptional = new CompletableFuture<>(); canceled.completeExceptionally(new Exception("test")); MultiKeyCommandLoader cl2 = new MultiKeyCommandLoader(cmd->exceptional); CompletableFuture memento2 = cl2.memento(); try { memento2.get(1, TimeUnit.MILLISECONDS); } catch (Exception e) { } CompletableFuture<Boolean> falseRes = new CompletableFuture<>(); falseRes.complete(false); MultiKeyCommandLoader cl3 = new MultiKeyCommandLoader(cmd->falseRes); CompletableFuture memento3 = cl3.memento(); try { memento3.get(1, TimeUnit.MILLISECONDS); } catch (Exception e) { } }
public CompletableFuture<List<Memento>> memento() { CompletableFuture<List<Memento>> f = new CompletableFuture<>(); List<Memento> list = new LinkedList<>(); GeneralCommand<K, Consumer<Memento>> command = new GeneralCommand<>(filter,list::add,CommandLabel.MEMENTO_BUILD,creationTime,expirationTime); CompletableFuture<Boolean> cf = conveyor.apply(command); if(cf.isCancelled()) { f.cancel(true); } if(cf.isCompletedExceptionally()) { try { cf.get(); } catch (Exception e) { f.completeExceptionally(e); } } return cf.thenCompose( res->{ if(res) { f.complete(list); } else { f.cancel(true); } return f; }); }
MultiKeyCommandLoader { public CompletableFuture<List<Memento>> memento() { CompletableFuture<List<Memento>> f = new CompletableFuture<>(); List<Memento> list = new LinkedList<>(); GeneralCommand<K, Consumer<Memento>> command = new GeneralCommand<>(filter,list::add,CommandLabel.MEMENTO_BUILD,creationTime,expirationTime); CompletableFuture<Boolean> cf = conveyor.apply(command); if(cf.isCancelled()) { f.cancel(true); } if(cf.isCompletedExceptionally()) { try { cf.get(); } catch (Exception e) { f.completeExceptionally(e); } } return cf.thenCompose( res->{ if(res) { f.complete(list); } else { f.cancel(true); } return f; }); } }
MultiKeyCommandLoader { public CompletableFuture<List<Memento>> memento() { CompletableFuture<List<Memento>> f = new CompletableFuture<>(); List<Memento> list = new LinkedList<>(); GeneralCommand<K, Consumer<Memento>> command = new GeneralCommand<>(filter,list::add,CommandLabel.MEMENTO_BUILD,creationTime,expirationTime); CompletableFuture<Boolean> cf = conveyor.apply(command); if(cf.isCancelled()) { f.cancel(true); } if(cf.isCompletedExceptionally()) { try { cf.get(); } catch (Exception e) { f.completeExceptionally(e); } } return cf.thenCompose( res->{ if(res) { f.complete(list); } else { f.cancel(true); } return f; }); } MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor,long creationTime, long expirationTime, long ttlMsec, Predicate<K> filter); private  MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor,long creationTime, long ttl, Predicate<K> filter, boolean dumb);  MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor); }
MultiKeyCommandLoader { public CompletableFuture<List<Memento>> memento() { CompletableFuture<List<Memento>> f = new CompletableFuture<>(); List<Memento> list = new LinkedList<>(); GeneralCommand<K, Consumer<Memento>> command = new GeneralCommand<>(filter,list::add,CommandLabel.MEMENTO_BUILD,creationTime,expirationTime); CompletableFuture<Boolean> cf = conveyor.apply(command); if(cf.isCancelled()) { f.cancel(true); } if(cf.isCompletedExceptionally()) { try { cf.get(); } catch (Exception e) { f.completeExceptionally(e); } } return cf.thenCompose( res->{ if(res) { f.complete(list); } else { f.cancel(true); } return f; }); } MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor,long creationTime, long expirationTime, long ttlMsec, Predicate<K> filter); private  MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor,long creationTime, long ttl, Predicate<K> filter, boolean dumb);  MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor); MultiKeyCommandLoader<K,OUT> foreach(); MultiKeyCommandLoader<K,OUT> foreach(Predicate<K> p); MultiKeyCommandLoader<K,OUT> expirationTime(long et); MultiKeyCommandLoader<K,OUT> creationTime(long ct); MultiKeyCommandLoader<K,OUT> expirationTime(Instant instant); MultiKeyCommandLoader<K,OUT> creationTime(Instant instant); MultiKeyCommandLoader<K,OUT> ttl(long time, TimeUnit unit); MultiKeyCommandLoader<K,OUT> ttl(Duration duration); CompletableFuture<Boolean> cancel(); CompletableFuture<Boolean> timeout(); CompletableFuture<Boolean> reschedule(); CompletableFuture<List<ProductBin<K,OUT>>> peek(); CompletableFuture<Boolean> peek(Consumer<ProductBin<K,OUT>> consumer); CompletableFuture<List<Memento>> memento(); CompletableFuture<Boolean> memento(Consumer<Memento> memento); @Override String toString(); }
MultiKeyCommandLoader { public CompletableFuture<List<Memento>> memento() { CompletableFuture<List<Memento>> f = new CompletableFuture<>(); List<Memento> list = new LinkedList<>(); GeneralCommand<K, Consumer<Memento>> command = new GeneralCommand<>(filter,list::add,CommandLabel.MEMENTO_BUILD,creationTime,expirationTime); CompletableFuture<Boolean> cf = conveyor.apply(command); if(cf.isCancelled()) { f.cancel(true); } if(cf.isCompletedExceptionally()) { try { cf.get(); } catch (Exception e) { f.completeExceptionally(e); } } return cf.thenCompose( res->{ if(res) { f.complete(list); } else { f.cancel(true); } return f; }); } MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor,long creationTime, long expirationTime, long ttlMsec, Predicate<K> filter); private  MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor,long creationTime, long ttl, Predicate<K> filter, boolean dumb);  MultiKeyCommandLoader(Function<GeneralCommand<K,?>, CompletableFuture<Boolean>> conveyor); MultiKeyCommandLoader<K,OUT> foreach(); MultiKeyCommandLoader<K,OUT> foreach(Predicate<K> p); MultiKeyCommandLoader<K,OUT> expirationTime(long et); MultiKeyCommandLoader<K,OUT> creationTime(long ct); MultiKeyCommandLoader<K,OUT> expirationTime(Instant instant); MultiKeyCommandLoader<K,OUT> creationTime(Instant instant); MultiKeyCommandLoader<K,OUT> ttl(long time, TimeUnit unit); MultiKeyCommandLoader<K,OUT> ttl(Duration duration); CompletableFuture<Boolean> cancel(); CompletableFuture<Boolean> timeout(); CompletableFuture<Boolean> reschedule(); CompletableFuture<List<ProductBin<K,OUT>>> peek(); CompletableFuture<Boolean> peek(Consumer<ProductBin<K,OUT>> consumer); CompletableFuture<List<Memento>> memento(); CompletableFuture<Boolean> memento(Consumer<Memento> memento); @Override String toString(); final long creationTime; final long expirationTime; final long ttlMsec; final Predicate<K> filter; }