本文整理汇总了Java中java.nio.channels.AsynchronousServerSocketChannel.open方法的典型用法代码示例。如果您正苦于以下问题:Java AsynchronousServerSocketChannel.open方法的具体用法?Java AsynchronousServerSocketChannel.open怎么用?Java AsynchronousServerSocketChannel.open使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.channels.AsynchronousServerSocketChannel
的用法示例。
在下文中一共展示了AsynchronousServerSocketChannel.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listen
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
@Override
public void listen(int thread, int port, AioServerListener listener) {
this.port = port;
this.listener = listener;
try {
channelGroup = AsynchronousChannelGroup.withFixedThreadPool(thread, Executors.defaultThreadFactory());
serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverSocketChannel.bind(new InetSocketAddress(port));
serverSocketChannel.accept(null, this);
if (logger.isInfoEnable())
logger.info("启动AIO监听[{}]服务。", port);
} catch (IOException e) {
logger.warn(e, "启动AIO监听[{}]服务时发生异常!", port);
}
}
示例2: listen
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
@Override
protected void listen(int backlog) throws IOException {
AsynchronousServerSocketChannel channel = AsynchronousServerSocketChannel.open();
try {
if (localAddress != null) {
channel.bind(new InetSocketAddress(localAddress, localport), backlog);
localport = ((InetSocketAddress) channel.getLocalAddress()).getPort();
}
} catch (IOException e) {
try {
channel.close();
} catch (IOException suppressed) {
e.addSuppressed(suppressed);
}
throw e;
}
this.channel = channel;
}
示例3: startServer
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public synchronized void startServer(SocketAddress addr, Object attachment, AsynchronousChannelGroup group)
{
stopServer();
try
{
_acceptor = AsynchronousServerSocketChannel.open(group);
int backlog = onAcceptorCreated(_acceptor, attachment);
if(backlog >= 0)
{
_acceptor.bind(addr, backlog);
beginAccept();
return;
}
}
catch(Throwable e)
{
doException(null, e);
}
stopServer();
}
示例4: run
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
@Override
public void run() {
try {
final int workerThreads = Math.max(4, 2 *
Runtime.getRuntime().availableProcessors());
channelGroup = AsynchronousChannelGroup.withFixedThreadPool(
workerThreads, Executors.defaultThreadFactory());
serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
serverSocketChannel.bind(new InetSocketAddress(port));
serverSocketChannel.accept(null,
new AcceptCompletionHandler(serverSocketChannel));
channelGroup.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
} catch(IOException | InterruptedException ex) {
Log.get().log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
示例5: start
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
@Override
public void start() throws IOException, InterruptedException {
if (running.compareAndSet(false, true)) {
final CountDownLatch latch = new CountDownLatch(1);
final AsynchronousServerSocketChannel ssc = AsynchronousServerSocketChannel.open();
ssc.bind(new InetSocketAddress(port));
ssc.accept(this, new AcceptHandler());
connectionLatch = latch;
serverSocketChannel = ssc;
}
}
示例6: AIOAcceptor
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public AIOAcceptor(String name, String ip, int port,
FrontendConnectionFactory factory, AsynchronousChannelGroup group)
throws IOException {
this.name = name;
this.port = port;
this.factory = factory;
serverChannel = AsynchronousServerSocketChannel.open(group);
/** 设置TCP属性 */
serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverChannel.setOption(StandardSocketOptions.SO_RCVBUF, 1024 * 16 * 2);
// backlog=100
serverChannel.bind(new InetSocketAddress(ip, port), 100);
}
示例7: AsyncTimeServerHandler
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public AsyncTimeServerHandler(int port){
this.port = port;
try{
//创建AsyncTimeServerHandler并启动服务端Socket
asynchronousServerSocketChannel = AsynchronousServerSocketChannel.open();
asynchronousServerSocketChannel.bind(new InetSocketAddress(this.port));
System.out.println("服务器已启动, 端口号: " + port);
}catch(Exception e){
e.printStackTrace();
}
}
示例8: AsyncServerHandler
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public AsyncServerHandler(int port) {
try {
// 创建服务端通道
channel = AsynchronousServerSocketChannel.open();
// 绑定端口
channel.bind(new InetSocketAddress(port));
System.out.println("服务器已启动,端口号:" + port);
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: start
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public void start(String serverIp, int serverPort) throws IOException
{
this.serverNode = new Node(serverIp, serverPort);
ExecutorService groupExecutor = serverGroupContext.getGroupExecutor();
AsynchronousChannelGroup channelGroup = AsynchronousChannelGroup.withThreadPool(groupExecutor);
serverSocketChannel = AsynchronousServerSocketChannel.open(channelGroup);
serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverSocketChannel.setOption(StandardSocketOptions.SO_RCVBUF, 64 * 1024);
InetSocketAddress listenAddress = null;
if (StringUtils.isBlank(serverIp))
{
listenAddress = new InetSocketAddress(serverPort);
} else
{
listenAddress = new InetSocketAddress(serverIp, serverPort);
}
serverSocketChannel.bind(listenAddress, 0);
AcceptCompletionHandler<SessionContext, P, R> acceptCompletionHandler = serverGroupContext.getAcceptCompletionHandler();
serverSocketChannel.accept(this, acceptCompletionHandler);
System.out.println("start server on " + this.serverNode);
}
示例10: AsyncServerHandler
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public AsyncServerHandler(int port) {
try {
//创建服务端通道
channel = AsynchronousServerSocketChannel.open();
//绑定端口
channel.bind(new InetSocketAddress(port));
System.out.println("服务器已启动,端口号:" + port);
} catch (IOException e) {
e.printStackTrace();
}
}
示例11: AsyncTimeServerHandler
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public AsyncTimeServerHandler(int port) {
this.port = port;
try {
asynchronousServerSocketChannel = AsynchronousServerSocketChannel
.open();
asynchronousServerSocketChannel.bind(new InetSocketAddress(port));
System.out.println("The time server is start in port : " + port);
} catch (IOException e) {
e.printStackTrace();
}
}
示例12: AsyncTimeServerHandler
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public AsyncTimeServerHandler(int port) {
this.port = port;
try {
asynchronousServerSocketChannel = AsynchronousServerSocketChannel
.open();
asynchronousServerSocketChannel.bind(new InetSocketAddress(port));
System.out.println("The time server is start in port : " + port);
} catch (IOException e) {
e.printStackTrace();
}
}
示例13: start
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public void start() throws IOException {
int initialSize = Runtime.getRuntime().availableProcessors();
AsynchronousChannelGroup channelGroup = AsynchronousChannelGroup
.withCachedThreadPool(Executors.newCachedThreadPool(),
initialSize);
AsynchronousServerSocketChannel server = AsynchronousServerSocketChannel
.open(channelGroup);
server.bind(new InetSocketAddress(port));
this.pendingAccept();
logger.debug("server started at port " + this.port);
}
示例14: NIOAcceptor
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public NIOAcceptor(String name, String ip, int port,
FrontendConnectionFactory factory, AsynchronousChannelGroup group)
throws IOException {
this.name = name;
this.port = port;
this.factory = factory;
serverChannel = AsynchronousServerSocketChannel.open(group);
/** 设置TCP属性 */
serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverChannel.setOption(StandardSocketOptions.SO_RCVBUF, 16 * 1024);
// backlog=100
serverChannel.bind(new InetSocketAddress(ip, port), 100);
}
示例15: NIOAcceptor
import java.nio.channels.AsynchronousServerSocketChannel; //导入方法依赖的package包/类
public NIOAcceptor(String name, String ip,int port,
FrontendConnectionFactory factory, AsynchronousChannelGroup group)
throws IOException {
this.name=name;
this.port = port;
this.factory = factory;
serverChannel = AsynchronousServerSocketChannel.open(group);
/** 设置TCP属性 */
serverChannel.setOption(StandardSocketOptions.SO_REUSEADDR, true);
serverChannel.setOption(StandardSocketOptions.SO_RCVBUF, 16 * 1024);
// backlog=100
serverChannel.bind(new InetSocketAddress(ip,port), 100);
}