@Override public boolean isConnectionPending() {return channel != null && channel.isConnectionPending();}
public boolean finishConnect() throws IOException { if (channel.isConnectionPending()) { channel.finishConnect(); localPort = channel.socket().getLocalPort(); isFinishConnect = true; return true; } else { return false; } }
/** * This will connect the channel; if it is in a pending state then this will finish * establishing the connection. Finally the socket handler is registered with this * channel. * * @throws IOException if anything goes wrong during the connection establishment * or registering of the handler */ private void connect(SelectionKey selectionKey) throws IOException { SocketChannel clientChannel = (SocketChannel) selectionKey.channel(); if (clientChannel.isConnectionPending()) { clientChannel.finishConnect(); } clientChannel.register(AbstractSocketHandler.this.selector, SelectionKey.OP_READ); }
public SocketChannel getTCPSocket() throws IOException { // Under lock, claim an existing open socket if possible synchronized(this) { // Limit myself to the number of open sockets from node-to-node while( _socksAvail == 0 ) try { wait(); } catch( InterruptedException ie ) { } // Claim an open socket SocketChannel sock = _socks[--_socksAvail]; if( sock != null ) { if( sock.isOpen() ) return sock; // Return existing socket! // Else its an already-closed socket, lower open TCP count assert TCPS.get() > 0; TCPS.decrementAndGet(); } } // Must make a fresh socket SocketChannel sock2 = SocketChannel.open(); sock2.socket().setReuseAddress(true); sock2.socket().setSendBufferSize(AutoBuffer.BBSIZE); boolean res = sock2.connect( _key ); assert res && !sock2.isConnectionPending() && sock2.isBlocking() && sock2.isConnected() && sock2.isOpen(); TCPS.incrementAndGet(); // Cluster-wide counting return sock2; } public synchronized void freeTCPSocket( SocketChannel sock ) {
@Override protected void connectOP(SelectionKey key) throws IOException { U.must(key.isConnectable()); SocketChannel socketChannel = (SocketChannel) key.channel(); if (!socketChannel.isConnectionPending()) { // not ready to retrieve the connection status return; } ConnectionTarget target = (ConnectionTarget) key.attachment(); boolean ready; try { ready = socketChannel.finishConnect(); U.must(ready, "Expected an established connection!"); Log.info("Connected", "address", target.addr); connected.add(new RapidoidChannel(socketChannel, true, target.protocol, target.holder, target.reconnecting, target.state)); } catch (ConnectException e) { retryConnecting(target); } }
private void connectionEstablished(SelectionKey key, Object att) throws Exception { SocketChannel channel = (SocketChannel) key.channel(); if (!channel.isConnectionPending()) return; Attachment attachment = (Attachment) att; AsyncConnection conn; try { channel.finishConnect(); nioEventLoopAdapter.addSocketChannel(channel); NioWritableChannel writableChannel = new NioWritableChannel(channel, this); if (attachment.connectionManager != null) { conn = attachment.connectionManager.createConnection(writableChannel, false); } else { conn = new TcpClientConnection(writableChannel, this); } conn.setInetSocketAddress(attachment.inetSocketAddress); addConnection(attachment.inetSocketAddress, conn); channel.register(nioEventLoopAdapter.getSelector(), SelectionKey.OP_READ, conn); } finally { attachment.latch.countDown(); } }
!((SocketChannel) ch).isConnectionPending()) { notConnected = true;
/** * Tells whether or not a connection operation is in progress on this channel. * * @return true if, and only if, a connection operation has been initiated on this channel but not yet completed by invoking * the finishConnect method */ public boolean isConnectionPending() { return ((SocketChannel) channel).isConnectionPending(); }
/** * Tells whether or not a connection operation is in progress on this channel. * * @return true if, and only if, a connection operation has been initiated on this channel but not yet completed by invoking * the finishConnect method */ public boolean isConnectionPending() { return ((SocketChannel) channel).isConnectionPending(); }
/** * {@inheritDoc} */ @Override public boolean isConnectionPending() { return channel.isConnectionPending(); }
(!((SocketChannel)key.channel()).isConnectionPending()) && con.getTimeSinceCreated(now) > 2 * NTCPTransport.ESTABLISH_TIMEOUT) { if (_log.shouldLog(Log.INFO))
public boolean finishConnect() throws IOException { if (channel.isConnectionPending()) { channel.finishConnect(); localPort = channel.socket().getLocalPort(); isFinishConnect = true; return true; } else { return false; } }
private boolean finishConnect(Connection c, SocketChannel channel) throws IOException { System.out.println("----------------finishConnect-----------------"); if (channel.isConnectionPending()) { System.out.println("----------------finishConnect-isConnectionPending-----------------"); channel.finishConnect(); // c.setLocalPort(channel.socket().getLocalPort()); return true; } else { return false; } }
private boolean finishConnect(AbstractConnection c, SocketChannel channel) throws IOException { if (channel.isConnectionPending()) { channel.finishConnect(); c.setLocalPort(channel.socket().getLocalPort()); return true; } else { return false; } }
public void connect() throws IOException { openChannel(); if (!socketChannel.isConnected() && !socketChannel.isConnectionPending()) { SocketAddress socketAddress = new InetSocketAddress(InetAddress.getByAddress(destinationIPAddress), destinationPort); socketChannel.connect(socketAddress); } }
private int interestSet() { if (channel.isConnectionPending()) return SelectionKey.OP_CONNECT; int interestSet = 0; if (!getReadQueue().isEmpty()) interestSet = SelectionKey.OP_READ; if (!getWriteQueue().isEmpty()) interestSet |= SelectionKey.OP_WRITE; return interestSet; }
@Override public void run() { SocketChannel channel = connect.channel; if (channel.isConnectionPending()) { if (LOG.isDebugEnabled()) LOG.debug("Channel {} timed out while connecting, closing it", channel); connect.failed(new SocketTimeoutException("Connect Timeout")); } } }
protected String status() { if(channel == null) return "n/a"; if(isConnected()) return "connected"; if(channel.isConnectionPending()) return "connection pending"; if(isOpen()) return "open"; return "closed"; }
@Override public void expired() { if (channel.isConnectionPending()) { LOG.debug("Channel {} timed out while connecting, closing it", channel); close(); _connectingChannels.remove(channel); destination.onConnectionFailed(new SocketTimeoutException()); } }
protected String status() { if(channel == null) return "n/a"; if(isConnected()) return "connected"; if(channel.isConnectionPending()) return "connection pending"; if(isOpen()) return "open"; return "closed"; }