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


Java IdleStateHandler類代碼示例

本文整理匯總了Java中io.netty.handler.timeout.IdleStateHandler的典型用法代碼示例。如果您正苦於以下問題:Java IdleStateHandler類的具體用法?Java IdleStateHandler怎麽用?Java IdleStateHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IdleStateHandler類屬於io.netty.handler.timeout包,在下文中一共展示了IdleStateHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: open

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
@Override
    public void open() {
        EventLoopGroup eventLoop = new NioEventLoopGroup();
        bootstrap = new Bootstrap();
        bootstrap.group(eventLoop);
        bootstrap.channel(NioSocketChannel.class);
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3 * 1000);
        bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
        bootstrap.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline()
//                        .addLast("logging",new LoggingHandler(LogLevel.INFO))
                        .addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader()))) // in 1
                        .addLast("handler", new ClientReadHandler()) // in 2
                        .addLast("encoder", new ObjectEncoder())// out 3
                        .addLast("idleStateHandler", new IdleStateHandler(0, 1, 0))
                        .addLast(new ClientIdleHandler());

            }
        });
    }
 
開發者ID:justice-code,項目名稱:star-map,代碼行數:23,代碼來源:StarClientProtocol.java

示例2: setupWSChannel

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
protected ChannelHandler setupWSChannel(SslContext sslCtx, Configuration conf, DataStore datastore) {
    return new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
            ch.pipeline().addLast("httpServer", new HttpServerCodec());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
            ch.pipeline().addLast("sessionExtractor", new WebSocketHttpCookieHandler(config));
            ch.pipeline().addLast("idle-handler", new IdleStateHandler(conf.getWebsocket().getTimeout(), 0, 0));
            ch.pipeline().addLast("ws-protocol", new WebSocketServerProtocolHandler(WS_PATH, null, true));
            ch.pipeline().addLast("wsDecoder", new WebSocketRequestDecoder(datastore, config));
            ch.pipeline().addLast("error", new WSExceptionHandler());
        }
    };

}
 
開發者ID:NationalSecurityAgency,項目名稱:qonduit,代碼行數:18,代碼來源:Server.java

示例3: initChannel

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
    RPCChannelHandler channelHandler = 
            new RPCChannelHandler(syncManager, rpcService);

    IdleStateHandler idleHandler = 
            new IdleStateHandler(5, 10, 0);
    ReadTimeoutHandler readTimeoutHandler = 
            new ReadTimeoutHandler(30);
    
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("idle", idleHandler);
    pipeline.addLast("timeout", readTimeoutHandler);
    pipeline.addLast("handshaketimeout",
                     new HandshakeTimeoutHandler(channelHandler, timer, 10));

    pipeline.addLast("syncMessageDecoder",
                     new SyncMessageDecoder(maxFrameSize));
    pipeline.addLast("syncMessageEncoder",
                     new SyncMessageEncoder());

    pipeline.addLast("handler", channelHandler);
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:24,代碼來源:RPCChannelInitializer.java

示例4: mayBeCreateIdleStateHandler

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
private Optional<IdleStateHandler> mayBeCreateIdleStateHandler() {
    if (hbInterval > 0 && hbLossThreshold > 0) {
        int interval = hbInterval;
        int readTimeout = hbInterval * hbLossThreshold;

        if (hbDisabled) {
            interval = 0;

            if (debug) {
                log.debug("Registering heartbeatless timeout handler [from={}, read-timeout={}]", address(), readTimeout);
            }
        } else {
            if (debug) {
                log.debug("Registering heartbeat handler [from={}, interval={}, loss-threshold={}, read-timeout={}]",
                    address(), interval, hbLossThreshold, readTimeout);
            }
        }

        return Optional.of(new IdleStateHandler(readTimeout, interval, 0, TimeUnit.MILLISECONDS));
    }

    return Optional.empty();
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:24,代碼來源:NettyServerClient.java

示例5: initChannel

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
@Override
public void initChannel(final SocketChannel ch) throws Exception {
    final ChannelPipeline p = ch.pipeline();

    // removes idle connections after READER_IDLE_SECONDS seconds
    p.addLast("idleStateHandler",
            new IdleStateHandler(READER_IDLE_SECONDS, 0, 0));

    // handle new connections and idle timeouts
    p.addLast("auth", authHandler);

    // break each data chunk by newlines and split out metrics
    p.addLast("line", new GraphiteMetricDecoder(maxLength));

    // batch up metrics and store
    p.addLast("metrics", new MetricHandler(store));
}
 
開發者ID:smoketurner,項目名稱:graphiak,代碼行數:18,代碼來源:GraphiakInitializer.java

示例6: initChannel

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    try {
        ch.config().setOption(ChannelOption.TCP_NODELAY, true);
        ch.config().setOption(ChannelOption.IP_TOS, 0x18);
    } catch (ChannelException ex) {
        // IP_TOS not supported by platform, ignore
    }
    ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
    
    PacketRegistry r = new PacketRegistry();

    ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 30));
    ch.pipeline().addLast(new HttpServerCodec());
    ch.pipeline().addLast(new HttpObjectAggregator(65536));
    ch.pipeline().addLast(new WebSocketHandler());
    ch.pipeline().addLast(new PacketDecoder(r));
    ch.pipeline().addLast(new PacketEncoder(r));
    ch.pipeline().addLast(mExecutorGroup, "serverHandler", new ClientHandler(mServer));
}
 
開發者ID:FightForSub,項目名稱:FFS-PubSub,代碼行數:21,代碼來源:NetworkManager.java

示例7: newChannelInitializer

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
private ChannelInitializer<SocketChannel> newChannelInitializer(final NegotiateConfig config,
		final ExchangeChannelGroup channelGroup, final EventExecutorGroup executorGroup) {
	return new ChannelInitializer<SocketChannel>() {
		@Override
		protected void initChannel(SocketChannel ch) throws Exception {
			ChannelPipeline pipeline = ch.pipeline();
			ch.attr(ChannelAttrKeys.maxIdleTimeout).set(config.maxIdleTimeout());
			ch.attr(ChannelAttrKeys.channelGroup).set(channelGroup);
			ch.attr(ChannelAttrKeys.clientSide).set(true);
			ch.attr(OneTime.awaitNegotiate).set(new CountDownLatch(1));
			ch.attr(OneTime.channelConfig).set(config);
			// TODO should increase ioRatio when every ChannelHandler bind to executorGroup?
			pipeline.addLast(executorGroup, 
					RemotingEncoder.INSTANCE, 
					new RemotingDecoder(), 
					new IdleStateHandler(config.idleTimeout(), 0, 0), 
					HeartbeatChannelHandler.INSTANCE,
					NegotiateChannelHandler.INSTANCE,
					ConcreteRequestHandler.INSTANCE);
		}
	};
}
 
開發者ID:spccold,項目名稱:sailfish,代碼行數:23,代碼來源:AbstractConfigurableExchangeChannelGroup.java

示例8: initChannel

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
@Override
protected void initChannel(SocketChannel ch) throws Exception {
	ch.config().setAllowHalfClosure(true);
	ChannelPipeline pipeline = ch.pipeline();

	//IdleStateHandler 與客戶端鏈接後,根據超出配置的時間自動觸發userEventTriggered
	//readerIdleTime服務端長時間沒有讀到數據,則為讀空閑,觸發讀空閑監聽,並自動關閉鏈路連接,周期性按readerIdleTime的超時間觸發空閑監聽方法
	//writerIdleTime服務端長時間沒有發送寫請求,則為空閑,觸發寫空閑監聽,空閑期間,周期性按writerIdleTime的超時間觸發空閑監聽方法
	//allIdleTime 服務端在allIdleTime時間內未接收到客戶端消息,或者,也未去向客戶端發送消息,則觸發周期性操作
	pipeline.addLast("ping", new IdleStateHandler(10, 20, 35, TimeUnit.SECONDS));
	// 以("\n")為結尾分割的 解碼器
	pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
	// 字符串解碼 和 編碼
	pipeline.addLast("decoder", new StringDecoder());
	pipeline.addLast("encoder", new StringEncoder());
	// 自己的邏輯Handler
	pipeline.addLast("handler", new DataServerHandler(nodeInfo));
}
 
開發者ID:beijing-penguin,項目名稱:raft-java,代碼行數:19,代碼來源:StartServer.java

示例9: initChannel

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
@Override
public void initChannel(SocketChannel ch) {
    /* Netty default: {@code maxInitialLineLength (4096)} */
    int maxInitialLineLength = 4096 * 2;
    /* Netty default: {@code maxHeaderSize (8192)} */
    int maxHeaderSize = 8192 * 2;
    /* Netty default: {@code maxChunkSize (8192)} */
    int maxChunkSize = 8192 * 2;
    int readerIdleTimeSeconds = 0;
    int writerIdleTimeSeconds = 0;
    int allIdleTimeSeconds = 10;
    ch.pipeline().addLast(new LoggingHandler(NettyProxyFrontendHandler.class), //
            new HttpRequestDecoder(maxInitialLineLength, maxHeaderSize, maxChunkSize), //
            new IdleStateHandler(readerIdleTimeSeconds, writerIdleTimeSeconds, allIdleTimeSeconds), //
            new NettyProxyFrontendHandler());
}
 
開發者ID:ganskef,項目名稱:shortcircuit-proxy,代碼行數:17,代碼來源:NettyProxyFrontendInitializer.java

示例10: start

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
private void start() throws InterruptedException {
    EventLoopGroup eventLoopGroup=new NioEventLoopGroup();
    Bootstrap bootstrap=new Bootstrap();
    bootstrap.channel(NioSocketChannel.class);
    bootstrap.option(ChannelOption.SO_KEEPALIVE,true);
    bootstrap.group(eventLoopGroup);
    bootstrap.remoteAddress(host,port);
    bootstrap.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel socketChannel) throws Exception {
            socketChannel.pipeline().addLast(new IdleStateHandler(20,10,0));
            socketChannel.pipeline().addLast(new ObjectEncoder());
            socketChannel.pipeline().addLast(new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
            socketChannel.pipeline().addLast(new NettyClientHandler());
        }
    });
    ChannelFuture future =bootstrap.connect(host,port).sync();
    if (future.isSuccess()) {
        socketChannel = (SocketChannel)future.channel();
        System.out.println("connect server  成功---------");
    }
}
 
開發者ID:howdyli,項目名稱:netty,代碼行數:23,代碼來源:NettyClientBootstrap.java

示例11: initializePlainTCPTransport

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
    final SmartConnectorIdleTimeoutHandler timeoutHandler = new SmartConnectorIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    int port = Integer.parseInt(props.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
    initFactory(host, port, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) {
            pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            //pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("handler", handler);
        }
    });
}
 
開發者ID:sn3009,項目名稱:EasyMessage,代碼行數:19,代碼來源:NettyAcceptor.java

示例12: NettyConnector

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
public NettyConnector(InetSocketAddress isa, final TransportConfig transportConfig) {
    workerGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("N4C-Work"));
    clientBoot = new Bootstrap().group(workerGroup).channel(NioSocketChannel.class);
    clientBoot.option(ChannelOption.TCP_NODELAY, true);
    clientBoot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, transportConfig.getConnectTimeout());
    clientBoot.option(ChannelOption.SO_RCVBUF, 8 * 1024).option(ChannelOption.SO_SNDBUF, 8 * 1024);
    clientBoot.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            TransportProtocolDecoder decoder = new TransportProtocolDecoder();
            decoder.setMaxObjectSize(transportConfig.getMaxSize());
            TransportProtocolEncoder encoder = new TransportProtocolEncoder();
            encoder.setMaxObjectSize(transportConfig.getMaxSize());
            ch.pipeline().addLast("TransportProtocolDecoder", decoder);
            ch.pipeline().addLast("TransportProtocolEncoder", encoder);

            int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds();
            ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(0, intervalSeconds, 0));
            ch.pipeline().addLast("NettyClientHandler", new NettyClientHandler());
        }
    });

    clientBoot.remoteAddress(isa);
}
 
開發者ID:dinstone,項目名稱:jrpc,代碼行數:26,代碼來源:NettyConnector.java

示例13: NettyConnector

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
public NettyConnector(InetSocketAddress isa, final TransportConfig transportConfig) {
    workerGroup = new NioEventLoopGroup(1, new DefaultExecutorServiceFactory("N5C-Work"));
    clientBoot = new Bootstrap().group(workerGroup).channel(NioSocketChannel.class);
    clientBoot.option(ChannelOption.TCP_NODELAY, true);
    clientBoot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, transportConfig.getConnectTimeout());
    clientBoot.option(ChannelOption.SO_RCVBUF, 8 * 1024).option(ChannelOption.SO_SNDBUF, 8 * 1024);
    clientBoot.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            TransportProtocolDecoder decoder = new TransportProtocolDecoder();
            decoder.setMaxObjectSize(transportConfig.getMaxSize());
            TransportProtocolEncoder encoder = new TransportProtocolEncoder();
            encoder.setMaxObjectSize(transportConfig.getMaxSize());
            ch.pipeline().addLast("TransportProtocolDecoder", decoder);
            ch.pipeline().addLast("TransportProtocolEncoder", encoder);

            int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds();
            ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(0, intervalSeconds, 0));
            ch.pipeline().addLast("NettyClientHandler", new NettyClientHandler());
        }
    });

    clientBoot.remoteAddress(isa);
}
 
開發者ID:dinstone,項目名稱:jrpc,代碼行數:26,代碼來源:NettyConnector.java

示例14: initializePlainTCPTransport

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
private void initializePlainTCPTransport(final NettyMQTTHandler handler, IConfig props) throws IOException {
    final MoquetteIdleTimeoutHandler timeoutHandler = new MoquetteIdleTimeoutHandler();
    String host = props.getProperty(BrokerConstants.HOST_PROPERTY_NAME);
    int port = Integer.parseInt(props.getProperty(BrokerConstants.PORT_PROPERTY_NAME));
    initFactory(host, port, new PipelineInitializer() {
        @Override
        void init(ChannelPipeline pipeline) {
            pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
            pipeline.addAfter("idleStateHandler", "idleEventHandler", timeoutHandler);
            //pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
            pipeline.addFirst("bytemetrics", new BytesMetricsHandler(m_bytesMetricsCollector));
            pipeline.addLast("decoder", new MQTTDecoder());
            pipeline.addLast("encoder", new MQTTEncoder());
            pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
            pipeline.addLast("handler", handler);
        }
    });
}
 
開發者ID:projectsrepos,項目名稱:jim,代碼行數:19,代碼來源:NettyAcceptor.java

示例15: initChannel

import io.netty.handler.timeout.IdleStateHandler; //導入依賴的package包/類
@Override
protected void initChannel(Channel ch) throws Exception {
    RPCChannelHandler channelHandler =
            new RPCChannelHandler(syncManager, rpcService);

    IdleStateHandler idleHandler =
            new IdleStateHandler(5, 10, 0);
    ReadTimeoutHandler readTimeoutHandler =
            new ReadTimeoutHandler(30);

    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast("idle", idleHandler);
    pipeline.addLast("timeout", readTimeoutHandler);
    pipeline.addLast("handshaketimeout",
                     new HandshakeTimeoutHandler(channelHandler, timer, 10));

    pipeline.addLast("syncMessageDecoder",
                     new SyncMessageDecoder(maxFrameSize));
    pipeline.addLast("syncMessageEncoder",
                     new SyncMessageEncoder());

    pipeline.addLast("handler", channelHandler);
}
 
開發者ID:zhenshengcai,項目名稱:floodlight-hardware,代碼行數:24,代碼來源:RPCChannelInitializer.java


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