當前位置: 首頁>>代碼示例>>Java>>正文


Java NioSocketAcceptor.setBacklog方法代碼示例

本文整理匯總了Java中org.apache.mina.transport.socket.nio.NioSocketAcceptor.setBacklog方法的典型用法代碼示例。如果您正苦於以下問題:Java NioSocketAcceptor.setBacklog方法的具體用法?Java NioSocketAcceptor.setBacklog怎麽用?Java NioSocketAcceptor.setBacklog使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.mina.transport.socket.nio.NioSocketAcceptor的用法示例。


在下文中一共展示了NioSocketAcceptor.setBacklog方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //導入方法依賴的package包/類
private void init(Config config) {
    address = new InetSocketAddress(config.sourcePort);
    acceptor = new NioSocketAcceptor();
    if (acceptor.getFilterChain().get(LOGGER) == null) {
        acceptor.getFilterChain().addLast(LOGGER, new LoggingFilter());
    }
    if (acceptor.getFilterChain().get(CODEC) == null) {
        ProtocolCodecFactory codecFactory = config.codec == null ?
                MinaUtil.getTextLineCodecFactory() : (ProtocolCodecFactory) config.codec;
        acceptor.getFilterChain().addLast(CODEC, new ProtocolCodecFilter(codecFactory));
    }
    acceptor.setHandler(new MinaServerHandler());
    acceptor.getSessionConfig().setReadBufferSize(config.bufferSize);
    acceptor.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
    acceptor.setReuseAddress(true); //避免重啟時提示地址被占用
    //設置主服務監聽端口的監聽隊列的最大值為50,如果當前已經有50個連接,新的連接將被服務器拒絕
    acceptor.setBacklog(50);

    KeepAliveFilter keepAliveFilter = MinaUtil.initServerKeepAlive(config, this);
    if (keepAliveFilter != null) {
        acceptor.getFilterChain().addLast(HEARTBEAT, keepAliveFilter);
    }
}
 
開發者ID:EthanCo,項目名稱:Halo-Turbo,代碼行數:24,代碼來源:MinaTcpServerSocket.java

示例2: 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

示例3: init

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //導入方法依賴的package包/類
public void init() {
	gameAcceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors() * 2 + 1);
	gameAcceptor.setBacklog(2000);
	gameAcceptor.getSessionConfig().setIdleTime(IdleStatus.READER_IDLE, 10);
	gameAcceptor.getSessionConfig().setReadBufferSize(2048);
	gameAcceptor.getSessionConfig().setReceiveBufferSize(2048);
	gameAcceptor.getSessionConfig().setSendBufferSize(2048);
	gameAcceptor.getSessionConfig().setTcpNoDelay(true);
	gameAcceptor.setFilterChainBuilder(ioFilterChainBuilder);
	gameAcceptor.setHandler(ioHandler);
}
 
開發者ID:myking520,項目名稱:gamefm,代碼行數:12,代碼來源:GameNioSocketAcceptor.java

示例4: 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

示例5: createAcceptor

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //導入方法依賴的package包/類
@Override
protected IoAcceptor createAcceptor() {
    NioSocketAcceptor acceptor = new NioSocketAcceptor(executor, ioProcessor);
    acceptor.setCloseOnDeactivation(false);
    acceptor.setReuseAddress(reuseAddress);
    acceptor.setBacklog(backlog);

    // MINA itself forces our socket receive buffer to 1024 bytes
    // by default, despite what the operating system defaults to.
    // This limits us to about 3 MB/s incoming data transfer.  By
    // forcing back to the operating system default we can get a
    // decent transfer rate again.
    //
    final Socket s = new Socket();
    try {
        try {
            acceptor.getSessionConfig().setReceiveBufferSize(s.getReceiveBufferSize());
        } finally {
            s.close();
        }
    } catch (IOException e) {
        log.warn("cannot adjust SO_RCVBUF back to system default", e);
    }
    if (sessionConfig != null) {
        acceptor.getSessionConfig().setAll(sessionConfig);
    }
    return acceptor;
}
 
開發者ID:cloudnautique,項目名稱:cloud-cattle,代碼行數:29,代碼來源:SharedExecutorMinaAcceptor.java

示例6: 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

示例7: startServer

import org.apache.mina.transport.socket.nio.NioSocketAcceptor; //導入方法依賴的package包/類
@Override
public void startServer(String bindAddr, int port) {
	try {
		acceptor = new NioSocketAcceptor();
		acceptor.getSessionConfig().setTcpNoDelay(true);
		int sendBuf = GlobalConfig.getInstance().getIntProperty(GlobalConfigKey.tcp_sendbuf);
		if ( sendBuf <= 0 ) {
			sendBuf = 1024;
		}
		log.info("Set tcp SO_SNDBUF to " + sendBuf);
		acceptor.getSessionConfig().setSendBufferSize(sendBuf);
		int recvBuf = GlobalConfig.getInstance().getIntProperty(GlobalConfigKey.tcp_recvbuf);
		if ( recvBuf <= 0 ) {
			recvBuf = 1024;
		}
		log.info("Set tcp SO_RECVBUF to " + recvBuf);
		acceptor.getSessionConfig().setReceiveBufferSize(recvBuf);
		int backlog = GlobalConfig.getInstance().getIntProperty(GlobalConfigKey.tcp_backlog);
		if ( backlog <= 0 ) {
			backlog = 10000;
		}
		log.info("Set tcp SO_BACKLOG to " + backlog);
		acceptor.setBacklog(10000);
		acceptor.getSessionConfig().setKeepAlive(true);
		
		reloadHandler = new ReloadProtocolCodecFilter(
				protocolCodecFilterClassName, protocolHandlerClassName);
		
		acceptor.getFilterChain().addLast("protocol", reloadHandler);
		acceptor.setHandler(reloadHandler);
		
		//Bind and start to accept incoming connections
		//TODO change the port to external configuration.
		if ( bindAddr != null ) {
			bindAddress = new InetSocketAddress(bindAddr, port);
		} else {
			bindAddress = new InetSocketAddress(port);
		}
		//If the user are idle over 10 minutes, call the session idle method.
		int idleTime = GlobalConfig.getInstance().
				getIntProperty("common.server.idle.seconds");
		acceptor.getSessionConfig().setBothIdleTime(idleTime);
		acceptor.setReuseAddress(true);
		acceptor.bind(bindAddress);
		log.info(serverName+" bind at " + bindAddress);
		serverStartMillis = System.currentTimeMillis();
	} catch (Throwable e) {
		log.error("Failed to start " + serverName, e);
	}
}
 
開發者ID:wangqi,項目名稱:gameserver,代碼行數:51,代碼來源:CommonServer.java


注:本文中的org.apache.mina.transport.socket.nio.NioSocketAcceptor.setBacklog方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。