/** * {@inheritDoc} */ @Override public void onRegistered(SelectionKey selectionKey) { future.set(selectionKey); }
@Override public void onRegistered(SelectionKey selectionKey) { this.selectionKey = selectionKey; SocketAddress localAddress; try { localAddress = serverSocketChannel.getLocalAddress(); addr.set(localAddress); } catch (IOException e) { addr.setException(e); return; } try { System.out.println("Accepting connections on port " + localAddress); } catch (Exception e) { // ignore } registered.set(null); }
throw e; futureChannel.set(channel); capabilityContent = null; capabilityLength = null;
@Test public void setValue() throws Exception { assertTrue(future.set("value")); assertCompletedFuture("value"); }
@Test public void setValue_simpleThreaded() throws Exception { SettableFuture<Integer> future = SettableFuture.create(); assertTrue(future.set(42)); // Later attempts to set the future should return false. assertFalse(future.set(23)); assertFalse(future.setException(new Exception("bar"))); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); assertEquals(42, (int) future.get()); }
@Test public void cancel_beforeSet() throws Exception { SettableFuture<Object> async = SettableFuture.create(); async.cancel(true); assertFalse(async.set(42)); }
@Test public void setException() throws Exception { SettableFuture<Object> future = SettableFuture.create(); Exception e = new Exception("foobarbaz"); assertTrue(future.setException(e)); // Later attempts to set the future should return false. assertFalse(future.set(23)); assertFalse(future.setException(new Exception("quux"))); // Check that the future has been set properly. assertTrue(future.isDone()); assertFalse(future.isCancelled()); try { future.get(); fail("Expected ExecutionException"); } catch (ExecutionException ee) { assertSame(e, ee.getCause()); } }