public <A> IoFuture<O> addNotifier(final Notifier<? super O, A> notifier, final A attachment) { parent.addNotifier(new Notifier<I, A>() { public void notify(final IoFuture<? extends I> future, final A attachment) { notifier.notify(CastingIoFuture.this, attachment); } }, attachment); return this; } }
public <A> IoFuture<T> addNotifier(final Notifier<? super T, A> notifier, A attachment) { delegate.addNotifier(new Notifier<D, A>() { public void notify(final IoFuture<? extends D> future, A attachment) { notifier.notify(AbstractConvertingIoFuture.this, attachment); } }, attachment); return this; } }
/** * Wait for all the futures to complete. * * @param futures the futures to wait for * @throws InterruptedException if the current thread is interrupted while waiting */ public static void awaitAllInterruptibly(IoFuture<?>... futures) throws InterruptedException { final int len = futures.length; final CountDownLatch cdl = new CountDownLatch(len); for (IoFuture<?> future : futures) { future.addNotifier(COUNT_DOWN_NOTIFIER, cdl); } cdl.await(); }
private static void writePayload(final WebSocketHttpExchange exchange, final ByteBuffer payload) { exchange.sendData(payload).addNotifier(new IoFuture.Notifier<Void, Object>() { @Override public void notify(final IoFuture<? extends Void> ioFuture, final Object attachment) { if (ioFuture.getStatus() == IoFuture.Status.DONE) { exchange.endExchange(); } else { exchange.close(); } } }, null); }
void tryOne(final Result<T> attachment) { final IoFuture<? extends T> ioFuture = delegate.open(openListener); ioFuture.addNotifier(this, attachment); } }
void splice(FutureResult<Connection> futureResult, IoFuture<Connection> realFuture, final AuthenticationConfiguration authConfig) { // always add in this order futureResult.addCancelHandler(realFuture); realFuture.addNotifier(new IoFuture.HandlingNotifier<Connection, FutureResult<Connection>>() { public void handleCancelled(final FutureResult<Connection> futureResult1) { futureResult1.setCancelled(); } public void handleFailed(final IOException exception, final FutureResult<Connection> futureResult1) { futureResult1.setException(exception); } public void handleDone(final Connection connection, final FutureResult<Connection> futureResult1) { futureResult1.setResult(new ManagedConnection(connection, ConnectionInfo.this, authConfig, futureResult1)); } }, futureResult); }
@Override public void connect(final ClientCallback<ClientConnection> listener, final InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) { if (bindAddress == null) { ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), options).addNotifier(createNotifier(listener), null); } else { ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), null, options).addNotifier(createNotifier(listener), null); } }
@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) { if (bindAddress == null) { worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), options).addNotifier(createNotifier(listener), null); } else { worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), null, options).addNotifier(createNotifier(listener), null); }}
@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<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(); }
/** * 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 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>() {
@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>() {
@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) { if (ssl == null) { listener.failed(UndertowMessages.MESSAGES.sslWasNull()); return; } OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap(); if(bindAddress == null) { ssl.openSslConnection(worker, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), tlsOptions).addNotifier(createNotifier(listener), null); } else { ssl.openSslConnection(worker, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), tlsOptions).addNotifier(createNotifier(listener), null); } }
@Override public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) { if (ssl == null) { listener.failed(UndertowMessages.MESSAGES.sslWasNull()); return; } if(bindAddress == null) { OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap(); ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), options).addNotifier(createNotifier(listener), null); } else { ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, options), options).addNotifier(createNotifier(listener), 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); }
private Mono<Void> executeInternal(URI url, HttpHeaders headers, WebSocketHandler handler) { MonoProcessor<Void> completion = MonoProcessor.create(); return Mono.fromCallable( () -> { if (logger.isDebugEnabled()) { logger.debug("Connecting to " + url); } List<String> protocols = handler.getSubProtocols(); ConnectionBuilder builder = createConnectionBuilder(url); DefaultNegotiation negotiation = new DefaultNegotiation(protocols, headers, builder); builder.setClientNegotiation(negotiation); return builder.connect().addNotifier( new IoFuture.HandlingNotifier<WebSocketChannel, Object>() { @Override public void handleDone(WebSocketChannel channel, Object attachment) { handleChannel(url, handler, completion, negotiation, channel); } @Override public void handleFailed(IOException ex, Object attachment) { completion.onError(new IllegalStateException("Failed to connect to " + url, ex)); } }, null); }) .then(completion); }
/** * 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(); }
protected void processInvocation(final EJBReceiverInvocationContext receiverContext) throws Exception { final AuthenticationContext authenticationContext = receiverContext.getAuthenticationContext(); final IoFuture<ConnectionPeerIdentity> futureConnection = getConnection(receiverContext.getClientInvocationContext(), receiverContext.getClientInvocationContext().getDestination(), authenticationContext); // this actually causes the invocation to move forward futureConnection.addNotifier(notifier, receiverContext); }