本文整理汇总了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);
}
}
示例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));
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}