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


Java NioSocketAcceptor.getSessionConfig方法代码示例

本文整理汇总了Java中org.apache.mina.transport.socket.nio.NioSocketAcceptor.getSessionConfig方法的典型用法代码示例。如果您正苦于以下问题:Java NioSocketAcceptor.getSessionConfig方法的具体用法?Java NioSocketAcceptor.getSessionConfig怎么用?Java NioSocketAcceptor.getSessionConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.transport.socket.nio.NioSocketAcceptor的用法示例。


在下文中一共展示了NioSocketAcceptor.getSessionConfig方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SocketServer

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public SocketServer(int port,  int threadPoolSize) {
		NioSocketAcceptor acceptor = new NioSocketAcceptor();
		acceptor.setHandler(new ServerHandler());
//		acceptor.getFilterChain().addLast("mychian",new ProtocolCodecFilter(new TextLineCodecFactory()));
//		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
		acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(threadPoolSize)));
		SocketSessionConfig ssc = acceptor.getSessionConfig();// 建立连接的配置文件
		ssc.setReadBufferSize(4096);// 设置接收最大字节默认4096
		ssc.setReceiveBufferSize(10240);// 设置输入缓冲区的大小
		ssc.setSendBufferSize(10240);// 设置输出缓冲区的大小
		ssc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
		
		try {
			// 绑定端口
			acceptor.bind(new InetSocketAddress(port));
			System.out.println("服务器启动正常,监听端口 " + port);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:21,代码来源:SocketServer.java

示例2: serverStart

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
@Override
protected void serverStart() throws RemotingException {

    acceptor = new NioSocketAcceptor(); //TCP Acceptor

    // acceptor.getFilterChain().addFirst("logging", new MinaLoggingFilter());
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecFactory(getCodec())));
    acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());

    acceptor.setHandler(new MinaHandler(this));
    IoSessionConfig cfg = acceptor.getSessionConfig();
    cfg.setReaderIdleTime(remotingServerConfig.getReaderIdleTimeSeconds());
    cfg.setWriterIdleTime(remotingServerConfig.getWriterIdleTimeSeconds());
    cfg.setBothIdleTime(remotingServerConfig.getServerChannelMaxIdleTimeSeconds());

    bindAddress = new InetSocketAddress(remotingServerConfig.getListenPort());
    try {
        acceptor.bind(bindAddress);
    } catch (IOException e) {
        throw new RemotingException("Start Mina server error", e);
    }
}
 
开发者ID:WenZuHuai,项目名称:light-task-scheduler,代码行数:23,代码来源:MinaRemotingServer.java

示例3: main

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) {
	int port = U.getInt("cleaner.server.port");
	int idleTime = U.getInt("cleaner.server.time");
	NioSocketAcceptor clientAcceptor = new NioSocketAcceptor();
	clientAcceptor.setReuseAddress(true);

	DefaultIoFilterChainBuilder chain = clientAcceptor.getFilterChain();
	SocketSessionConfig config = clientAcceptor.getSessionConfig();
	config.setIdleTime(IdleStatus.READER_IDLE, idleTime);// 读空闲 10秒
	config.setReuseAddress(true);
	config.setReadBufferSize(4096);// 默认2048
	config.setKeepAlive(true);
	config.setTcpNoDelay(true);// 开启nagle算法
	// 编解码
	chain.addLast("coder", new ProtocolCodecFilter(new TextLineCodecFactory(U.UTF8)));
	clientAcceptor.setHandler(new CleanerHandler());
	try {
		clientAcceptor.bind(new InetSocketAddress(port));
		log.info("心跳模块启动..");
	} catch (IOException e) {
		log.error("心跳模块启动失败", e);
	}
}
 
开发者ID:East196,项目名称:maker,代码行数:24,代码来源:BeatServer.java

示例4: initialize

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public void initialize() {
	idleTime = U.getInt("chat.server.idleTime");
	System.out.println(idleTime);

	clientAcceptor = new NioSocketAcceptor();
	clientAcceptor.setReuseAddress(true);

	DefaultIoFilterChainBuilder chain = clientAcceptor.getFilterChain();
	SocketSessionConfig config = clientAcceptor.getSessionConfig();
	config.setReuseAddress(true);
	config.setIdleTime(IdleStatus.READER_IDLE, idleTime);// 读空闲 20秒
	config.setReadBufferSize(4096);// 默认2048
	config.setKeepAlive(true);
	config.setTcpNoDelay(true);// 禁用/开启nagle算法
	// 编解码
	chain.addLast("coder", new ProtocolCodecFilter(new MessageCodecFactory()));
	// 日志
	chain.addLast("logger", new LoggingFilter());
	// 业务逻辑处理线程池
	chain.addLast("threadPool", new ExecutorFilter());
}
 
开发者ID:East196,项目名称:maker,代码行数:22,代码来源:TcpServer.java

示例5: startListner

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public  void startListner(IoHandler iohandler,int listenPort) throws Exception{
	acceptor = new NioSocketAcceptor();
	acceptor.setBacklog(100);
	acceptor.setReuseAddress(true);
	acceptor.setHandler(iohandler);
	
       DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
       IoFilter protocol = new ProtocolCodecFilter(new GameProtocolcodecFactory());
       chain.addLast("codec", protocol);
	threadpool = new OrderedThreadPoolExecutor(500);
	threadpool.setThreadFactory(new ServerThreadFactory("OrderedThreadPool"));
	chain.addLast("threadPool", new ExecutorFilter(threadpool));
	
	int recsize = 5120;
	int sendsize = 40480;                                                                                         
	int timeout = 10;
	SocketSessionConfig sc = acceptor.getSessionConfig();
	sc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
	sc.setReceiveBufferSize(recsize);// 设置输入缓冲区的大小
	sc.setSendBufferSize(sendsize);// 设置输出缓冲区的大小
	sc.setTcpNoDelay(true);// flush函数的调用 设置为非延迟发送,为true则不组装成大包发送,收到东西马上发出   
	sc.setSoLinger(0);
	sc.setIdleTime(IdleStatus.READER_IDLE, timeout);
	acceptor.bind(new InetSocketAddress(listenPort));
}
 
开发者ID:yongzhidai,项目名称:GameServer,代码行数:26,代码来源:NetManager.java

示例6: main

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("protocol", new ProtocolCodecFilter(new WebSocketCodecFactory()));
    // close sessions when the acceptor is stopped
    acceptor.setCloseOnDeactivation(true);
    acceptor.setHandler(new WebSocketHandler());
    SocketSessionConfig sessionConf = acceptor.getSessionConfig();
    sessionConf.setReuseAddress(true);
    acceptor.setReuseAddress(true);
    // loop through the addresses and bind
    Set<InetSocketAddress> socketAddresses = new HashSet<InetSocketAddress>();
    socketAddresses.add(new InetSocketAddress("0.0.0.0", 8888));
    //socketAddresses.add(new InetSocketAddress("localhost", 8888));
    log.debug("Binding to {}", socketAddresses.toString());
    acceptor.bind(socketAddresses);
    System.out.println("WS server started listening");
    listening = true;
    while (true) {
        try {
            Thread.sleep(2000L);
        } catch (InterruptedException e) {
            System.out.println("WS server stopped listening");
        }
    }
}
 
开发者ID:Red5,项目名称:red5-websocket,代码行数:26,代码来源:WebSocketServerTest.java

示例7: initService

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
private void initService() throws Exception
  {
      IoBuffer.setUseDirectBuffer(false);

      acceptor = new NioSocketAcceptor(
      		Runtime.getRuntime().availableProcessors() + 1);
      config = acceptor.getSessionConfig();
      config.setReuseAddress(true);
      DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();

      chain.addLast("codec", new ProtocolCodecFilter(
      		new TextLineCodecFactory(
              		MailsterConstants.DEFAULT_CHARSET, 
              		LineDelimiter.CRLF, 
              		LineDelimiter.CRLF)));

executor = Executors.newCachedThreadPool(
		ThreadFactoryUtilities.createFactory("POP3 Thread"));
chain.addLast("threadPool", new ExecutorFilter(executor));

      handler = new Pop3ProtocolHandler(userManager);
  }
 
开发者ID:edeoliveira,项目名称:Mailster,代码行数:23,代码来源:MailsterPop3Service.java

示例8: SocketServer

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
public SocketServer(int port, MessageHandler msgHandler, int threadPoolSize) {
		mServerHandler = new ServerHandler(msgHandler);

		acceptor = new NioSocketAcceptor();
		acceptor.setHandler(mServerHandler);// 设置接收器的处理程序
		acceptor.setReuseAddress(true) ;
//		acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(10)));//建立有序线程池
		acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(Runtime.getRuntime().availableProcessors()+1)));//建立有序线程池
//		acceptor.getFilterChain().addLast("exector", new ExecutorFilter(new OrderedThreadPoolExecutor(128)));//建立有序线程池
/*		Executor threadPool = Executors.newFixedThreadPool(threadPoolSize);// 建立线程池
		acceptor.getFilterChain().addLast("exector",
				new ExecutorFilter(threadPool));*/
		acceptor.getFilterChain().addLast("codec",//解码\转码
				new ProtocolCodecFilter(new MessageCodecFactory(Charset.forName("UTF-8"))));

		try {
			// 绑定端口
			acceptor.bind(new InetSocketAddress(port));
			logger.info("服务器启动正常,监听端口 " + port);
		} catch (IOException e) {
			e.printStackTrace();
		}
		SocketSessionConfig ssc = acceptor.getSessionConfig();// 建立连接的配置文件
		ssc.setReadBufferSize(4096);// 设置接收最大字节默认4096
//		ssc.setReceiveBufferSize(1024);// 设置输入缓冲区的大小
//		ssc.setSendBufferSize(1024);// 设置输出缓冲区的大小
//		ssc.setReuseAddress(true);// 设置每一个非主监听连接的端口可以重用
		ssc.setTcpNoDelay(false);
		
		
	}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:32,代码来源:SocketServer.java

示例9: buildSocketAcceptor

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
private static NioSocketAcceptor buildSocketAcceptor()
{
    // Create SocketAcceptor with correct number of processors
    final int processorCount = JiveGlobals.getIntProperty( "xmpp.processor.count", Runtime.getRuntime().availableProcessors() );

    final NioSocketAcceptor socketAcceptor = new NioSocketAcceptor( processorCount );

    // Set that it will be possible to bind a socket if there is a connection in the timeout state.
    socketAcceptor.setReuseAddress( true );

    // Set the listen backlog (queue) length. Default is 50.
    socketAcceptor.setBacklog( JiveGlobals.getIntProperty( "xmpp.socket.backlog", 50 ) );

    // Set default (low level) settings for new socket connections
    final SocketSessionConfig socketSessionConfig = socketAcceptor.getSessionConfig();

    //socketSessionConfig.setKeepAlive();
    final int receiveBuffer = JiveGlobals.getIntProperty( "xmpp.socket.buffer.receive", -1 );
    if ( receiveBuffer > 0 )
    {
        socketSessionConfig.setReceiveBufferSize( receiveBuffer );
    }

    final int sendBuffer = JiveGlobals.getIntProperty( "xmpp.socket.buffer.send", -1 );
    if ( sendBuffer > 0 )
    {
        socketSessionConfig.setSendBufferSize( sendBuffer );
    }

    final int linger = JiveGlobals.getIntProperty( "xmpp.socket.linger", -1 );
    if ( linger > 0 )
    {
        socketSessionConfig.setSoLinger( linger );
    }

    socketSessionConfig.setTcpNoDelay( JiveGlobals.getBooleanProperty( "xmpp.socket.tcp-nodelay", socketSessionConfig.isTcpNoDelay() ) );

    return socketAcceptor;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:40,代码来源:MINAConnectionAcceptor.java

示例10: bind

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //导入方法依赖的package包/类
@Override
public MinaAcceptance bind() {
    // This socket acceptor will handle incoming connections
    acceptor = new NioSocketAcceptor(transportConfig.getNioProcessorCount());
    acceptor.setReuseAddress(true);
    acceptor.setBacklog(128);

    SocketSessionConfig sessionConfig = acceptor.getSessionConfig();
    sessionConfig.setTcpNoDelay(true);

    // set read buffer size
    sessionConfig.setReceiveBufferSize(16 * 1024);
    sessionConfig.setSendBufferSize(16 * 1024);

    // get filter chain builder
    DefaultIoFilterChainBuilder chainBuilder = acceptor.getFilterChain();

    // add message codec filter
    final TransportProtocolEncoder encoder = new TransportProtocolEncoder();
    final TransportProtocolDecoder decoder = new TransportProtocolDecoder();

    encoder.setMaxObjectSize(transportConfig.getMaxSize());
    decoder.setMaxObjectSize(transportConfig.getMaxSize());
    chainBuilder.addLast("codec", new ProtocolCodecFilter(encoder, decoder));

    // add keep alive filter
    KeepAliveFilter kaFilter = new KeepAliveFilter(new PassiveKeepAliveMessageFactory(), IdleStatus.BOTH_IDLE);
    kaFilter.setRequestInterval(transportConfig.getHeartbeatIntervalSeconds());
    kaFilter.setForwardEvent(true);
    chainBuilder.addLast("keepAlive", kaFilter);

    // add business handler
    acceptor.setHandler(new MinaIoHandler());

    try {
        acceptor.bind(serviceAddress);

        int processorCount = transportConfig.getBusinessProcessorCount();
        if (processorCount > 0) {
            NamedThreadFactory threadFactory = new NamedThreadFactory("Mina-BusinssProcessor");
            executorService = Executors.newFixedThreadPool(processorCount, threadFactory);
        }
    } catch (Exception e) {
        throw new RuntimeException("can't bind service on " + serviceAddress, e);
    }
    LOG.info("mina acceptance bind on {}", serviceAddress);

    return this;
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:50,代码来源:MinaAcceptance.java


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