本文整理汇总了Java中org.apache.mina.transport.socket.SocketSessionConfig.setReceiveBufferSize方法的典型用法代码示例。如果您正苦于以下问题:Java SocketSessionConfig.setReceiveBufferSize方法的具体用法?Java SocketSessionConfig.setReceiveBufferSize怎么用?Java SocketSessionConfig.setReceiveBufferSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.transport.socket.SocketSessionConfig
的用法示例。
在下文中一共展示了SocketSessionConfig.setReceiveBufferSize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SocketServer
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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: startListner
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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: sessionCreated
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
public void sessionCreated(IoSession session)
{
if (session.getConfig() instanceof SocketSessionConfig)
{
SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();
cfg.setReceiveBufferSize(1024);
cfg.setTcpNoDelay(true);
}
session.getConfig().setIdleTime(IdleStatus.READER_IDLE, timeout);
// We're going to use SSL negotiation notification.
session.setAttribute(SslFilter.USE_NOTIFICATION);
// Initialize POP3 protocol session attributes
MinaPop3Connection conn = new MinaPop3Connection(session, userManager);
session.setAttribute(CONNECTION, conn);
session.setAttribute(USING_APOP_AUTH, usingAPOPAuthMethod);
session.setAttribute(SECURED_AUTH_REQUIRED, secureAuthRequired);
session.setAttribute(PEER_IS_CLOSING_SESSION, Boolean.FALSE);
sendGreetings(conn);
}
示例4: initConnector
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
private void initConnector(InetSocketAddress isa, TransportConfig config) {
// create connector
ioConnector = new NioSocketConnector(1);
ioConnector.setConnectTimeoutMillis(config.getConnectTimeout());
SocketSessionConfig sessionConfig = ioConnector.getSessionConfig();
sessionConfig.setTcpNoDelay(true);
sessionConfig.setReceiveBufferSize(8 * 1024);
sessionConfig.setSendBufferSize(8 * 1024);
DefaultIoFilterChainBuilder chainBuilder = ioConnector.getFilterChain();
final TransportProtocolEncoder encoder = new TransportProtocolEncoder();
final TransportProtocolDecoder decoder = new TransportProtocolDecoder();
encoder.setMaxObjectSize(config.getMaxSize());
decoder.setMaxObjectSize(config.getMaxSize());
// add filter
chainBuilder.addLast("codec", new ProtocolCodecFilter(encoder, decoder));
// add keep alive filter
ActiveKeepAliveMessageFactory messageFactory = new ActiveKeepAliveMessageFactory(config.getSerializeType());
KeepAliveFilter kaFilter = new KeepAliveFilter(messageFactory, IdleStatus.BOTH_IDLE);
kaFilter.setRequestInterval(config.getHeartbeatIntervalSeconds());
kaFilter.setForwardEvent(true);
chainBuilder.addLast("keepAlive", kaFilter);
// set handler
ioConnector.setHandler(new MinaIoHandler());
ioConnector.setDefaultRemoteAddress(isa);
}
示例5: start
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
@Override
public void start() throws SuspendExecution, Exception {
// Acceptor
acceptor = new PooledNioSocketAcceptor(cpool);
acceptor.setBacklog(1024);
acceptor.setSessionDataStructureFactory(new PooledIoSessionDataStructureFactory(cpool));
messageFactory =
new MinaMessageFactory(
// hostAx.getActorSystem().getCustomMessageMap(),
hostAx.getActorSystem().getCMsgMap(),
localInfo.getMinaMsgPoolSize(),
localInfo.getMinaMsgPoolInitSize(),
localInfo.getMinaMsgPoolMaxSize()
);
acceptor.getFilterChain().addLast("codec", new PooledProtocolCodecFilter(cpool, new MinaCodecFactory(messageFactory)));
// Handler
acceptor.setHandler(new MinaIoHandler(hostAx));
// Config
acceptor.setReuseAddress(true);
SocketSessionConfig sscfg = acceptor.getSessionConfig();
sscfg.setReadBufferSize(2048);
sscfg.setMinReadBufferSize(2048);
sscfg.setMaxReadBufferSize(2048);
sscfg.setIdleTime(IdleStatus.READER_IDLE, localInfo.getMinaIdleTime());
sscfg.setReceiveBufferSize(64 * 1024);
sscfg.setSendBufferSize(160 * 1024);
sscfg.setWriteTimeout(2);
sscfg.setTcpNoDelay(true);
sscfg.setSoLinger(-1);
sscfg.setKeepAlive(false);
// Bind
List<SocketAddress> socketAddresses = new ArrayList<SocketAddress>();
socketAddresses.add(new InetSocketAddress(localInfo.getHost(), localInfo.getPort()));
acceptor.bind(socketAddresses);
}
示例6: sessionCreated
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
@Override
public void sessionCreated(IoSession session) throws Exception {
SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();
cfg.setReceiveBufferSize(2 * 1024 * 1024);
cfg.setReadBufferSize(2 * 1024 * 1024);
cfg.setKeepAlive(true);
cfg.setSoLinger(0);
}
示例7: buildSocketAcceptor
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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;
}
示例8: bind
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的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;
}
示例9: start
import org.apache.mina.transport.socket.SocketSessionConfig; //导入方法依赖的package包/类
@Override
public void start() throws SuspendExecution, Exception {
connector = new PooledNioSocketConnector(cpool);
connector.setSessionDataStructureFactory(new PooledIoSessionDataStructureFactory(cpool));
messageFactory =
new MinaMessageFactory(
// hostAx.getActorSystem().getCustomMessageMap(),
hostAx.getActorSystem().getCMsgMap(),
remoteInfo.getMinaMsgPoolSize(),
remoteInfo.getMinaMsgPoolInitSize(),
remoteInfo.getMinaMsgPoolMaxSize()
);
connector.getFilterChain().addLast("codec", new PooledProtocolCodecFilter(cpool, new MinaCodecFactory(messageFactory)));
connector.setHandler(new MinaIoHandler(hostAx));
connector.setConnectTimeoutMillis(TimeUnit.SECONDS.toMillis(remoteInfo.getMinaConnectTimeout()));
SocketSessionConfig sscfg = connector.getSessionConfig();
sscfg.setReadBufferSize(2048);
sscfg.setMinReadBufferSize(2048);
sscfg.setMaxReadBufferSize(2048);
sscfg.setIdleTime(IdleStatus.READER_IDLE, remoteInfo.getMinaIdleTime());
sscfg.setReceiveBufferSize(64 * 1024);
sscfg.setSendBufferSize(160 * 1024);
sscfg.setWriteTimeout(2);
sscfg.setTcpNoDelay(true);
sscfg.setSoLinger(-1);
sscfg.setKeepAlive(false);
heartAid = hostAx.getActorSystem().spawn(hostAx, hostAx.getFiberScheduler(), new IFiberActorHandler() {
@Override
public void run(Actor self) throws SuspendExecution, InterruptedException {
// 心跳计时器Actor
Message cmsg = self.recv("INIT");
ActorId sireAid = cmsg.getSender();
Pattern pattern = new Pattern();
pattern.match("STOP");
pattern.after(remoteInfo.getHeartTimeout(), TimeUnit.SECONDS);
while (true){
try (PoolGuard guard = self.precv(pattern)){
Message msg = guard.get();
if (msg != null){
String type = msg.getType();
if (AtomCode.equals(type, "STOP")){
break;
}
}else{
self.send(sireAid, "HEART");
}
}catch (Throwable e){
logger.error("{} heart error: {}", getClass().getSimpleName(), ExceptionUtils.printStackTrace(e));
}
}
}
}, LinkType.MONITORED);
hostAx.send(heartAid, "INIT");
}