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