本文整理汇总了Java中org.apache.mina.transport.socket.SocketSessionConfig.setWriteTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java SocketSessionConfig.setWriteTimeout方法的具体用法?Java SocketSessionConfig.setWriteTimeout怎么用?Java SocketSessionConfig.setWriteTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.transport.socket.SocketSessionConfig
的用法示例。
在下文中一共展示了SocketSessionConfig.setWriteTimeout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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");
}