public static <T> Completion<T> future(Future<T> future) { return future(future, null); }
@Test public void testFutureComplete() { final AtomicInteger count = new AtomicInteger(); Completion<String> completion = Completion.future(new Callable<String>() { public String call() throws Exception { count.incrementAndGet(); return "foo"; } }); assertEquals(0, count.get()); assertEquals("foo", completion.get()); assertEquals(1, count.get()); assertEquals("foo", completion.get()); assertEquals(1, count.get()); assertEquals(null, completion.getCause()); assertEquals(1, count.get()); assertEquals(false, completion.isFailed()); assertEquals(1, count.get()); }
public MockApplication<P> init() throws Exception { if (lifeCycle == null) { assertCompile(); } if (lifeCycle != null) { Completion refresh = lifeCycle.refresh(); if (refresh.isFailed()) { throw refresh.getCause(); } else { return this; } } else { throw new IllegalStateException("Could not compile application"); } }
public Completion<Boolean> refresh(boolean recompile) { Completion<Boolean> refresh = module.runtime.refresh(recompile); if (refresh.isFailed()) { return refresh; } else { while (application.get() == null) { application.compareAndSet(null, new ApplicationRuntime( log, module.getRunMode(), module.runtime, injector, config.name, server, resolver)); } return application.get().refresh(); } }
@Override public Completion<Boolean> refresh(boolean recompile) { return Completion.completed(false); }
@Test public void testFutureComplete() { final AtomicInteger count = new AtomicInteger(); Completion<String> completion = Completion.future(new Callable<String>() { public String call() throws Exception { count.incrementAndGet(); return "foo"; } }); assertEquals(0, count.get()); assertEquals("foo", completion.get()); assertEquals(1, count.get()); assertEquals("foo", completion.get()); assertEquals(1, count.get()); assertEquals(null, completion.getCause()); assertEquals(1, count.get()); assertEquals(false, completion.isFailed()); assertEquals(1, count.get()); }
public MockApplication<P> init() throws Exception { if (lifeCycle == null) { assertCompile(); } if (lifeCycle != null) { Completion refresh = lifeCycle.refresh(); if (refresh.isFailed()) { throw refresh.getCause(); } else { return this; } } else { throw new IllegalStateException("Could not compile application"); } }
public Completion<Boolean> refresh(boolean recompile) { Completion<Boolean> refresh = module.runtime.refresh(recompile); if (refresh.isFailed()) { return refresh; } else { while (application.get() == null) { application.compareAndSet(null, new ApplicationRuntime( log, module.getRunMode(), module.runtime, injector, config.name, server, resolver)); } return application.get().refresh(); } }
@Override public Completion<Boolean> refresh(boolean recompile) { return Completion.completed(false); }
@Test public void testFutureFails() { final Exception reason = new Exception(); final AtomicInteger count = new AtomicInteger(); Completion<String> completion = Completion.future(new Callable<String>() { public String call() throws Exception { count.incrementAndGet(); throw reason; } }); assertEquals(0, count.get()); assertEquals(null, completion.get()); assertEquals(1, count.get()); assertEquals(null, completion.get()); assertEquals(1, count.get()); assertEquals(reason, completion.getCause()); assertEquals(1, count.get()); assertEquals(true, completion.isFailed()); assertEquals(1, count.get()); } }
public static <T> Completion<T> future(Future<T> future) { return future(future, null); }
@Test public void testFutureFails() { final Exception reason = new Exception(); final AtomicInteger count = new AtomicInteger(); Completion<String> completion = Completion.future(new Callable<String>() { public String call() throws Exception { count.incrementAndGet(); throw reason; } }); assertEquals(0, count.get()); assertEquals(null, completion.get()); assertEquals(1, count.get()); assertEquals(null, completion.get()); assertEquals(1, count.get()); assertEquals(reason, completion.getCause()); assertEquals(1, count.get()); assertEquals(true, completion.isFailed()); assertEquals(1, count.get()); } }
public synchronized Completion<Boolean> refresh() { if (application != null) { if (classLoader != moduleLifeCycle.getClassLoader()) { stop(); } } // if (application == null) { try { start(); return Completion.completed(true); } catch (Exception e) { return Completion.failed(e); } } else { return Completion.completed(false); } }
public static <T> Completion<T> future(Callable<T> callable) { FutureTask<T> task = new FutureTask<T>(callable); return future(task, task); }
public synchronized Completion<Boolean> refresh() { if (application != null) { if (classLoader != moduleLifeCycle.getClassLoader()) { stop(); } } // if (application == null) { try { start(); return Completion.completed(true); } catch (Exception e) { return Completion.failed(e); } } else { return Completion.completed(false); } }
public static <T> Completion<T> future(Callable<T> callable) { FutureTask<T> task = new FutureTask<T>(callable); return future(task, task); }