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


Java AsynchronousSocketChannel.open方法代码示例

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


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

示例1: 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

示例2: connect

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
private void connect() throws BindException{
	String errorMessage = "";
	if (socketChannel == null || !socketChannel.isOpen() || closed) {
		try {
			socketChannel = AsynchronousSocketChannel.open();
			socketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
			socketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
			socketChannel.connect(new InetSocketAddress(ip, port)).get(timeout, TimeUnit.MILLISECONDS);
			closed = false;
			
			//when connect to the server, keep receiving data either server response or server call
			receive();
		} catch (Exception e) {
			log.error("Connection error: " + e.getMessage());
			errorMessage = e.getMessage();
		}
	}
	if (socketChannel == null) {
		throw new BindException(errorMessage);
	}
}
 
开发者ID:zijan,项目名称:Tatala-RPC,代码行数:22,代码来源:LongClientSession.java

示例3: connect

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
private void connect() throws BindException{
	String errorMessage = "";
	if (socketChannel == null || !socketChannel.isOpen() || closed) {
		try {
			socketChannel = AsynchronousSocketChannel.open();
			socketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
			socketChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
			socketChannel.connect(new InetSocketAddress(ip, port)).get(timeout, TimeUnit.MILLISECONDS);
			closed = false;
			log.debug("Session start to " + socketChannel.getRemoteAddress());
			
			//when connect to the server, keep receiving data either server response or server call
			receive();
		} catch (Exception e) {
			log.error("Connection error: " + e.getMessage());
			errorMessage = e.getMessage();
		}
	}
	if (socketChannel == null) {
		throw new BindException(errorMessage);
	}
}
 
开发者ID:zijan,项目名称:Tatala-RPC,代码行数:23,代码来源:LongClientSession.java

示例4: startClient

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
@SuppressWarnings("resource")
public void startClient(SocketAddress addr, Object attachment, AsynchronousChannelGroup group)
{
	AsynchronousSocketChannel channel = null;
	try
	{
		channel = AsynchronousSocketChannel.open(group);
		int recvBufSize = onChannelCreated(channel, attachment);
		if(recvBufSize >= 0)
			channel.connect(addr, new ConnectParam(channel, recvBufSize), _connectHandler);
		else
			channel.close();
	}
	catch(Throwable e)
	{
		doException(null, e);
		closeChannel(channel);
	}
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:20,代码来源:TcpManager.java

示例5: SocketClient

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public SocketClient(PoolManager pool_manager, InetSocketAddress server, Consumer<Node> callback_on_connection) throws IOException {
	if (pool_manager == null) {
		throw new NullPointerException("\"pool_manager\" can't to be null");
	}
	this.distant_server_addr = server;
	if (server == null) {
		throw new NullPointerException("\"server\" can't to be null");
	}
	this.callback_on_connection = callback_on_connection;
	if (callback_on_connection == null) {
		throw new NullPointerException("\"callback_on_connection\" can't to be null");
	}
	
	handler_connect = new SocketConnect();
	
	channel = AsynchronousSocketChannel.open(pool_manager.getChannelGroup());
	
	channel.connect(server, new Node(this, pool_manager, channel), handler_connect);
}
 
开发者ID:hdsdi3g,项目名称:MyDMAM,代码行数:20,代码来源:SocketClient.java

示例6: openSocketChannel

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
protected NetworkChannel openSocketChannel(boolean isAIO)
		throws IOException {
	if (isAIO) {
		return AsynchronousSocketChannel
               .open(MycatServer.getInstance().getNextAsyncChannelGroup());
	} else {
		SocketChannel channel = null;
		channel = SocketChannel.open();
		channel.configureBlocking(false);
		return channel;
	}

}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:14,代码来源:BackendConnectionFactory.java

示例7: 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

示例8: AsyncTimeClientHandler

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public AsyncTimeClientHandler(String host, int port) {
    this.port = port;
    this.host = host;
    try{
        this.asynchronousSocketChannel = AsynchronousSocketChannel.open();
    }catch(Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:SnailFastGo,项目名称:netty_op,代码行数:10,代码来源:AsyncTimeClientHandler.java

示例9: AsyncClientHandler

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public AsyncClientHandler(String host, int port) {
	this.host = host;
	this.port = port;
	try {
		// 创建异步的客户端通道
		clientChannel = AsynchronousSocketChannel.open();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
开发者ID:minilynn,项目名称:samplecode,代码行数:11,代码来源:Client.java

示例10: openSocketChannel

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
protected NetworkChannel openSocketChannel(boolean isAIO)
        throws IOException {
    if (isAIO) {
        return AsynchronousSocketChannel.open(DbleServer.getInstance().getNextAsyncChannelGroup());
    } else {
        SocketChannel channel = null;
        channel = SocketChannel.open();
        channel.configureBlocking(false);
        return channel;
    }

}
 
开发者ID:actiontech,项目名称:dble,代码行数:13,代码来源:BackendConnectionFactory.java

示例11: connect

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
@Override
public void connect(String host, int port, AioClientListener listener) {
    this.host = host;
    this.port = port;
    this.listener = listener;
    try {
        socketChannel = AsynchronousSocketChannel.open();
        socketChannel.connect(new InetSocketAddress(host, port), null, this);
    } catch (IOException e) {
        logger.warn(e, "连接到服务端[{}:{}]时发生异常!", host, port);
    }
}
 
开发者ID:heisedebaise,项目名称:tephra,代码行数:13,代码来源:AioClientImpl.java

示例12: ready

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
void ready() {
    try {
        channel = AsynchronousSocketChannel.open();
        channel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
        Future<Void> future = channel.connect(remote.getAddress());
        if (future.get() != null) {
            log.log(Level.WARNING, "Can't connect to {0}", remote);
        } else {
            log.log(Level.INFO, "Connected to server {0}", remote);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:archerfeel,项目名称:awacs,代码行数:15,代码来源:Connection.java

示例13: AsyncClientHandler

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public AsyncClientHandler(String host, int port) {
    this.host = host;
    this.port = port;
    try {
        //创建异步的客户端通道
        clientChannel = AsynchronousSocketChannel.open();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:xuxueli,项目名称:xxl-incubator,代码行数:11,代码来源:AsyncClientHandler.java

示例14: AsyncTimeClientHandler

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public AsyncTimeClientHandler(String host, int port) {
this.host = host;
this.port = port;
try {
    client = AsynchronousSocketChannel.open();
} catch (IOException e) {
    e.printStackTrace();
}
   }
 
开发者ID:changyuefeng,项目名称:netty-book,代码行数:10,代码来源:AsyncTimeClientHandler.java

示例15: 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


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