Refine search
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 ChannelListener<StreamConnection>() { public void handleEvent(final StreamConnection connection) { } catch (IOException e) { if (futureResult.setException(e)) { IoUtils.safeClose(connection); if (! futureResult.setResult(wrappedConnection)) { IoUtils.safeClose(connection); } else { ChannelListeners.invokeChannelListener(wrappedConnection, openListener); connection.addNotifier(new IoFuture.HandlingNotifier<StreamConnection, FutureResult<SslConnection>>() { public void handleCancelled(final FutureResult<SslConnection> attachment) { attachment.setCancelled(); futureResult.addCancelHandler(connection); return futureResult.getIoFuture();
@Override public void handleException(StreamSinkChannel channel, IOException exception) { safeClose(channel); future.setException(exception); } }));
public Cancellable cancel() { if (futureResult.setCancelled()) { safeClose(channel); } return this; } });
private IoFuture<SslConnection> setupSslConnection(FutureResult<SslConnection> futureResult, IoFuture<StreamConnection> connection) { connection.addNotifier(new IoFuture.HandlingNotifier<StreamConnection, FutureResult<SslConnection>>() { public void handleCancelled(final FutureResult<SslConnection> attachment) { attachment.setCancelled(); } public void handleFailed(final IOException exception, final FutureResult<SslConnection> attachment) { attachment.setException(exception); } }, futureResult); futureResult.addCancelHandler(connection); return futureResult.getIoFuture(); }
@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(); } }
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(); }
if (contentLength != null) { if (!"0".equals(contentLength)) { future.setException(new IOException("Upgrade responses must have a content length of zero.")); return; future.setException(new IOException("Upgrade responses cannot have a transfer coding")); return; safeClose(connection); future.setException(e); return; future.setResult(connection); ChannelListeners.invokeChannelListener(connection, openListener);
public void handleEvent(final StreamConnection channel) { final AssembledConnectedStreamChannel assembledChannel = new AssembledConnectedStreamChannel(channel, channel.getSourceChannel(), channel.getSinkChannel()); if (!futureResult.setResult(assembledChannel)) { safeClose(assembledChannel); } else { ChannelListeners.invokeChannelListener(assembledChannel, openListener); } } }
/** * 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(); }
return new FailedIoFuture<StreamConnection>(e); final FutureResult<StreamConnection> futureResult = new FutureResult<StreamConnection>(this); try { boolean ok = false; if (bindListener != null) ChannelListeners.invokeChannelListener(new BoundChannel() { public SocketAddress getLocalAddress() { return serverChannel.socket().getLocalSocketAddress(); handle.resume(SelectionKey.OP_ACCEPT); ok = true; futureResult.addCancelHandler(new Cancellable() { public Cancellable cancel() { if (futureResult.setCancelled()) { return futureResult.getIoFuture(); } finally { if (! ok) safeClose(serverChannel);
private void flushUpgradeChannel() { try { if(!connection.getSinkChannel().flush()) { connection.getSinkChannel().getWriteSetter().set(ChannelListeners.flushingChannelListener(new ChannelListener<StreamSinkChannel>() { @Override public void handleEvent(StreamSinkChannel channel) { channel.suspendWrites(); new UpgradeResultListener().handleEvent(connection.getSourceChannel()); } }, new ChannelExceptionHandler<StreamSinkChannel>() { @Override public void handleException(StreamSinkChannel channel, IOException exception) { safeClose(channel); future.setException(exception); } })); connection.getSinkChannel().resumeWrites(); return; } } catch (IOException e) { safeClose(connection); future.setException(e); return; } new UpgradeResultListener().handleEvent(connection.getSourceChannel()); }
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; }
mis.read(namingHeader); if (! Arrays.equals(namingHeader, ProtocolUtils.NAMING_BYTES)) { futureResult.setException(new IOException(Messages.log.invalidHeader())); return; version = 1; } else { futureResult.setException(new IOException(Messages.log.noCompatibleVersions())); return; futureResult.setResult(remoteClientTransport); } catch (IOException e) { safeClose(channel); futureResult.setException(new IOException(Messages.log.connectFailed(e))); return;
FutureResult<ConnectionPeerIdentity> futureResult = new FutureResult<>(connection.getEndpoint().getExecutor()); final IoFuture<ConnectionPeerIdentity> appearing = futureAuths.putIfAbsent(configuration, futureResult.getIoFuture()); if (appearing != null) { ioFuture = appearing; } else { AtomicReference<Thread> threadRef = new AtomicReference<>(Thread.currentThread()); futureResult.addCancelHandler(new Cancellable() { public Cancellable cancel() { final Thread thread = threadRef.get(); threadRef.set(null); ioFuture = futureResult.getIoFuture(); return ioFuture.get(); } catch (AuthenticationException e) { throw e;
throws IOException, InterruptedException, KeyManagementException, NoSuchProviderException, NoSuchAlgorithmException { XnioSsl xnioSsl = new JsseXnioSsl(context.getXnio(), options); FutureResult<ConnectionHandlerFactory> result = new FutureResult<ConnectionHandlerFactory>(); instance.connect(null, destination, options, result, new CallbackHandler() { IoFuture<ConnectionHandlerFactory> ioFuture = result.getIoFuture(); Status s = ioFuture.await(5, TimeUnit.SECONDS); if ( s == Status.FAILED ) { System.err.println("Cannot connect"); if ( ioFuture.getException() != null ) { ioFuture.getException().printStackTrace(System.err);
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(); } }
return ioFuture; final FutureResult<ConnectionPeerIdentity> futureResult = new FutureResult<>(connection.getEndpoint().getExecutor()); ioFuture = futureAuths.putIfAbsent(configuration, futureResult.getIoFuture()); if (ioFuture != null) { return ioFuture; futureResult.setResult(authenticate(configuration)); } catch (AuthenticationException e) { futureResult.setException(e); futureResult.addCancelHandler(new Cancellable() { public Cancellable cancel() { Object oldVal; return futureResult.getIoFuture();
final FutureResult<Connection> futureResult = new FutureResult<Connection>(getExecutor()); futureResult.setCancelled(); return true; futureResult.setCancelled(); } else { futureResult.setResult(connection); ); ok = true; futureResult.addCancelHandler(connect); return futureResult.getIoFuture(); } finally { if (! ok) {
protected IoFuture<StreamConnection> createConnection(final URI uri, final InetSocketAddress bindAddress, final InetSocketAddress destination, final OptionMap connectOptions, final ChannelListener<StreamConnection> openListener) { final URI newUri; try { newUri = new URI("http", "", uri.getHost(), uri.getPort(), "/", "", ""); } catch (URISyntaxException e) { return new FailedIoFuture<>(new IOException(e)); } final FutureResult<StreamConnection> returnedFuture = new FutureResult<>(getExecutor()); ChannelListener<StreamConnection> upgradeListener = new UpgradeListener<StreamConnection>(StreamConnection.class, newUri, openListener, returnedFuture); IoFuture<StreamConnection> rawFuture = super.createConnection(uri, bindAddress, destination, connectOptions, upgradeListener); rawFuture.addNotifier( new IoFuture.HandlingNotifier<StreamConnection, FutureResult<StreamConnection>>() { @Override public void handleCancelled(FutureResult<StreamConnection> attachment) { attachment.setCancelled(); } @Override public void handleFailed(IOException exception, FutureResult<StreamConnection> attachment) { attachment.setException(exception); } } , returnedFuture); return returnedFuture.getIoFuture(); }
@Override public void failed(IOException e) { ioFuture.setException(e); } }, bindAddress, proxyUri, worker, proxySsl, bufferPool, optionMap);