/** * Helper method that checks whether the newSocket completes a two-port * connection or not. If yes, the {@link ActiveConnection} object is created and * returned. */ private ActiveConnection acceptConnection(AcceptedSocket newSocket) throws LLPException, IOException { ActiveConnection conn = null; if (newSocket != null) { String address = newSocket.socket.getInetAddress().getHostAddress(); AcceptedSocket otherSocket = waitingForSecondSocket.remove(address); if (otherSocket != null && otherSocket.origin != newSocket.origin) { log.debug("Socket {} completes a two-port connection", newSocket.socket); Socket in = getInboundSocket(newSocket, otherSocket); Socket out = getOutboundSocket(newSocket, otherSocket); conn = new ActiveConnection(getParser(), getLlp(), in, out, getExecutorService()); } else { log.debug( "Registered {} Still waiting for second socket for two-port connection", newSocket.socket); waitingForSecondSocket.put(address, newSocket); } } return conn; }
/** * Helper method that checks whether the newSocket completes a two-port * connection or not. If yes, the {@link ActiveConnection} object is created and * returned. */ private ActiveConnection acceptConnection(AcceptedSocket newSocket) throws LLPException, IOException { ActiveConnection conn = null; if (newSocket != null) { String address = newSocket.socket.getInetAddress().getHostAddress(); AcceptedSocket otherSocket = waitingForSecondSocket.remove(address); if (otherSocket != null && otherSocket.origin != newSocket.origin) { log.debug("Socket {} completes a two-port connection", newSocket.socket); Socket in = getInboundSocket(newSocket, otherSocket); Socket out = getOutboundSocket(newSocket, otherSocket); conn = new ActiveConnection(getParser(), getLlp(), in, out, getExecutorService()); } else { log.debug( "Registered {} Still waiting for second socket for two-port connection", newSocket.socket); waitingForSecondSocket.put(address, newSocket); } } return conn; }
/** * Loop that waits for a connection and starts a ConnectionManager when it * gets one. */ @Override protected void handle() { if (acceptor.getServiceExitedWithException() != null) { setServiceExitedWithException(acceptor.getServiceExitedWithException()); } try { // Wait some period of time for connections AcceptedSocket newSocket = queue.poll(500, TimeUnit.MILLISECONDS); if (newSocket != null) { log.info("Accepted connection from {}:{} on local port {}", new Object[] { newSocket.socket.getInetAddress().getHostAddress(), newSocket.socket.getPort(), port }); ActiveConnection c = new ActiveConnection(getParser(), getLlp(), newSocket.socket, getExecutorService()); newConnection(c); } } catch (InterruptedException ie) { // just timed out } catch (Exception e) { log.error("Error while accepting connections: ", e); } }
/** * Loop that waits for a connection and starts a ConnectionManager when it * gets one. */ @Override protected void handle() { if (acceptor.getServiceExitedWithException() != null) { setServiceExitedWithException(acceptor.getServiceExitedWithException()); } try { // Wait some period of time for connections AcceptedSocket newSocket = queue.poll(500, TimeUnit.MILLISECONDS); if (newSocket != null) { log.info("Accepted connection from {}:{} on local port {}", new Object[] { newSocket.socket.getInetAddress().getHostAddress(), newSocket.socket.getPort(), port }); ActiveConnection c = new ActiveConnection(getParser(), getLlp(), newSocket.socket, getExecutorService()); newConnection(c); } } catch (InterruptedException ie) { // just timed out } catch (Exception e) { log.error("Error while accepting connections: ", e); } }
Connection connection = new ActiveConnection(parser, llp, new Socket( host, port)); final Initiator initiator = connection.getInitiator();
Connection connection = new ActiveConnection(parser, llp, new Socket( host, port)); final Initiator initiator = connection.getInitiator();
public static Connection openEagerly(ConnectionData connectionData, ExecutorService executorService) throws Exception { Connection connection; if (connectionData.getPort2() == 0) { connection = new ActiveConnection(connectionData.getParser(), connectionData.getProtocol(), createSocket(connectionData.getSocketFactory(), connectionData.getHost(), connectionData.getPort(), connectionData.isTls()), executorService); } else { Socket outbound = createSocket(connectionData.getSocketFactory(), connectionData.getHost(), connectionData.getPort(), connectionData.isTls()); Socket inbound = createSocket(connectionData.getSocketFactory(), connectionData.getHost(), connectionData.getPort2(), connectionData.isTls()); connection = new ActiveConnection(connectionData.getParser(), connectionData.getProtocol(), inbound, outbound, executorService); } connection.activate(); return connection; }
public static Connection openEagerly(ConnectionData connectionData, ExecutorService executorService) throws Exception { Connection connection; if (connectionData.getPort2() == 0) { connection = new ActiveConnection(connectionData.getParser(), connectionData.getProtocol(), createSocket(connectionData.getSocketFactory(), connectionData.getHost(), connectionData.getPort(), connectionData.isTls()), executorService); } else { Socket outbound = createSocket(connectionData.getSocketFactory(), connectionData.getHost(), connectionData.getPort(), connectionData.isTls()); Socket inbound = createSocket(connectionData.getSocketFactory(), connectionData.getHost(), connectionData.getPort2(), connectionData.isTls()); connection = new ActiveConnection(connectionData.getParser(), connectionData.getProtocol(), inbound, outbound, executorService); } connection.activate(); return connection; }