當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。