本文整理汇总了Java中org.apache.mina.transport.socket.nio.NioSocketConnector.getSessionConfig方法的典型用法代码示例。如果您正苦于以下问题:Java NioSocketConnector.getSessionConfig方法的具体用法?Java NioSocketConnector.getSessionConfig怎么用?Java NioSocketConnector.getSessionConfig使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.transport.socket.nio.NioSocketConnector
的用法示例。
在下文中一共展示了NioSocketConnector.getSessionConfig方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clientStart
import org.apache.mina.transport.socket.nio.NioSocketConnector; //导入方法依赖的package包/类
@Override
protected void clientStart() throws RemotingException {
try {
connector = new NioSocketConnector(); //TCP Connector
// connector.getFilterChain().addFirst("logging", new MinaLoggingFilter());
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecFactory(getCodec())));
connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());
connector.setHandler(new MinaHandler(this));
IoSessionConfig cfg = connector.getSessionConfig();
cfg.setReaderIdleTime(remotingClientConfig.getReaderIdleTimeSeconds());
cfg.setWriterIdleTime(remotingClientConfig.getWriterIdleTimeSeconds());
cfg.setBothIdleTime(remotingClientConfig.getClientChannelMaxIdleTimeSeconds());
} catch (Exception e) {
throw new RemotingException("Mina Client start error", e);
}
}
示例2: MinaDestination
import org.apache.mina.transport.socket.nio.NioSocketConnector; //导入方法依赖的package包/类
public MinaDestination(String host, int port, boolean withLogging) throws Exception {
socketAddress = new InetSocketAddress(host, port);
connector = new NioSocketConnector(Runtime.getRuntime().availableProcessors() + 1);
connector.setConnectTimeoutMillis(10000L);
connectorConfig = connector.getSessionConfig();
executor = new OrderedThreadPoolExecutor(5);
connector.getFilterChain().addLast("threadPool", new ExecutorFilter(executor));
if (withLogging) {
connector.getFilterChain().addLast("logger", new LoggingFilter());
}
SslFilter filter = new SslFilter(SSLContext.getDefault(), true);
filter.setUseClientMode(true);
connector.getFilterChain().addFirst("sslFilter", filter);
}
示例3: initConnector
import org.apache.mina.transport.socket.nio.NioSocketConnector; //导入方法依赖的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);
}
示例4: main
import org.apache.mina.transport.socket.nio.NioSocketConnector; //导入方法依赖的package包/类
public static void main(String[] args) {
NioSocketConnector connector = new NioSocketConnector();
DefaultIoFilterChainBuilder chain = connector.getFilterChain();
SocketSessionConfig config = connector.getSessionConfig();
config.setReuseAddress(true);
config.setIdleTime(IdleStatus.READER_IDLE, 20);// 读空闲 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());
connector.setHandler(new MinaMessageHandler());
connector.setConnectTimeoutMillis(15 * 1000); // 设置连接超时 ,15秒
connector.setConnectTimeoutCheckInterval(300);
// 建立连接
ConnectFuture cf = connector.connect(new InetSocketAddress("localhost", 8000));
// 等待连接创建完成
cf.awaitUninterruptibly();
Packet packet = Packet.newBuilder().setCmdId(0).setChatMsgAck(ChatMsgAck.newBuilder().setResult(123)).build();
cf.getSession().write(packet.toByteArray());
packet = Packet.newBuilder().setCmdId(1).setChatMsgAck(ChatMsgAck.newBuilder().setResult(123)).build();
cf.getSession().write(packet.toByteArray());
// 等待连接断开
cf.getSession().getCloseFuture().awaitUninterruptibly();
// 释放连接
connector.dispose();
}
示例5: WSClient
import org.apache.mina.transport.socket.nio.NioSocketConnector; //导入方法依赖的package包/类
public WSClient(String host, int port) {
this.host = host;
this.port = port;
connector = new NioSocketConnector();
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new WebSocketCodecFactory()));
connector.setHandler(this);
SocketSessionConfig sessionConf = connector.getSessionConfig();
sessionConf.setReuseAddress(true);
connector.setConnectTimeout(3);
}