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