public IoFuture<WebSocketChannel> connect() { return connectImpl(uri, new FutureResult<WebSocketChannel>(), 0); } private IoFuture<WebSocketChannel> connectImpl(final URI uri, final FutureResult<WebSocketChannel> ioFuture, final int redirectCount) {
@Override public IoFuture<Void> sendData(final ByteBuffer data) { try { while (data.hasRemaining()) { out.write(data.get()); } return new FinishedIoFuture<>(null); } catch (IOException e) { final FutureResult<Void> ioFuture = new FutureResult<>(); ioFuture.setException(e); return ioFuture.getIoFuture(); } }
@Override public IoFuture<byte[]> readRequestData() { final ByteArrayOutputStream data = new ByteArrayOutputStream(); try { byte[] buf = new byte[1024]; int r; while ((r = in.read(buf)) != -1) { data.write(buf, 0, r); } return new FinishedIoFuture<>(data.toByteArray()); } catch (IOException e) { final FutureResult<byte[]> ioFuture = new FutureResult<>(); ioFuture.setException(e); return ioFuture.getIoFuture(); } } }
public IoFuture<SslConnection> openSslConnection(final XnioWorker worker, final InetSocketAddress bindAddress, final InetSocketAddress destination, final ChannelListener<? super SslConnection> openListener, final ChannelListener<? super BoundChannel> bindListener, final OptionMap optionMap) { final FutureResult<SslConnection> futureResult = new FutureResult<>(worker); final IoFuture<StreamConnection> connection = worker.openStreamConnection(bindAddress, destination, new StreamConnectionChannelListener(optionMap, destination, futureResult, openListener), bindListener, optionMap); return setupSslConnection(futureResult, connection); } @Override
@Override public IoFuture<SslConnection> openSslConnection(final XnioIoThread ioThread, final InetSocketAddress bindAddress, final InetSocketAddress destination, final ChannelListener<? super SslConnection> openListener, final ChannelListener<? super BoundChannel> bindListener, final OptionMap optionMap) { final FutureResult<SslConnection> futureResult = new FutureResult<>(ioThread); final IoFuture<StreamConnection> connection = ioThread.openStreamConnection(bindAddress, destination, new StreamConnectionChannelListener(optionMap, destination, futureResult, openListener), bindListener, optionMap); return setupSslConnection(futureResult, connection); }
public IoFuture<T> open(final ChannelListener<? super T> openListener) { final FutureResult<T> result = new FutureResult<T>(); final IoUtils.RetryingNotifier<T> notifier = new IoUtils.RetryingNotifier<T>(maxTries, result, delegate, openListener); notifier.tryOne(result); return result.getIoFuture(); } }
public IoFuture<ClientConnection> connect(InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) { ClientProvider provider = getClientProvider(uri); final FutureResult<ClientConnection> result = new FutureResult<>(); provider.connect(new ClientCallback<ClientConnection>() { @Override public void completed(ClientConnection r) { result.setResult(r); } @Override public void failed(IOException e) { result.setException(e); } }, bindAddress, uri, worker, ssl, bufferPool, options); return result.getIoFuture(); }
public IoFuture<ClientConnection> connect(InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) { ClientProvider provider = getClientProvider(uri); final FutureResult<ClientConnection> result = new FutureResult<>(); provider.connect(new ClientCallback<ClientConnection>() { @Override public void completed(ClientConnection r) { result.setResult(r); } @Override public void failed(IOException e) { result.setException(e); } }, bindAddress, uri, ioThread, ssl, bufferPool, options); return result.getIoFuture(); }
public IoFuture<Channel> openChannel(final String serviceType, final OptionMap optionMap) { FutureResult<Channel> result = new FutureResult<Channel>(getExecutor()); result.addCancelHandler(connectionHandler.open(serviceType, result, optionMap)); return result.getIoFuture(); }
public IoFuture<ClientConnection> connect(InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) { ClientProvider provider = getClientProvider(uri); final FutureResult<ClientConnection> result = new FutureResult<>(); provider.connect(new ClientCallback<ClientConnection>() { @Override public void completed(ClientConnection r) { result.setResult(r); } @Override public void failed(IOException e) { result.setException(e); } }, bindAddress, uri, worker, ssl, bufferPool, options); return result.getIoFuture(); }
@Override public IoFuture<Void> sendData(final ByteBuffer data) { if (sender == null) { this.sender = exchange.getResponseSender(); } final FutureResult<Void> future = new FutureResult<>(); sender.send(data, new IoCallback() { @Override public void onComplete(final HttpServerExchange exchange, final Sender sender) { future.setResult(null); } @Override public void onException(final HttpServerExchange exchange, final Sender sender, final IOException exception) { UndertowLogger.REQUEST_IO_LOGGER.ioException(exception); future.setException(exception); } }); return future.getIoFuture(); }
public IoFuture<ClientConnection> connect(InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) { ClientProvider provider = getClientProvider(uri); final FutureResult<ClientConnection> result = new FutureResult<>(); provider.connect(new ClientCallback<ClientConnection>() { @Override public void completed(ClientConnection r) { result.setResult(r); } @Override public void failed(IOException e) { result.setException(e); } }, bindAddress, uri, ioThread, ssl, bufferPool, options); return result.getIoFuture(); }
/** * Connect to a remote stream server. The protocol family is determined by the type of the socket address given. * * @param destination the destination address * @param openListener the listener which will be notified when the channel is open, or {@code null} for none * @param optionMap the option map * @return the future result of this operation */ @Deprecated public IoFuture<ConnectedStreamChannel> connectStream(SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, OptionMap optionMap) { final FutureResult<ConnectedStreamChannel> futureResult = new FutureResult<ConnectedStreamChannel>(); final ChannelListener<StreamConnection> nestedOpenListener = new StreamConnectionWrapListener(futureResult, openListener); final IoFuture<StreamConnection> future = openStreamConnection(destination, nestedOpenListener, optionMap); future.addNotifier(STREAM_WRAPPING_HANDLER, futureResult); futureResult.addCancelHandler(future); return futureResult.getIoFuture(); }
/** * Connect to a remote stream server. The protocol family is determined by the type of the socket address given. * * @param destination the destination address * @param openListener the listener which will be notified when the channel is open, or {@code null} for none * @param bindListener the listener which will be notified when the channel is bound, or {@code null} for none * @param optionMap the option map * @return the future result of this operation */ @Deprecated public IoFuture<ConnectedStreamChannel> connectStream(SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) { final FutureResult<ConnectedStreamChannel> futureResult = new FutureResult<ConnectedStreamChannel>(); final ChannelListener<StreamConnection> nestedOpenListener = new StreamConnectionWrapListener(futureResult, openListener); final IoFuture<StreamConnection> future = openStreamConnection(destination, nestedOpenListener, bindListener, optionMap); future.addNotifier(STREAM_WRAPPING_HANDLER, futureResult); futureResult.addCancelHandler(future); return futureResult.getIoFuture(); }
/** * Connect to a remote datagram server. The protocol family is determined by the type of the socket address given. * * @param destination the destination address * @param openListener the listener which will be notified when the channel is open, or {@code null} for none * @param bindListener the listener which will be notified when the channel is bound, or {@code null} for none * @param optionMap the option map * @return the future result of this operation */ @Deprecated // FIXME XNIO-192 invoke bind listener public IoFuture<ConnectedMessageChannel> connectDatagram(SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) { final FutureResult<ConnectedMessageChannel> futureResult = new FutureResult<ConnectedMessageChannel>(); final ChannelListener<MessageConnection> nestedOpenListener = new MessageConnectionWrapListener(futureResult, openListener); final IoFuture<MessageConnection> future = openMessageConnection(destination, nestedOpenListener, optionMap); future.addNotifier(MESSAGE_WRAPPING_HANDLER, futureResult); futureResult.addCancelHandler(future); return futureResult.getIoFuture(); }
/** * Accept a stream connection at a destination address. If a wildcard address is specified, then a destination address * is chosen in a manner specific to the OS and/or channel type. * * @param destination the destination (bind) address * @param openListener the listener which will be notified when the channel is open, or {@code null} for none * @param bindListener the listener which will be notified when the acceptor is bound, or {@code null} for none * @param optionMap the option map * @return the future connection */ @Deprecated public IoFuture<ConnectedStreamChannel> acceptStream(SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) { final FutureResult<ConnectedStreamChannel> futureResult = new FutureResult<ConnectedStreamChannel>(); final ChannelListener<StreamConnection> nestedOpenListener = new StreamConnectionWrapListener(futureResult, openListener); final IoFuture<StreamConnection> future = acceptStreamConnection(destination, nestedOpenListener, bindListener, optionMap); future.addNotifier(STREAM_WRAPPING_HANDLER, futureResult); futureResult.addCancelHandler(future); return futureResult.getIoFuture(); }
/** * Accept a message connection at a destination address. If a wildcard address is specified, then a destination address * is chosen in a manner specific to the OS and/or channel type. * * @param destination the destination (bind) address * @param openListener the listener which will be notified when the channel is open, or {@code null} for none * @param bindListener the listener which will be notified when the acceptor is bound, or {@code null} for none * @param optionMap the option map * @return the future connection */ @Deprecated public IoFuture<ConnectedMessageChannel> acceptDatagram(SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) { final FutureResult<ConnectedMessageChannel> futureResult = new FutureResult<ConnectedMessageChannel>(); final ChannelListener<MessageConnection> nestedOpenListener = new MessageConnectionWrapListener(futureResult, openListener); final IoFuture<MessageConnection> future = acceptMessageConnection(destination, nestedOpenListener, bindListener, optionMap); future.addNotifier(MESSAGE_WRAPPING_HANDLER, futureResult); futureResult.addCancelHandler(future); return futureResult.getIoFuture(); }
/** * Connect to a remote stream server. The protocol family is determined by the type of the socket addresses given * (which must match). * * @param bindAddress the local address to bind to * @param destination the destination address * @param openListener the listener which will be notified when the channel is open, or {@code null} for none * @param bindListener the listener which will be notified when the channel is bound, or {@code null} for none * @param optionMap the option map * @return the future result of this operation */ @Deprecated public IoFuture<ConnectedStreamChannel> connectStream(SocketAddress bindAddress, SocketAddress destination, ChannelListener<? super ConnectedStreamChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) { final FutureResult<ConnectedStreamChannel> futureResult = new FutureResult<ConnectedStreamChannel>(); final ChannelListener<StreamConnection> nestedOpenListener = new StreamConnectionWrapListener(futureResult, openListener); final IoFuture<StreamConnection> future = openStreamConnection(bindAddress, destination, nestedOpenListener, bindListener, optionMap); future.addNotifier(STREAM_WRAPPING_HANDLER, futureResult); futureResult.addCancelHandler(future); return futureResult.getIoFuture(); }
/** * Connect to a remote datagram server. The protocol family is determined by the type of the socket addresses given * (which must match). * * @param bindAddress the local address to bind to * @param destination the destination address * @param openListener the listener which will be notified when the channel is open, or {@code null} for none * @param bindListener the listener which will be notified when the channel is bound, or {@code null} for none * @param optionMap the option map * @return the future result of this operation */ @Deprecated // FIXME bindAddress is now ignored public IoFuture<ConnectedMessageChannel> connectDatagram(SocketAddress bindAddress, SocketAddress destination, ChannelListener<? super ConnectedMessageChannel> openListener, ChannelListener<? super BoundChannel> bindListener, OptionMap optionMap) { final FutureResult<ConnectedMessageChannel> futureResult = new FutureResult<ConnectedMessageChannel>(); final ChannelListener<MessageConnection> nestedOpenListener = new MessageConnectionWrapListener(futureResult, openListener); final IoFuture<MessageConnection> future = openMessageConnection(destination, nestedOpenListener, optionMap); future.addNotifier(MESSAGE_WRAPPING_HANDLER, futureResult); futureResult.addCancelHandler(future); return futureResult.getIoFuture(); }
private static Channel getChannel ( ConnectionProviderContextImpl context, ConnectionHandler ch, OptionMap options ) throws IOException { Channel c; FutureResult<Channel> chResult = new FutureResult<Channel>(context.getExecutor()); ch.open("jmx", chResult, options); IoFuture<Channel> cFuture = chResult.getIoFuture(); Status s2 = cFuture.await(); if ( s2 == Status.FAILED ) { System.err.println("Cannot connect"); if ( cFuture.getException() != null ) { throw new IOException("Connect failed", cFuture.getException()); } } else if ( s2 != Status.DONE ) { cFuture.cancel(); throw new IOException("Connect timeout"); } c = cFuture.get(); return c; }