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


Java AsynchronousSocketChannel.setOption方法代码示例

本文整理汇总了Java中java.nio.channels.AsynchronousSocketChannel.setOption方法的典型用法代码示例。如果您正苦于以下问题:Java AsynchronousSocketChannel.setOption方法的具体用法?Java AsynchronousSocketChannel.setOption怎么用?Java AsynchronousSocketChannel.setOption使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.channels.AsynchronousSocketChannel的用法示例。


在下文中一共展示了AsynchronousSocketChannel.setOption方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleNewConnection

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
/**
   * Creates a new client and adds it to the list of connections.
   * Sets the clients handler to the initial state of NameReader
   *
   * @param channel the newly accepted channel
   */
private void handleNewConnection(AsynchronousSocketChannel channel) {
	try {
		channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
	} catch (IOException e) {
		// ignore
		//
		e.printStackTrace();
	}

	//new dealer and channel
	AioServerDataDealer dealer = null;
	
	dealer = aioDataDealerFactory.getAioServerDataDealer();
	
	int channelId = getChannelId();
	AioServerChannel aioChannel = new AioServerChannel(channelId, channel, dealer, this);
	connections.put(channelId, aioChannel);
	
	//start channel
	aioChannel.run(null);
}
 
开发者ID:psfu,项目名称:waterwave,代码行数:28,代码来源:AioServer.java

示例2: retry

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
private void retry() {
    try {
        TimeUnit.SECONDS.sleep(1);
        if (null != this.channel && this.channel.isOpen()) {
            this.channel.close();
        }
        log.debug("连接:{}", this.socketAddress.toString());
        final AsynchronousSocketChannel asynchronousSocketChannel = AsynchronousSocketChannel.open(this.group);
        asynchronousSocketChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
        asynchronousSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
        asynchronousSocketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
        asynchronousSocketChannel.connect(this.socketAddress).get(5, TimeUnit.SECONDS);
        this.channel = new FastChannel(asynchronousSocketChannel, this.serializer, timeout);
    } catch (final Exception e) {
        retry();
    }
}
 
开发者ID:sd4324530,项目名称:fastrpc,代码行数:18,代码来源:FastRpcClient.java

示例3: testSingleConnect

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public void testSingleConnect() throws IOException, ExecutionException, InterruptedException, TimeoutException {
	AsynchronousSocketChannel serverConnectionChannel = null;
	try {
		assertNotNull(serverAddress);

		serverConnectionChannel = AsynchronousSocketChannel.open();
		serverConnectionChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
		
		// Ensure we have have returned an open connection
		assertNotNull(serverConnectionChannel);
		assertTrue("Channel is not open", serverConnectionChannel.isOpen());

		// Blocking connect
		Future<Void> future = serverConnectionChannel.connect(serverAddress);
		future.get(getTimeout(), TimeUnit.MILLISECONDS);
		
		// Ensure we are connected
		assertNotNull("Unable to get remote address", serverConnectionChannel.getRemoteAddress());
		
	} finally {
		if (serverConnectionChannel != null) {
			try {
				serverConnectionChannel.close();
			} catch (ClosedChannelException cce) {
				// That's ok
			}
			assertFalse("Channel was not closed", serverConnectionChannel.isOpen());
		}
	}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:31,代码来源:MultipleConnectFutureTest.java

示例4: openSocketChannel

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
protected AsynchronousSocketChannel openSocketChannel(
        AsynchronousChannelGroup asynchronousChannelGroup) throws IOException {
    AsynchronousSocketChannel channel =
            AsynchronousSocketChannel.open(asynchronousChannelGroup);
    channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
    channel.setOption(StandardSocketOptions.SO_REUSEADDR, false);
    channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
    return channel;
}
 
开发者ID:flownclouds,项目名称:Timo,代码行数:10,代码来源:BackendConnectionFactory.java

示例5: openSocketChannel

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
protected AsynchronousSocketChannel openSocketChannel() throws IOException {
	AsynchronousSocketChannel channel = AsynchronousSocketChannel
			.open(MycatServer.getInstance().getNextAsyncChannelGroup());
	channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
	channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
	channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);

	return channel;
}
 
开发者ID:youngor,项目名称:openclouddb,代码行数:10,代码来源:BackendConnectionFactory.java

示例6: make

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public FrontendConnection make(AsynchronousSocketChannel channel)
		throws IOException {
	channel.setOption(StandardSocketOptions.SO_RCVBUF, socketRecvBuffer);
	channel.setOption(StandardSocketOptions.SO_SNDBUF, socketSendBuffer);
	channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
	channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);

	FrontendConnection c = getConnection(channel);
	c.setPacketHeaderSize(packetHeaderSize);
	c.setMaxPacketSize(maxPacketSize);
	c.setWriteQueue(new BufferQueue(writeQueueCapcity));
	c.setIdleTimeout(idleTimeout);
	c.setCharset(charset);
	return c;
}
 
开发者ID:youngor,项目名称:openclouddb,代码行数:16,代码来源:FrontendConnectionFactory.java

示例7: onChannelCreated

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
@Override
public int onChannelCreated(AsynchronousSocketChannel channel, Object attachment) throws IOException
{
	super.onChannelCreated(channel, attachment);
	channel.setOption(StandardSocketOptions.TCP_NODELAY, true);
	return 0;
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:8,代码来源:TestEchoAio.java

示例8: onChannelCreated

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
/**
 * 连接创建且在TcpSession创建前响应一次. 可以修改一些连接的设置
 * @param channel
 * @param attachment 作为客户端建立的连接时为startClient传入的参数; 作为服务器建立的连接时为null
 * @return 返回>=0表示读缓冲区大小(每次最多读的字节数,0表示取默认值);返回<0表示断开连接,不再创建TcpSession
 */
@SuppressWarnings("static-method")
public int onChannelCreated(AsynchronousSocketChannel channel, Object attachment) throws IOException
{
	channel.setOption(StandardSocketOptions.TCP_NODELAY, false);
	channel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
	channel.setOption(StandardSocketOptions.SO_KEEPALIVE, false);
	channel.setOption(StandardSocketOptions.SO_RCVBUF, TcpSession.DEF_RECV_SOBUF_SIZE);
	channel.setOption(StandardSocketOptions.SO_SNDBUF, TcpSession.DEF_SEND_SOBUF_SIZE);
	return 0;
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:17,代码来源:TcpManager.java

示例9: testMultipleConnectSequential

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public void testMultipleConnectSequential() throws IOException, ExecutionException, InterruptedException, TimeoutException {
	assertNotNull(serverAddress);
	System.out.println("MultipleConnectFutureTest.testMultipleConnectSequential() creating " +
			numberOfConnections + " connections");
	for (int counter = 0; counter < numberOfConnections; counter++) {
		HangNotifier.ping();
		AsynchronousSocketChannel serverConnectionChannel = null;
		try {
			serverConnectionChannel = AsynchronousSocketChannel.open();
			serverConnectionChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
			
			// Ensure we have have returned an open connection
			assertNotNull(serverConnectionChannel);
			assertTrue("Channel is not open on iteration " + counter, serverConnectionChannel.isOpen());
	
			// Blocking connect
			Future<Void> future = serverConnectionChannel.connect(serverAddress);
			future.get(getTimeout(), TimeUnit.MILLISECONDS);
			
			// Ensure we are connected
			assertNotNull("Unable to get remote address on iteration " + counter, serverConnectionChannel.getRemoteAddress());
		} finally {
			if (serverConnectionChannel != null) {
				try {
					serverConnectionChannel.close();
				} catch (ClosedChannelException cce) {
					// That's ok
				} catch (IOException ioe) {
					throw ioe;
				}
				assertFalse("Channel was not closed on iteration " + counter, serverConnectionChannel.isOpen());
			}
		}
		
		// We can't hammer the server continuously, or we'll run out of resource.
		// Sleep before the test claims completion
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {}
	}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-systemtest,代码行数:42,代码来源:MultipleConnectFutureTest.java

示例10: createListener

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
/**
 * 
 * 
 * @param channelGroup
 * @return
 * @throws IOException
 * 
 * 
 *             SO_SNDBUF The size of the socket send buffer .
 *             SO_RCVBUF The size of the socket receive buffer. 
 *             SO_KEEPALIVE Keep connection alive. 
 *             SO_REUSEADDR Re-use address .
 *             TCP_NODELAY Disable the Nagle algorithm.
 * 
 * 
 */
private AsynchronousSocketChannel createListener(AsynchronousChannelGroup channelGroup) throws IOException {
	final AsynchronousSocketChannel listener = AsynchronousSocketChannel.open(channelGroup);
	//TODO
	//listener.setOption(StandardSocketOptions.TCP_NODELAY, true);
	listener.setOption(StandardSocketOptions.SO_REUSEADDR, true);
	listener.setOption(StandardSocketOptions.SO_RCVBUF, 16 * 1024);
	listener.setOption(StandardSocketOptions.SO_SNDBUF, 16 * 1024);
	return listener;
}
 
开发者ID:psfu,项目名称:waterwave,代码行数:26,代码来源:AioClient.java


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