3435363738394041
} public static Timeout newKeepAliveTimeout(final SelectableChannel clientChannel, long keepAliveTimeout) { return new Timeout( System.currentTimeMillis() + keepAliveTimeout, new AsyncCallback() { public void onCallback() { Closeables.closeQuietly(clientChannel); } } ); }
252627282930313233
*/ public void start() { IOLoop.INSTANCE.addTimeout( new Timeout( System.currentTimeMillis() + period, new AsyncCallback() { @Override public void onCallback() { run(); }} ) ); }
102103104105106107108109110
private void startTimeout() { logger.debug("start timeout..."); timeout = new Timeout( System.currentTimeMillis() + TIMEOUT, new AsyncCallback() { public void onCallback() { onTimeout(); } } ); IOLoop.INSTANCE.addTimeout(timeout); }
127128129130131132133134
logger.debug("Connected..."); cancelTimeout(); startTimeout(); socket.write( makeRequestLineAndHeaders(), new AsyncCallback() { public void onCallback() { onWriteComplete(); }} ); }
204205206207208209210211212
readCallback = nopAsyncStringResult; cb.onFailure(e); } private void invokeWriteCallback() { AsyncCallback cb = writeCallback; writeCallback = AsyncCallback.nopCb; cb.onCallback(); }
210211212213214215216217218
writeCallback = AsyncCallback.nopCb; cb.onCallback(); } private void invokeCloseCallback() { AsyncCallback cb = closeCallback; closeCallback = AsyncCallback.nopCb; cb.onCallback(); }
6667686970717273747576
latch.await(5, TimeUnit.SECONDS); } @After public void tearDown() throws InterruptedException { IOLoop.INSTANCE.addCallback(new AsyncCallback() { @Override public void onCallback() { IOLoop.INSTANCE.stop(); } }); Thread.sleep(300); // give the IOLoop thread some time to gracefully shutdown }
107108109110111112113114
// TODO stop ioloop } private void onConnect() { latch.countDown(); AsyncCallback wcb = new AsyncCallback() { @Override public void onCallback() { onWriteComplete(); }}; socket.write("roger|\r\n", wcb); }
515253545556575859
assertEquals(0, tm.getNumberOfTimeouts()); assertEquals(0, tm.getNumberOfKeepAliveTimeouts()); } private void addNopTimeout(long timeout) { tm.addTimeout(new Timeout(timeout, new AsyncCallback() { @Override public void onCallback() { /*nop*/} })); }
575859606162636465
@Override public void onCallback() { /*nop*/} })); } private void addNopKeepAliveTimeout(SelectableChannel channel, long timeout) { tm.addKeepAliveTimeout(channel, new Timeout(timeout, new AsyncCallback() { @Override public void onCallback() { /*nop*/ } })); }