本文整理匯總了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();
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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));
}
示例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");
}
}
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}