@Override public void onWritePossible() throws Exception { future.result(TRUE); }
private static void block(final Connection c, final FutureImpl<Boolean> future) { try { final long writeTimeout = c.getTransport().getWriteTimeout(MILLISECONDS); if (writeTimeout != -1) { future.get(writeTimeout, MILLISECONDS); } else { future.get(); } } catch (ExecutionException e) { c.closeWithReason(Exceptions.makeIOException(e.getCause())); } catch (Exception e) { c.closeWithReason(Exceptions.makeIOException(e)); } }
public void abort(Throwable t) { delegate.failure(t); }
public void attachToSelectorRunner(final SelectorRunner selectorRunner) throws IOException { detachSelectorRunner(); final SelectorHandler selectorHandler = transport.getSelectorHandler(); final FutureImpl<RegisterChannelResult> future = Futures.createSafeFuture(); selectorHandler.registerChannelAsync( selectorRunner, channel, 0, this, Futures.toCompletionHandler(future)); try { final RegisterChannelResult result = future.get(readTimeoutMillis, TimeUnit.MILLISECONDS); this.selectorRunner = selectorRunner; this.selectionKey = result.getSelectionKey(); } catch (InterruptedException | TimeoutException e) { throw new IOException("", e); } catch (ExecutionException e) { throw new IOException("", e.getCause()); } }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { final String msg = ctx.getMessage(); final int count = counter.getAndIncrement(); final String check = pattern + count; if (!check.equals(msg)) { resultFuture.failure(new IllegalStateException( "Client ResultFilter: unexpected echo came: " + msg + ". Expected response: " + check)); return ctx.getStopAction(); } if (count == msgNum - 1) { resultFuture.result(msgNum); } return ctx.getStopAction(); } }
@Override public NextAction handleRead(FilterChainContext ctx) throws IOException { final GIOPMessage message = ctx.getMessage(); resultFuture.result(message); return ctx.getStopAction(); } }
@Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { final String msg = ctx.getMessage(); final String sniHost = sniHostAttr.get(ctx.getConnection()); resultFuture.result(new String[] {msg, sniHost}); return ctx.getInvokeAction(); }
@Override public NextAction handleRead(FilterChainContext ctx) throws IOException { Buffer b = ctx.getMessage(); if (!part1Future.isDone()) { part1Future.result(b.allowBufferDispose()); } else if (!part2Future.isDone()) { part2Future.result(b.isComposite() && b.allowBufferDispose()); } return ctx.getStopAction(b); } }
protected void waitNIOFuture(final FutureImpl<Connection> future, final CompletionHandler<Connection> completionHandler) { try { future.get(connectionTimeoutMillis, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Futures.notifyFailure(future, completionHandler, e); } catch (TimeoutException e) { Futures.notifyFailure(future, completionHandler, new IOException("Channel registration on Selector timeout!")); } catch (Exception ingored) { } }
@Override public NextAction handleClose(FilterChainContext ctx) throws IOException { if (!future.isDone()) { future.failure(new EOFException("handleClose was called")); } return ctx.getStopAction(); } }
/** * Method is called, when UDP message came from the server. * * @param ctx the {@link FilterChainContext}. * @return * @throws IOException */ @Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { // We have StringFilter down on the filterchain - so we can get String directly final String messageFromServer = ctx.getMessage(); // check the echo future.result(message.equals(messageFromServer)); return ctx.getInvokeAction(); }
public void register() throws IOException { final FutureImpl<RegisterChannelResult> future = Futures.createSafeFuture(); transport.getNIOChannelDistributor().registerServiceChannelAsync( channel, SelectionKey.OP_READ, this, Futures.toCompletionHandler(future, ((UDPNIOTransport) transport).registerChannelCompletionHandler )); try { future.get(10, TimeUnit.SECONDS); } catch (Exception e) { throw new IOException("Error registering server channel key", e); } notifyReady(); }
@Override public NextAction handleRead(FilterChainContext ctx) throws IOException { try { final Buffer buffer = ctx.getMessage(); final String rcvdStr = buffer.toStringContent(); final String expectedChunk = patternString.substring(bytesReceived, bytesReceived + buffer.remaining()); if (!expectedChunk.equals(rcvdStr)) { clientFuture.failure(new AssertionError("Content doesn't match. Expected: " + expectedChunk + " Got: " + rcvdStr)); } bytesReceived += buffer.remaining(); if (bytesReceived == patternString.length()) { clientFuture.result(bytesReceived); } } catch (Exception e) { clientFuture.failure(e); } return super.handleRead(ctx); }
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (!delegate.isCancelled() || !delegate.isDone()) { return delegate.get(timeout, unit); } else { return null; } }