当前位置: 首页>>代码示例>>Java>>正文


Java AsynchronousSocketChannel.isOpen方法代码示例

本文整理汇总了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);
	}
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:17,代码来源:TcpManager.java

示例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) {
	// }
	// });

}
 
开发者ID:psfu,项目名称:waterwave,代码行数:44,代码来源:AioClient.java

示例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;
}
 
开发者ID:tywo45,项目名称:talent-aio,代码行数:48,代码来源:AioUtils.java


注:本文中的java.nio.channels.AsynchronousSocketChannel.isOpen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。