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


Java AsynchronousServerSocketChannel.open方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:heisedebaise,项目名称:tephra,代码行数:18,代码来源:AioServerImpl.java

示例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;
}
 
开发者ID:yngui,项目名称:jephyr,代码行数:19,代码来源:NioSocketImpl.java

示例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();
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:21,代码来源:TcpManager.java

示例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);
    }
}
 
开发者ID:cli,项目名称:sonews,代码行数:20,代码来源:AsynchronousNNTPDaemon.java

示例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;
    }
}
 
开发者ID:altiplanogao,项目名称:io-comparison,代码行数:15,代码来源:AioServer.java

示例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);
}
 
开发者ID:huang-up,项目名称:mycat-src-1.6.1-RELEASE,代码行数:14,代码来源:AIOAcceptor.java

示例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();
    }
}
 
开发者ID:SnailFastGo,项目名称:netty_op,代码行数:12,代码来源:AsyncTimeServerHandler.java

示例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();
	}
}
 
开发者ID:minilynn,项目名称:samplecode,代码行数:12,代码来源:Server.java

示例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);
}
 
开发者ID:tywo45,项目名称:talent-aio,代码行数:29,代码来源:AioServer.java

示例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();
    }
}
 
开发者ID:xuxueli,项目名称:xxl-incubator,代码行数:12,代码来源:AsyncServerHandler.java

示例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();
}
   }
 
开发者ID:changyuefeng,项目名称:netty-book,代码行数:12,代码来源:AsyncTimeServerHandler.java

示例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();
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:12,代码来源:AsyncTimeServerHandler.java

示例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);
}
 
开发者ID:trnnn,项目名称:EasySocket,代码行数:13,代码来源:SocketServer.java

示例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);
}
 
开发者ID:youngor,项目名称:openclouddb,代码行数:14,代码来源:NIOAcceptor.java

示例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);
}
 
开发者ID:youngor,项目名称:openclouddb,代码行数:14,代码来源:NIOAcceptor.java


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