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


Java Bootstrap.option方法代碼示例

本文整理匯總了Java中io.netty.bootstrap.Bootstrap.option方法的典型用法代碼示例。如果您正苦於以下問題:Java Bootstrap.option方法的具體用法?Java Bootstrap.option怎麽用?Java Bootstrap.option使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.bootstrap.Bootstrap的用法示例。


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

示例1: open

import io.netty.bootstrap.Bootstrap; //導入方法依賴的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: newPool

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
@Override
protected FastdfsPool newPool(InetSocketAddress addr) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("channel pool created : {}", addr);
    }

    Bootstrap bootstrap = new Bootstrap().channel(NioSocketChannel.class).group(loopGroup);
    bootstrap.remoteAddress(addr);
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) connectTimeout);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    return new FastdfsPool(
            bootstrap,
            readTimeout,
            idleTimeout,
            maxConnPerHost
    );
}
 
開發者ID:rodbate,項目名稱:fastdfs-spring-boot,代碼行數:19,代碼來源:FastdfsPoolGroup.java

示例3: connect

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
@Override
public void connect() throws IOException, InterruptedException {
    workerGroup = new NioEventLoopGroup();

    Bootstrap b = new Bootstrap();
    b.group(workerGroup);
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(
                    //new LoggingHandler(LogLevel.INFO),
                    new MsgEncoder(),
                    new MsgDecoder(),
                    new NettyClientHandler()
            );
        }
    });

    ChannelFuture f = b.connect(address, port).sync();
    channel = f.channel();
}
 
開發者ID:altiplanogao,項目名稱:io-comparison,代碼行數:25,代碼來源:NettyClient.java

示例4: connectAsync

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
public ChannelFuture connectAsync(String host, int port, String remoteId, boolean discoveryMode) {
    ethereumListener.trace("Connecting to: " + host + ":" + port);

    EthereumChannelInitializer ethereumChannelInitializer = ctx.getBean(EthereumChannelInitializer.class, remoteId);
    ethereumChannelInitializer.setPeerDiscoveryMode(discoveryMode);

    Bootstrap b = new Bootstrap();
    b.group(workerGroup);
    b.channel(NioSocketChannel.class);

    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerConnectionTimeout());
    b.remoteAddress(host, port);

    b.handler(ethereumChannelInitializer);

    // Start the client.
    return b.connect();
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:21,代碼來源:PeerClient.java

示例5: connectAsync

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
public ChannelFuture connectAsync(String host, int port, String remoteId, boolean discoveryMode) {
    ethereumListener.trace("Connecting to: " + host + ":" + port);

    EthereumChannelInitializer ethereumChannelInitializer = ethereumChannelInitializerFactory.newInstance(remoteId);
    ethereumChannelInitializer.setPeerDiscoveryMode(discoveryMode);

    Bootstrap b = new Bootstrap();
    b.group(workerGroup);
    b.channel(NioSocketChannel.class);

    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.peerConnectionTimeout());
    b.remoteAddress(host, port);

    b.handler(ethereumChannelInitializer);

    // Start the client.
    return b.connect();
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:21,代碼來源:PeerClient.java

示例6: getBootstrap

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
/**
 * Init Bootstrap
 */
public static final Bootstrap getBootstrap() {
    EventLoopGroup group = new NioEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(group);
    b.channel(NioSocketChannel.class);
    b.handler(new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(Channel ch) throws Exception {
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
            pipeline.addLast("decoder", new ProtobufDecoder(MessageBuf.JMTransfer.getDefaultInstance()));
            pipeline.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
            pipeline.addLast("encoder", new ProtobufEncoder());
            pipeline.addLast("handler", new TcpClientHandler());
        }
    });


    b.option(ChannelOption.SO_KEEPALIVE, true);
    return b;
}
 
開發者ID:linkedkeeper,項目名稱:tcp-gateway,代碼行數:25,代碼來源:TcpClient.java

示例7: createBootstrap

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
private Bootstrap createBootstrap(RedisClientConfig config, Type type) {
    Bootstrap bootstrap = new Bootstrap()
                    .channel(config.getSocketChannelClass())
                    .group(config.getGroup())
                    .remoteAddress(addr);

    bootstrap.handler(new RedisChannelInitializer(bootstrap, config, this, channels, type));
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
    bootstrap.option(ChannelOption.SO_KEEPALIVE, config.isKeepAlive());
    bootstrap.option(ChannelOption.TCP_NODELAY, config.isTcpNoDelay());
    return bootstrap;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:13,代碼來源:RedisClient.java

示例8: createBootstrap

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
private Bootstrap createBootstrap() {
    final Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(new NioEventLoopGroup(workerCount, daemonThreadFactory(settings, TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX)));
    bootstrap.channel(NioSocketChannel.class);

    bootstrap.handler(getClientChannelInitializer());

    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, Math.toIntExact(defaultConnectionProfile.getConnectTimeout().millis()));
    bootstrap.option(ChannelOption.TCP_NODELAY, TCP_NO_DELAY.get(settings));
    bootstrap.option(ChannelOption.SO_KEEPALIVE, TCP_KEEP_ALIVE.get(settings));

    final ByteSizeValue tcpSendBufferSize = TCP_SEND_BUFFER_SIZE.get(settings);
    if (tcpSendBufferSize.getBytes() > 0) {
        bootstrap.option(ChannelOption.SO_SNDBUF, Math.toIntExact(tcpSendBufferSize.getBytes()));
    }

    final ByteSizeValue tcpReceiveBufferSize = TCP_RECEIVE_BUFFER_SIZE.get(settings);
    if (tcpReceiveBufferSize.getBytes() > 0) {
        bootstrap.option(ChannelOption.SO_RCVBUF, Math.toIntExact(tcpReceiveBufferSize.getBytes()));
    }

    bootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);

    final boolean reuseAddress = TCP_REUSE_ADDRESS.get(settings);
    bootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);

    bootstrap.validate();

    return bootstrap;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:31,代碼來源:Netty4Transport.java

示例9: start

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
public static void start(MemberEventLoop loop) throws InterruptedException {
    String host = "127.0.0.1";
    int port = 9005;

    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try {
        Bootstrap b = new Bootstrap();
        b.group(workerGroup);
        b.channel(NioSocketChannel.class);
        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.handler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) throws Exception {

                ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
                ch.pipeline().addLast(new ProtobufDecoder(SocketMessage.getDefaultInstance()));

                ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
                ch.pipeline().addLast(new ProtobufEncoder());

                ch.pipeline().addLast(new IdleStateHandler(0, 5, 10, TimeUnit.SECONDS));
                ch.pipeline().addLast(new BusinessRouterHandler(loop));
            }
        });

        // Start the client.
        ChannelFuture f = b.connect(host, port).sync();

        // Wait until the connection is closed.

        f.channel().closeFuture().sync();

    } finally {
        workerGroup.shutdownGracefully();
    }

}
 
開發者ID:freedompy,項目名稱:commelina,代碼行數:38,代碼來源:NettyClient.java

示例10: setOpts

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
private void setOpts(Bootstrap bootstrap) {
    bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    setUserOpt(bootstrap, ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeout);
    setUserOpt(bootstrap, ChannelOption.TCP_NODELAY, tcpNoDelay);
    setUserOpt(bootstrap, ChannelOption.SO_RCVBUF, soReceiveBufferSize);
    setUserOpt(bootstrap, ChannelOption.SO_SNDBUF, soSendBufferSize);
    setUserOpt(bootstrap, ChannelOption.SO_REUSEADDR, soReuseAddress);
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:10,代碼來源:NettyClient.java

示例11: setUserOpt

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
private <O> void setUserOpt(Bootstrap bootstrap, ChannelOption<O> opt, O value) {
    if (value != null) {
        if (trace) {
            log.trace("Setting option {} = {} [to={}]", opt, value, id());
        }

        bootstrap.option(opt, value);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:10,代碼來源:NettyClient.java

示例12: newPool

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
@Override
protected FastdfsPool newPool(InetSocketAddress addr) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("channel pool created : {}", addr);
    }

    Bootstrap bootstrap = new Bootstrap().channel(NioSocketChannel.class).group(loopGroup);
    bootstrap.remoteAddress(addr);
    bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) connectTimeout);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    return new FastdfsPool(bootstrap, readTimeout, idleTimeout, maxConnPerHost);
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:14,代碼來源:FastdfsPoolGroup.java

示例13: start

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
@Override
public boolean start() {
    boolean result = false;
    do {
        TcpRouteDefinition route = definition.getRoute();

        if(null == route) {
            break;
        }
        if(route.getAddress() == null || route.getAddress().isEmpty()) {
            break;
        }
        if(route.getPort() == -1) {
            break;
        }

        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.channel(inbound.getClass());
            bootstrap.group(inbound.eventLoop());
            bootstrap.handler(new TcpProxyClientChannelInitializer(definition, this));
            bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
            bootstrap.option(ChannelOption.AUTO_READ, false);

            ChannelFuture future = bootstrap.connect(route.getAddress(), route.getPort());
            //forwarder = future.sync().channel();
            outbound = future.channel();
            future.addListener(listener);
        } catch (Exception e) {
            log.error("Failed starting tcp proxy client.", e);
            outbound = null;
            break;
        }
        result = true;
    } while (false);
    return result;
}
 
開發者ID:thebagchi,項目名稱:heimdall-proxy,代碼行數:38,代碼來源:TcpProxyClient.java

示例14: start

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
@Override
public boolean start() {
    boolean result = false;
    do {
        List<HttpRouteDefinition> routes = definition.getRoutes();

        for(HttpRouteDefinition route: routes) {
            if (null == route) {
                break;
            }
            if (route.getInputUrl() == null || route.getInputUrl().isEmpty()) {
                break;
            }
            if (route.getScheme().equals(null)) {
                break;
            }

            try {
                Bootstrap bootstrap = new Bootstrap();
                bootstrap.channel(inbound.getClass());
                bootstrap.group(inbound.eventLoop());
                bootstrap.handler(new HttpProxyClientChannelInitializer(definition, this));
                bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
                bootstrap.option(ChannelOption.AUTO_READ, false);

                ChannelFuture future = bootstrap.connect(route.getHost(), route.getPort());
                //forwarder = future.sync().channel();
                outbound = future.channel();
                future.addListener(listener);
            } catch (Exception e) {
                log.error("Failed starting http proxy client.", e);
                outbound = null;
                break;
            }
        }
        result = true;
    } while (false);
    return result;
}
 
開發者ID:thebagchi,項目名稱:heimdall-proxy,代碼行數:40,代碼來源:HttpProxyClient.java

示例15: connect

import io.netty.bootstrap.Bootstrap; //導入方法依賴的package包/類
public void connect() {
    workerGroup = new NioEventLoopGroup();
    Bootstrap b = new Bootstrap();
    b.group(workerGroup);
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);

    b.handler(new ChannelInitializer<SocketChannel>() {

        @Override protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addFirst(new LoggingHandler(LogLevel.DEBUG));

            ch.pipeline().addLast(new LengthFieldPrepender(4));
            ch.pipeline().addLast(new FrameEncoder());

            ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));

            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {
                @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
                    ByteBuf buf = (ByteBuf) msg;
                    messageHandler.accept(buf);
                }
            });
        }

    });


    ChannelFuture channelFuture = b.connect(host, port).syncUninterruptibly();

    channel = channelFuture.channel();

}
 
開發者ID:PumpkinDB,項目名稱:pumpkindb-java,代碼行數:34,代碼來源:Client.java


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