本文整理匯總了Java中java.nio.channels.AsynchronousSocketChannel.isOpen方法的典型用法代碼示例。如果您正苦於以下問題:Java AsynchronousSocketChannel.isOpen方法的具體用法?Java AsynchronousSocketChannel.isOpen怎麽用?Java AsynchronousSocketChannel.isOpen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.channels.AsynchronousSocketChannel
的用法示例。
在下文中一共展示了AsynchronousSocketChannel.isOpen方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: failed
import java.nio.channels.AsynchronousSocketChannel; //導入方法依賴的package包/類
@Override
public void failed(Throwable ex, ConnectParam param)
{
AsynchronousSocketChannel channel = param.channel;
try
{
SocketAddress addr = (channel.isOpen() ? channel.getRemoteAddress() : null);
closeChannel(channel);
onConnectFailed(addr, ex);
}
catch(Exception e)
{
closeChannel(channel);
doException(null, e);
}
}
示例2: handleNewConnection
import java.nio.channels.AsynchronousSocketChannel; //導入方法依賴的package包/類
protected void handleNewConnection(AsynchronousSocketChannel channel, AioClientDataDealer aioClientDataDealer) {
if (!channel.isOpen()) {
//log.log(1, "handleNewConnection closed.. ");
return;
}
AioClientDataDealer dealer = null;
if (aioClientDataDealer != null) {
dealer = aioClientDataDealer;
} else {
aioDataDealerFactory.getAioClientDataDealer();
}
int channelId = getChannelId();
AioClientChannel aioChannel = new AioClientChannel(channelId, channel, dealer, this);
// connections.add(aioChannel);
aioChannel.run(null);
dealer.clientOnConnect(aioChannel);
// String w = "GET / HTTP/1.1 \n\n";
// ByteBuffer buffer = ByteBuffer.wrap(w.getBytes());
// System.out.println("set write ");
// channel.write(buffer, buffer, new CompletionHandler<Integer, ByteBuffer>() {
// @Override
// public void completed(Integer result, ByteBuffer buffer) {
// if (buffer.hasRemaining()) {
// System.out.println("write... ");
// channel.write(buffer, buffer, this);
// } else {
// // Go back and check if there is new data to write
// // writeFromQueue();
// System.out.println("write complete " + result);
// }
// }
//
// @Override
// public void failed(Throwable exc, ByteBuffer attachment) {
// }
// });
}
示例3: checkBeforeIO
import java.nio.channels.AsynchronousSocketChannel; //導入方法依賴的package包/類
public static <SessionContext, P extends Packet, R> boolean checkBeforeIO(ChannelContext<SessionContext, P, R> channelContext)
{
if (channelContext == null)
{
log.error("channelContext = null, {}", ThreadUtils.stackTrace());
return false;
}
boolean isClosed = channelContext.isClosed();
boolean isRemoved = channelContext.isRemoved();
AsynchronousSocketChannel asynchronousSocketChannel = channelContext.getAsynchronousSocketChannel();
Boolean isopen = null;
if (asynchronousSocketChannel != null)
{
isopen = asynchronousSocketChannel.isOpen();
if (isClosed || isRemoved)
{
if (isopen)
{
try
{
Aio.close(channelContext, "asynchronousSocketChannel is open, but channelContext isClosed: " + isClosed + ", isRemoved: " + isRemoved);
} catch (Exception e)
{
log.error(e.toString(), e);
}
}
log.error("{}, isopen:{}, isClosed:{}, isRemoved:{}, {} ", channelContext, isopen, channelContext.isClosed(), channelContext.isRemoved(), ThreadUtils.stackTrace());
return false;
}
} else
{
log.error("{}, asynchronousSocketChannel is null, isClosed:{}, isRemoved:{}, {} ", channelContext, channelContext.isClosed(), channelContext.isRemoved(),
ThreadUtils.stackTrace());
return false;
}
if (!isopen)
{
log.error("{}, isopen:{}, isClosed:{}, isRemoved:{}, {} ", channelContext, isopen, channelContext.isClosed(), channelContext.isRemoved(), ThreadUtils.stackTrace());
Aio.close(channelContext, "asynchronousSocketChannel is not open");
return false;
}
return true;
}