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