/** * Creates, initializes and connects socket to the specific * {@link SocketAddress} and returns {@link Connection}, representing socket. * * @param remoteAddress remote address to connect to. * @return {@link GrizzlyFuture} of connect operation, which could be used to get * resulting {@link Connection}. */ @Override public GrizzlyFuture<Connection> connect(final SocketAddress remoteAddress) { return connectorHandler.connect(remoteAddress); }
public TCPNIOConnectorHandler build() { TCPNIOConnectorHandler handler = (TCPNIOConnectorHandler) super.build(); if (reuseAddress != null) { handler.setReuseAddress(reuseAddress); } if (timeout != null) { handler.setSyncConnectTimeout(timeout, timeoutTimeunit); } return handler; }
@Override protected AbstractSocketConnectorHandler create() { if (transport == null) { throw new IllegalStateException( "Unable to create TCPNIOConnectorHandler - transport is null"); } return new TCPNIOConnectorHandler(transport); } }
protected void connectSync(SocketAddress remoteAddress, SocketAddress localAddress, CompletionHandler<Connection> completionHandler) { final FutureImpl<Connection> future = connectAsync(remoteAddress, localAddress, completionHandler, true); waitNIOFuture(future, completionHandler); }
@Override public void connect(final SocketAddress remoteAddress, final SocketAddress localAddress, final CompletionHandler<Connection> completionHandler) { if (!transport.isBlocking()) { connectAsync(remoteAddress, localAddress, completionHandler, false); } else { connectSync(remoteAddress, localAddress, completionHandler); } }
preConfigure(finalConnection); finalConnection.setProcessor(getProcessor()); finalConnection.setProcessorSelector(getProcessorSelector()); futureToReturn = makeCancellableFuture(finalConnection); completionHandlerToPass = resolveFutureAndCompletionHandler(completionHandler, onlyAddCompletionHandlerToFuture, futureToReturn); } else {
connectorHandler.setProcessor(createFilterChain(null, clientSSLEngineConfigurator, proxy != null)); connectorHandler.connect(new InetSocketAddress(proxy.getHost(), proxyPort)); } else { connectorHandler.connect(new InetSocketAddress(uri.getHost(), port)); connectorHandler.setSyncConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS); awaitOnConnect(); } catch (Exception e) {
this.poolingSSLConnections = config.isAllowPoolingSslConnections(); defaultConnectionHandler = TCPNIOConnectorHandler.builder(transport).build();
protected static void onConnectedAsync(final TCPNIOConnection connection, final CompletionHandler<Connection> completionHandler) throws IOException { final TCPNIOTransport tcpTransport = (TCPNIOTransport) connection.getTransport(); final SocketChannel channel = (SocketChannel) connection.getChannel(); try { if (!channel.isConnected()) { channel.finishConnect(); } connection.resetProperties(); // Deregister OP_CONNECT interest connection.disableIOEvent(IOEvent.CLIENT_CONNECTED); // we can call configure for ready channel tcpTransport.getChannelConfigurator().postConfigure(tcpTransport, channel); } catch (Exception e) { abortConnection(connection, completionHandler, e); throw Exceptions.makeIOException(e); } if (connection.notifyReady()) { tcpTransport.fireIOEvent(IOEvent.CONNECTED, connection, new EnableReadHandler(completionHandler)); } }
@Override protected FutureImpl<Connection> connectAsync( final SocketAddress remoteAddress, final SocketAddress localAddress, final CompletionHandler<Connection> completionHandler, final boolean needFuture) { return connectAsync(remoteAddress, localAddress, completionHandler, needFuture, false); }
@Override protected void preConfigure(Connection conn) { super.preConfigure(conn); final org.glassfish.tyrus.websockets.Connection connection = getConnection(conn); protocolHandler.setConnection(connection); WebSocketEngine.WebSocketHolder holder = WebSocketEngine.getEngine() .setWebSocketHolder(connection, protocolHandler, RequestContext.Builder.create().requestURI(uri).build(), GrizzlyClientSocket.this, null); prepareHandshake(holder.handshake); } };
preConfigure(finalConnection); finalConnection.setProcessor(getProcessor()); finalConnection.setProcessorSelector(getProcessorSelector()); futureToReturn = makeCancellableFuture(finalConnection);
@Override public void connect(final SocketAddress remoteAddress, final SocketAddress localAddress, final CompletionHandler<Connection> completionHandler) { if (!transport.isBlocking()) { connectAsync(remoteAddress, localAddress, completionHandler, false); } else { connectSync(remoteAddress, localAddress, completionHandler); } }
}; connectorHandler.setSyncConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS); connectorHandler.setProcessor( createFilterChain(clientEngine, null, clientSSLEngineConfigurator, !(proxy.type() == Proxy.Type.DIRECT), requestURI, sharedTransport, upgradeRequest)); connectionGrizzlyFuture = connectorHandler.connect(connectAddress);
@Override public FutureResult<Connection> getConnectionAsync( final ResultHandler<? super Connection> handler) { acquireTransportAndTimeoutChecker(); // Protect resources. final SocketConnectorHandler connectorHandler = TCPNIOConnectorHandler.builder(transport.get()).processor(defaultFilterChain) .build(); final AsynchronousFutureResult<Connection, ResultHandler<? super Connection>> future = new AsynchronousFutureResult<Connection, ResultHandler<? super Connection>>(handler); connectorHandler.connect(getSocketAddress(), new CompletionHandlerAdapter(future)); return future; }
protected void connectSync(SocketAddress remoteAddress, SocketAddress localAddress, CompletionHandler<Connection> completionHandler) { final FutureImpl<Connection> future = connectAsync(remoteAddress, localAddress, completionHandler, true); waitNIOFuture(future, completionHandler); }
protected static void onConnectedAsync(final TCPNIOConnection connection, final CompletionHandler<Connection> completionHandler) throws IOException { final TCPNIOTransport tcpTransport = (TCPNIOTransport) connection.getTransport(); final SocketChannel channel = (SocketChannel) connection.getChannel(); try { if (!channel.isConnected()) { channel.finishConnect(); } connection.resetProperties(); // Deregister OP_CONNECT interest connection.disableIOEvent(IOEvent.CLIENT_CONNECTED); // we can call configure for ready channel tcpTransport.getChannelConfigurator().postConfigure(tcpTransport, channel); } catch (Exception e) { abortConnection(connection, completionHandler, e); throw Exceptions.makeIOException(e); } if (connection.notifyReady()) { tcpTransport.fireIOEvent(IOEvent.CONNECTED, connection, new EnableReadHandler(completionHandler)); } }
preConfigure(finalConnection); finalConnection.setProcessor(getProcessor()); finalConnection.setProcessorSelector(getProcessorSelector()); futureToReturn = makeCancellableFuture(finalConnection);
public TCPNIOConnectorHandler build() { TCPNIOConnectorHandler handler = (TCPNIOConnectorHandler) super.build(); if (reuseAddress != null) { handler.setReuseAddress(reuseAddress); } if (timeout != null) { handler.setSyncConnectTimeout(timeout, timeoutTimeunit); } return handler; }
@Override public void connect(final SocketAddress remoteAddress, final SocketAddress localAddress, final CompletionHandler<Connection> completionHandler) { if (!transport.isBlocking()) { connectAsync(remoteAddress, localAddress, completionHandler, false); } else { connectSync(remoteAddress, localAddress, completionHandler); } }