本文整理汇总了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;
}