本文整理了Java中java.nio.channels.SocketChannel.isConnectionPending()
方法的一些代码示例,展示了SocketChannel.isConnectionPending()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SocketChannel.isConnectionPending()
方法的具体详情如下:
包路径:java.nio.channels.SocketChannel
类名称:SocketChannel
方法名:isConnectionPending
[英]Indicates whether this channel's socket is still trying to connect.
[中]指示此频道的套接字是否仍在尝试连接。
代码示例来源:origin: wildfly/wildfly
@Override
public boolean isConnectionPending() {return channel != null && channel.isConnectionPending();}
代码示例来源:origin: alibaba/cobar
public boolean finishConnect() throws IOException {
if (channel.isConnectionPending()) {
channel.finishConnect();
localPort = channel.socket().getLocalPort();
isFinishConnect = true;
return true;
} else {
return false;
}
}
代码示例来源:origin: apache/nifi
/**
* 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);
}
代码示例来源:origin: h2oai/h2o-2
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 ) {
代码示例来源:origin: rapidoid/rapidoid
@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);
}
}
代码示例来源:origin: lealone/Lealone
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();
}
}
代码示例来源:origin: io.netty/netty
!((SocketChannel) ch).isConnectionPending()) {
notConnected = true;
代码示例来源:origin: org.mobicents.protocols.ss7.management/shell-transport
/**
* 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();
}
代码示例来源:origin: org.restcomm.protocols.ss7.management/shell-transport
/**
* 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();
}
代码示例来源:origin: com.projectdarkstar.server/sgs-server
/**
* {@inheritDoc}
*/
@Override
public boolean isConnectionPending() {
return channel.isConnectionPending();
}
代码示例来源:origin: i2p/i2p.i2p
(!((SocketChannel)key.channel()).isConnectionPending()) &&
con.getTimeSinceCreated(now) > 2 * NTCPTransport.ESTABLISH_TIMEOUT) {
if (_log.shouldLog(Log.INFO))
代码示例来源:origin: brucexx/heisenberg
public boolean finishConnect() throws IOException {
if (channel.isConnectionPending()) {
channel.finishConnect();
localPort = channel.socket().getLocalPort();
isFinishConnect = true;
return true;
} else {
return false;
}
}
代码示例来源:origin: MyCATApache/Mycat-NIO
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;
}
}
代码示例来源:origin: actiontech/dble
private boolean finishConnect(AbstractConnection c, SocketChannel channel)
throws IOException {
if (channel.isConnectionPending()) {
channel.finishConnect();
c.setLocalPort(channel.socket().getLocalPort());
return true;
} else {
return false;
}
}
代码示例来源:origin: jpcsp/jpcsp
public void connect() throws IOException {
openChannel();
if (!socketChannel.isConnected() && !socketChannel.isConnectionPending()) {
SocketAddress socketAddress = new InetSocketAddress(InetAddress.getByAddress(destinationIPAddress), destinationPort);
socketChannel.connect(socketAddress);
}
}
代码示例来源:origin: twitter/whiskey
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;
}
代码示例来源:origin: Nextdoor/bender
@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"));
}
}
}
代码示例来源:origin: apache/activemq-artemis
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";
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
@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());
}
}
代码示例来源:origin: apache/activemq-artemis
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";
}
内容来源于网络,如有侵权,请联系作者删除!