• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java WriteTimeoutHandler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.netty.handler.timeout.WriteTimeoutHandler的典型用法代码示例。如果您正苦于以下问题:Java WriteTimeoutHandler类的具体用法?Java WriteTimeoutHandler怎么用?Java WriteTimeoutHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



WriteTimeoutHandler类属于io.netty.handler.timeout包,在下文中一共展示了WriteTimeoutHandler类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: initChannel

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(io.netty.channel.socket.SocketChannel channel) throws Exception {
    ChannelPipeline pipeline = channel.pipeline();

    // 连接管理
    pipeline.addLast(ConnectionManageHandler.NAME, new ConnectionManageHandler(3000));

    // 空闲超时
    pipeline.addLast(new IdleStateHandler(10, 10, 0));
    pipeline.addLast(new IdleStateEventHandler());

    // 读写超时
    pipeline.addLast(new ReadTimeoutHandler(socksProperties.getReadTimeoutMillis(), TimeUnit.MILLISECONDS));
    pipeline.addLast(new WriteTimeoutHandler(socksProperties.getWriteTimeoutMillis(), TimeUnit.MILLISECONDS));

    // netty log
    //pipeline.addLast(new LoggingHandler());

    // 负责将输出的 Socks5Message 转为 ByteBuf
    pipeline.addLast(Socks5ServerEncoder.DEFAULT);

    // init
    pipeline.addLast(Socks5InitialRequestDecoder.class.getName(), new Socks5InitialRequestDecoder());
    pipeline.addLast(Socks5InitialRequestHandler.class.getName(), socks5InitialRequestHandler);

    // auth
    if (socks5PasswordAuthRequestHandler != null) {
        pipeline.addLast(Socks5PasswordAuthRequestDecoder.class.getName(), new Socks5PasswordAuthRequestDecoder());
        pipeline.addLast(Socks5PasswordAuthRequestHandler.class.getName(), socks5PasswordAuthRequestHandler);
    }

    // connection
    pipeline.addLast(Socks5CommandRequestDecoder.class.getName(), new Socks5CommandRequestDecoder());
    pipeline.addLast(Socks5CommandRequestHandler.class.getName(), socks5CommandRequestHandler);
}
 
开发者ID:tridays,项目名称:netty-socks,代码行数:36,代码来源:Socks5WorkerChannelInitializer.java


示例2: makeRequest

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
private void makeRequest(HttpRequest request) {
    log.debug("Writing request: {}", request);
    channel.pipeline().addFirst(new WriteTimeoutHandler(context.configuration().writeTimeout()));
    channel.writeAndFlush(new StreamedRequest(request, context.sdkRequestProvider(), channel))
           .addListener(wireCall -> {
               ChannelUtils.removeIfExists(channel.pipeline(), WriteTimeoutHandler.class);
               if (wireCall.isSuccess()) {
                   channel.pipeline().addFirst(new ReadTimeoutHandler(context.configuration().readTimeout()));
                   // Auto-read is turned off so trigger an explicit read to give control to HttpStreamsClientHandler
                   channel.read();
               } else {
                   handleFailure(() -> "Failed to make request to " + endpoint(), wireCall.cause());
               }
           });
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:16,代码来源:RunnableRequest.java


示例3: channelReleased

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
@Override
public void channelReleased(Channel ch) throws Exception {
    // Remove any existing handlers from the pipeline from the previous request.
    ChannelUtils.removeIfExists(ch.pipeline(),
                                HttpStreamsClientHandler.class,
                                ResponseHandler.class,
                                ReadTimeoutHandler.class,
                                WriteTimeoutHandler.class);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:10,代码来源:ChannelPipelineInitializer.java


示例4: initChannel

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel channel) throws Exception {

    BackendInfo backendInfo = Apex.getBalancingStrategy()
            .selectBackend(channel.remoteAddress().getHostName(), channel.remoteAddress().getPort());

    if (backendInfo == null) {
        // Gracefully close the channel
        channel.close();

        logger.error("Unable to select a backend server. All down?");
        return;
    }

    channel.pipeline()
            .addLast(new ReadTimeoutHandler(readTimeout))
            .addLast(new WriteTimeoutHandler(writeTimeout));

    GlobalTrafficShapingHandler trafficShapingHandler = Apex.getInstance().getTrafficShapingHandler();
    if (trafficShapingHandler != null) {
        channel.pipeline().addLast(trafficShapingHandler);
    }

    channel.pipeline().addLast(new SocketUpstreamHandler(backendInfo));

    // Keep track of connections per second
    if (connectionsPerSecondTask != null) {
        connectionsPerSecondTask.inc();
    }

    logger.debug("Connected [{}] <-> [{}:{} ({})]", channel.remoteAddress(), backendInfo.getHost(), backendInfo.getPort(), backendInfo.getName());
}
 
开发者ID:JackWhite20,项目名称:Apex,代码行数:33,代码来源:ApexSocketChannelInitializer.java


示例5: getChangeHandler

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
public ChannelHandler getChangeHandler(HandlerType handlerType,
                                       ClientSessionConfiguration sessionConfiguration,
                                       SessionCallbackHandler clientSession,
                                       Transcoder transcoder) {
    switch (handlerType) {
        case MESSAGE_LOGGER:
            return MESSAGE_LOGGER;
        case SESSION_WRAPPER:
            return new SessionWrapperHandler(clientSession);
        case WRITE_TIMEOUT_HANDLER:
            return new WriteTimeoutHandler(sessionConfiguration.getWriteTimeout(),
                                           TimeUnit.MILLISECONDS);
        case MESSAGE_DECODER:
            return new MessageDecoder(transcoder);
        case MESSAGE_ENCODER:
            return new MessageEncoder(transcoder);
        case LENGTH_FRAME_DECODER:
            return new LengthFieldBasedFrameDecoder(MAXIMUM_MESSAGE_BYTE_SIZE,
                                                    MESSAGE_FIELD_OFFSET,
                                                    LENGTH_FIELD_SIZE,
                                                    0,
                                                    LENGTH_FIELD_SIZE);
        case LENGTH_FRAME_ENCODER:
            return new LengthFieldPrepender(LENGTH_FIELD_SIZE, false);
        default:
            throw new IllegalArgumentException("Invalid handler type");
    }
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:29,代码来源:ChannelHandlerProvider.java


示例6: testCreateWriteTimeoutHandler

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
@Test
public void testCreateWriteTimeoutHandler() throws Exception {
    assertTrue("Not correct class",
               channelHandlerProvider.getChangeHandler(HandlerType.WRITE_TIMEOUT_HANDLER,
                                                       mock(ClientSessionConfiguration.class),
                                                       mock(SessionCallbackHandler.class),
                                                       mock(Transcoder.class))
                       instanceof WriteTimeoutHandler);
}
 
开发者ID:spapageo,项目名称:jannel,代码行数:10,代码来源:ChannelHandlerProviderTest.java


示例7: initChannel

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
	ch.pipeline().addLast("PushMessageDecoder-" + ch.hashCode(),
			new DDPushMessageDecoder());
	ch.pipeline().addLast("processPushTask-" + ch.hashCode(),
			new PushTaskHandler(
					NettyPushListener.this));
	ch.pipeline().addLast("WritTimeout-" + ch.hashCode(),
			new WriteTimeoutHandler(sockTimeoutSeconds));
	ch.pipeline().addLast(new PushResponseHandler());

}
 
开发者ID:taojiaenx,项目名称:taojiane_push,代码行数:13,代码来源:NettyPushListener.java


示例8: initChannel

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
    ChannelPipeline p = ch.pipeline();
    p.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS));
    p.addLast(new WriteTimeoutHandler(writeTimeout, TimeUnit.MILLISECONDS));
    p.addLast(serverHandler);
}
 
开发者ID:adohe,项目名称:Jasmine,代码行数:8,代码来源:CustomServerInitializer.java


示例9: refreshWriteTimeoutHandler

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
public void refreshWriteTimeoutHandler(Channel channel) {
    if (channel != null) {
        if (this.writeTimeout <= 0) {
            if (channel.pipeline().get("writeTimeout") != null) {
                channel.pipeline().remove("writeTimeout");
            }
        } else if (channel.pipeline().get("writeTimeout") == null) {
            channel.pipeline().addFirst("writeTimeout", new WriteTimeoutHandler(this.writeTimeout));
        } else {
            channel.pipeline().replace("writeTimeout", "writeTimeout", new WriteTimeoutHandler(this.writeTimeout));
        }
    }
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:14,代码来源:PCSession.java


示例10: refreshWriteTimeoutHandler

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
protected void refreshWriteTimeoutHandler(Channel channel) {
    if(channel != null) {
        if(this.writeTimeout <= 0) {
            if(channel.pipeline().get("writeTimeout") != null) {
                channel.pipeline().remove("writeTimeout");
            }
        } else {
            if(channel.pipeline().get("writeTimeout") == null) {
                channel.pipeline().addFirst("writeTimeout", new WriteTimeoutHandler(this.writeTimeout));
            } else {
                channel.pipeline().replace("writeTimeout", "writeTimeout", new WriteTimeoutHandler(this.writeTimeout));
            }
        }
    }
}
 
开发者ID:Steveice10,项目名称:PacketLib,代码行数:16,代码来源:TcpSession.java


示例11: initChannel

import io.netty.handler.timeout.WriteTimeoutHandler; //导入依赖的package包/类
@Override
public void initChannel( Channel channel )
{
    ChannelPipeline pipeline = channel.pipeline();

    // Connection Events
    String remoteHostString = ( (InetSocketAddress) channel.remoteAddress() ).getHostString();
    app.events().emit( new ConnectionEvent.Opened( remoteHostString ) );
    channel.closeFuture().addListener(
        future -> app.events().emit( new ConnectionEvent.Closed( remoteHostString ) )
    );

    if( app.config().bool( WERVAL_HTTP_LOG_LOWLEVEL_ENABLED ) )
    {
        // Log Netty Bytes
        LogLevel level = LogLevel.valueOf(
            app.config().string( WERVAL_HTTP_LOG_LOWLEVEL_LEVEL ).toUpperCase( US )
        );
        pipeline.addLast( "byte-logging", new LoggingHandler( "io.werval.server.netty.LowLevelLogger", level ) );
    }

    // Read/Write Timeout
    long readTimeout = app.config().seconds( WERVAL_HTTP_TIMEOUT_READ );
    long writeTimeout = app.config().seconds( WERVAL_HTTP_TIMEOUT_WRITE );
    pipeline.addLast( "read-timeout", new ReadTimeoutHandler( readTimeout, SECONDS ) );
    pipeline.addLast( "write-timeout", new WriteTimeoutHandler( writeTimeout, SECONDS ) );

    // HTTP Decoding / Encoding
    // HTTP decoders always generates multiple message objects per a single HTTP message:
    //
    //  1       * HttpRequest / HttpResponse
    //  0 - n   * HttpContent
    //  1       * LastHttpContent
    //
    // or a single FullHttpRequest if a handler ask for it
    pipeline.addLast( "http-codec", new HttpServerCodec() );

    // GZip decompression support
    pipeline.addLast( "http-decompressor", new HttpContentDecompressor() );

    // Allow to send chunked data
    pipeline.addLast( "chunked-write-handler", new ChunkedWriteHandler() );

    // Protocol Switching Handler
    pipeline.addLast( "subprotocol-switcher", new SubProtocolSwitchHandler( allChannels, app, devSpi ) );
}
 
开发者ID:werval,项目名称:werval,代码行数:47,代码来源:HttpServerChannelInitializer.java



注:本文中的io.netty.handler.timeout.WriteTimeoutHandler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Builder类代码示例发布时间:2022-05-22
下一篇:
Java BaseNode类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap