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


Java AsynchronousSocketChannel.connect方法代码示例

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


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

示例1: make

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public MySQLConnection make(MySQLDataSource pool, ResponseHandler handler)
		throws IOException {

	DBHostConfig dsc = pool.getConfig();
	AsynchronousSocketChannel channel = openSocketChannel();
	MySQLConnection c = new MySQLConnection(channel, pool.isReadNode());

	c.setHost(dsc.getIp());
	c.setPort(dsc.getPort());
	c.setUser(dsc.getUser());
	c.setPassword(dsc.getPassword());
	// c.setSchema(dsc.getDatabase());
	c.setHandler(new MySQLConnectionAuthenticator(c, handler));
	c.setPool(pool);
	c.setIdleTimeout(pool.getConfig().getIdleTimeout());
	channel.connect(new InetSocketAddress(dsc.getIp(), dsc.getPort()), c,
			MycatServer.getInstance().getConnector());
	return c;
}
 
开发者ID:youngor,项目名称:openclouddb,代码行数:20,代码来源:MySQLConnectionFactory.java

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

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

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public AsynchronousSocketChannel connect(SocketAddress remote, AioClientDataDealer aioClientDataDealer) throws IOException {
	AsynchronousSocketChannel listener = createListener(channelGroup);
	//log.log(1, "client start connect");

	AcceptHandler acceptHandler = new AcceptHandler(listener, aioClientDataDealer);

	listener.connect(remote, null, acceptHandler);
	return listener;
}
 
开发者ID:psfu,项目名称:waterwave,代码行数:10,代码来源:AioClient.java

示例5: main

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
        AsynchronousSocketChannel sc = AsynchronousSocketChannel.open();
        System.out.println(sc.getClass());
        Future connected = sc.connect(new InetSocketAddress("localhost", 9999));
// later ensure we are connected.
        connected.get();

        ByteBuffer bb = ByteBuffer.allocateDirect(4096);
// populate bb
        Future<Integer> writeFuture = sc.write(bb);
    }
 
开发者ID:lifey,项目名称:compfut,代码行数:12,代码来源:AsyncChannel.java

示例6: make

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public MySQLDetector make(MySQLHeartbeat heartbeat) throws IOException {
    DBHostConfig dsc = heartbeat.getSource().getConfig();
    AsynchronousSocketChannel channel = openSocketChannel();
    MySQLDetector detector = new MySQLDetector(channel);
    detector.setHost(dsc.getIp());
    detector.setPort(dsc.getPort());
    detector.setUser(dsc.getUser());
    detector.setPassword(dsc.getPassword());
    //detector.setSchema(dsc.getDatabase());
    detector.setHeartbeatTimeout(heartbeat.getHeartbeatTimeout());
    detector.setHeartbeat(heartbeat);
    channel.connect(new InetSocketAddress(dsc.getIp(), dsc.getPort()),detector,MycatServer.getInstance().getConnector());
   return detector;
}
 
开发者ID:youngor,项目名称:openclouddb,代码行数:15,代码来源:MySQLDetectorFactory.java

示例7: make

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public MyCATDetector make(MyCATHeartbeat heartbeat) throws IOException {
	
    MycatNodeConfig cnc = heartbeat.getNode().getConfig();
    SystemConfig sys = MycatServer.getInstance().getConfig().getSystem();
    AsynchronousSocketChannel channel = openSocketChannel();
    MyCATDetector detector = new MyCATDetector(channel);
    detector.setHost(cnc.getHost());
    detector.setPort(cnc.getPort());
    detector.setUser(sys.getClusterHeartbeatUser());
    detector.setPassword(sys.getClusterHeartbeatPass());
    detector.setHeartbeatTimeout(sys.getClusterHeartbeatTimeout());
    detector.setHeartbeat(heartbeat);
    channel.connect(new InetSocketAddress(cnc.getHost(), cnc.getPort()),detector,MycatServer.getInstance().getConnector());
    return detector;
}
 
开发者ID:youngor,项目名称:openclouddb,代码行数:16,代码来源:MyCATDetectorFactory.java

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

示例9: scan

import java.nio.channels.AsynchronousSocketChannel; //导入方法依赖的package包/类
public <A> void scan(InputStream inputStream, A attachment, ClamAVAsyncCallback<A> callback) throws IOException {
    AsynchronousSocketChannel asynchronousSocketChannel = AsynchronousSocketChannel.open(this.asynchronousChannelGroup);
    asynchronousSocketChannel.connect(this.address, new ClamAVAsyncObject(inputStream, attachment, callback, asynchronousSocketChannel), new ClamAVAsyncObjectCompletionHandlerConnect());
}
 
开发者ID:yongtang,项目名称:clamav4j,代码行数:5,代码来源:ClamAVAsync.java


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