Refine search
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; }
@Override public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) { ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() { @Override public void handleEvent(StreamConnection connection) { handleConnected(connection, listener, uri, ssl, bufferPool, options); } }; IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() { @Override public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) { if (ioFuture.getStatus() == IoFuture.Status.FAILED) { listener.failed(ioFuture.getException()); } } }; if(bindAddress == null) { worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null); } else { worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null); } }
/** * {@inheritDoc} */ public void notify(final IoFuture<? extends T> future, A attachment) { switch (future.getStatus()) { case CANCELLED: handleCancelled(attachment); break; case DONE: try { handleDone(future.get(), attachment); } catch (IOException e) { // not possible throw new IllegalStateException(); } break; case FAILED: handleFailed(future.getException(), attachment); break; default: // not possible throw new IllegalStateException(); } }
/** * Close a future resource, logging an error if an error occurs. Attempts to cancel the operation if it is * still in progress. * * @param futureResource the resource to close */ public static void safeClose(final IoFuture<? extends Closeable> futureResource) { if (futureResource != null) { futureResource.cancel().addNotifier(closingNotifier(), null); } }
@Override public void notify(IoFuture<? extends StreamConnection> ioFuture, Object attachment) { if (ioFuture.getStatus() == IoFuture.Status.FAILED) { listener.failed(ioFuture.getException()); } } }
@Override public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) { final URI upgradeUri; try { upgradeUri = new URI("http", uri.getUserInfo(), uri.getHost(), uri.getPort(), uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { listener.failed(new IOException(e)); return; } Map<String, String> headers = createHeaders(options, bufferPool, uri); HttpUpgrade.performUpgrade(worker, bindAddress, upgradeUri, headers, new Http2ClearOpenListener(bufferPool, options, listener, uri.getHost()), null, options, null).addNotifier(new FailedNotifier(listener), null); }
private IoFuture<WebSocketChannel> connectImpl(final URI uri, final FutureResult<WebSocketChannel> ioFuture, final int redirectCount) { WebSocketLogger.REQUEST_LOGGER.debugf("Opening websocket connection to %s", uri); final String scheme = uri.getScheme().equals("wss") ? "https" : "http"; final URI newUri; try { newUri = new URI(scheme, uri.getUserInfo(), uri.getHost(), uri.getPort() == -1 ? (uri.getScheme().equals("wss") ? 443 : 80) : uri.getPort(), uri.getPath().isEmpty() ? "/" : uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { throw new RuntimeException(e); String sysBind = System.getProperty(BIND_PROPERTY); if(toBind == null && sysBind != null) { toBind = new InetSocketAddress(sysBind, 0); result = HttpUpgrade.performUpgrade(worker, toBind, newUri, headers, new WebsocketConnectionListener(optionMap, handshake, newUri, ioFuture), null, optionMap, handshake.handshakeChecker(newUri, headers)); result.addNotifier(new IoFuture.Notifier<Object, Object>() { @Override public void notify(IoFuture<?> res, Object attachment) { ioFuture.addCancelHandler(new Cancellable() { @Override public Cancellable cancel() { return ioFuture.getIoFuture();
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(); }
ClientConnection connection = null; try { connection = client.connect(new URI(configUri), Http2Client.WORKER, Http2Client.SSL, Http2Client.BUFFER_POOL, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get(); } catch (Exception e) { logger.error("Exeption:", e); logger.error("Exception:", e); } finally { IoUtils.safeClose(connection);
this.httpClient.connect(url, this.worker, this.bufferPool, this.optionMap).get(); try { ClientRequest request = new ClientRequest().setMethod(method).setPath(url.getPath()); request.getRequestHeaders().add(HttpString.tryFromString(HttpHeaders.HOST), url.getHost()); if (StringUtils.hasLength(body)) { HttpString headerName = HttpString.tryFromString(HttpHeaders.CONTENT_LENGTH); IoUtils.safeClose(connection);
authConfigUri = (URI) authConfig; } else { authConfigUri = URI.create(authConfig.toString()); context = sslContext != null ? context.withSsl(MatchRule.ALL, () -> sslContext) : context; final IoFuture<Connection> futureConnection = endpoint.connect(convert(serviceUrl), getOptionMap(disabledMechanisms), context); IoFuture.Status result = futureConnection.await(getTimeoutValue(Timeout.CONNECTION, env), TimeUnit.SECONDS); connection = futureConnection.get(); } else if (result == IoFuture.Status.FAILED) { throw futureConnection.getException(); } else { throw new IOException("Operation failed with status " + result);
@Override public void run() { exchange.getConnection().getIoThread().openStreamConnection(new InetSocketAddress(host, port), new ChannelListener<StreamConnection>() { @Override public void handleEvent(final StreamConnection clientChannel) { exchange.acceptConnectRequest(new HttpUpgradeListener() { @Override public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) { final ClosingExceptionHandler handler = new ClosingExceptionHandler(streamConnection, clientChannel); Transfer.initiateTransfer(clientChannel.getSourceChannel(), streamConnection.getSinkChannel(), ChannelListeners.closingChannelListener(), ChannelListeners.writeShutdownChannelListener(ChannelListeners.<StreamSinkChannel>flushingChannelListener(ChannelListeners.closingChannelListener(), ChannelListeners.closingChannelExceptionHandler()), ChannelListeners.closingChannelExceptionHandler()), handler, handler, exchange.getConnection().getByteBufferPool()); Transfer.initiateTransfer(streamConnection.getSourceChannel(), clientChannel.getSinkChannel(), ChannelListeners.closingChannelListener(), ChannelListeners.writeShutdownChannelListener(ChannelListeners.<StreamSinkChannel>flushingChannelListener(ChannelListeners.closingChannelListener(), ChannelListeners.closingChannelExceptionHandler()), ChannelListeners.closingChannelExceptionHandler()), handler, handler, exchange.getConnection().getByteBufferPool()); } }); exchange.setStatusCode(200); exchange.endExchange(); } }, OptionMap.create(Options.TCP_NODELAY, true)).addNotifier(new IoFuture.Notifier<StreamConnection, Object>() { @Override public void notify(IoFuture<? extends StreamConnection> ioFuture, Object attachment) { if(ioFuture.getStatus() == IoFuture.Status.FAILED) { exchange.setStatusCode(503); exchange.endExchange(); } } },null); } });
void connectAndDiscover(URI uri, String clusterEffective) { final String scheme = uri.getScheme(); if (scheme == null || ! ejbReceiver.getRemoteTransportProvider().supportsProtocol(scheme) || ! endpoint.isValidUriScheme(scheme)) { countDown(); return; } outstandingCount.getAndIncrement(); final IoFuture<ConnectionPeerIdentity> future = doPrivileged((PrivilegedAction<IoFuture<ConnectionPeerIdentity>>) () -> getConnectedIdentityUsingClusterEffective(endpoint, uri, "ejb", "jboss", authenticationContext, clusterEffective)); onCancel(future::cancel); future.addNotifier(outerNotifier, uri); }
@Override public void handleEvent(StreamConnection channel) { Map<String, String> headers = createHeaders(options, bufferPool, uri); HttpUpgrade.performUpgrade(channel, upgradeUri, headers, new Http2ClearOpenListener(bufferPool, options, listener, uri.getHost()), null).addNotifier(new FailedNotifier(listener), null); } }, new ChannelListener<BoundChannel>() {
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();
void start() throws IOException { sendVersionHeader(); IoFuture<String> futureConnectionId = ConnectionIdReceiver.getConnectionId(channel); IoFuture.Status result = futureConnectionId.await(timeoutSeconds, TimeUnit.SECONDS); switch (result) { case DONE: connectionId = futureConnectionId.get(); mbeanServerConnection = new TheConnection(); localNotificationManager = new LocalNotificationManager(); channel.receiveMessage(new MessageReceiver()); break; case FAILED: throw futureConnectionId.getException(); default: throw new IOException("Unable to obtain connectionId, status=" + result.toString()); } }
/** * 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(); }
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); ioFuture.cancel(); System.err.println("Connect timeout"); System.exit(-1); ConnectionHandlerFactory chf = ioFuture.getInterruptibly(); return chf;
private boolean connectUsingRemoting(CommandContext cmdCtx, RemotingMBeanServerConnection rmtMBeanSvrConn) throws IOException, CliInitializationException { Connection conn = rmtMBeanSvrConn.getConnection(); Channel channel; final IoFuture<Channel> futureChannel = conn.openChannel("management", OptionMap.EMPTY); IoFuture.Status result = futureChannel.await(5, TimeUnit.SECONDS); if (result == IoFuture.Status.DONE) { channel = futureChannel.get(); } else { futureChannel.cancel(); return false; } ModelControllerClient modelCtlrClient = ExistingChannelModelControllerClient.createReceiving(channel, createExecutor()); cmdCtx.bindClient(modelCtlrClient); return true; }