當前位置: 首頁>>代碼示例>>Java>>正文


Java NioSocketConnector.getSessionConfig方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:WenZuHuai,項目名稱:light-task-scheduler,代碼行數:19,代碼來源:MinaRemotingClient.java

示例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);
}
 
開發者ID:oehf,項目名稱:ipf-oht-atna,代碼行數:17,代碼來源:MinaTLSSyslogSenderImpl.java

示例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);
}
 
開發者ID:dinstone,項目名稱:jrpc,代碼行數:32,代碼來源:MinaConnector.java

示例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();

}
 
開發者ID:East196,項目名稱:maker,代碼行數:34,代碼來源:TcpClient.java

示例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);
}
 
開發者ID:Red5,項目名稱:red5-websocket,代碼行數:11,代碼來源:WebSocketServerTest.java


注:本文中的org.apache.mina.transport.socket.nio.NioSocketConnector.getSessionConfig方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。