本文整理汇总了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;
}
示例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);
}
}
示例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());
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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) {}
}
}
示例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());
}