当前位置: 首页>>代码示例>>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;未经允许,请勿转载。