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


Java ServerBootstrap.childOption方法代碼示例

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


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

示例1: openServer

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
@Override
public void openServer(URL url) throws Exception{
    EventLoopGroup eventLoop = new NioEventLoopGroup();
    EventLoopGroup workLoop = new NioEventLoopGroup();
    serverBootstrap = new ServerBootstrap();
    serverBootstrap.group(eventLoop, workLoop);
    serverBootstrap.channel(NioServerSocketChannel.class);
    serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
    serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>(){

        @Override
        protected void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline()
                    .addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(getClass().getClassLoader()))) // in 1
                    .addLast("handler", new ServerHandler()) // in 2
                    .addLast("encoder", new ObjectEncoder()); // out 3

        }
    });
    serverChannel = serverBootstrap.bind(url.getPort()).sync().sync().channel();
    logger.info("start server at:" + url.getPort());
}
 
開發者ID:justice-code,項目名稱:star-map,代碼行數:23,代碼來源:StarServerProtocol.java

示例2: doOpen

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void doOpen() throws InterruptedException {
    EventLoopGroup bossGroup = new NioEventLoopGroup();
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    try{
        ServerBootstrap serverBootstrap = new ServerBootstrap();
        serverBootstrap.group(bossGroup,workerGroup);
        serverBootstrap.channel(NioServerSocketChannel.class);
        serverBootstrap.childHandler(new ChannelInitializer<SocketChannel>() {
            protected void initChannel(SocketChannel socketChannel) throws Exception {
                ChannelPipeline pipeline = socketChannel.pipeline();
                pipeline.addLast(new ObjectDecoder(1024*1024, ClassResolvers.weakCachingConcurrentResolver(this.getClass().getClassLoader())));
                pipeline.addLast(new ObjectEncoder());
                pipeline.addLast((SimpleChannelInboundHandler)handler);
            }
        });
        serverBootstrap.option(ChannelOption.SO_BACKLOG,1024);
        serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE,true);
        ChannelFuture future = serverBootstrap.bind(address,port).sync();
        //future.channel().closeFuture().sync();
    }finally{
        //workerGroup.shutdownGracefully();
        //bossGroup.shutdownGracefully();
    }
}
 
開發者ID:dachengxi,項目名稱:mini-dubbo,代碼行數:25,代碼來源:NettyServer.java

示例3: startAcceptingConnections

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();
    b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.SO_RCVBUF, 1048576);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.group(serverGroup, clientGroup);
    b.channel(serverChannelClass);
    if (enableNettyTls) {
        b.childHandler(new SslServerCommunicationChannelInitializer());
    } else {
        b.childHandler(new OnosCommunicationChannelInitializer());
    }
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);

    // Bind and start to accept incoming connections.
    b.bind(localEp.port()).sync().addListener(future -> {
        if (future.isSuccess()) {
            log.info("{} accepting incoming connections on port {}", localEp.host(), localEp.port());
        } else {
            log.warn("{} failed to bind to port {}", localEp.host(), localEp.port(), future.cause());
        }
    });
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:NettyMessagingManager.java

示例4: setChildOpts

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
private void setChildOpts(ServerBootstrap boot) {
    boot.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

    setChildUserOpt(boot, ChannelOption.TCP_NODELAY, tcpNoDelay);
    setChildUserOpt(boot, ChannelOption.SO_RCVBUF, soReceiveBufferSize);
    setChildUserOpt(boot, ChannelOption.SO_SNDBUF, soSendBuffer);
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:8,代碼來源:NettyServer.java

示例5: setChildUserOpt

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
private <O> void setChildUserOpt(ServerBootstrap boot, ChannelOption<O> opt, O value) {
    if (value != null) {
        if (DEBUG) {
            log.debug("Setting option {} = {} [address={}]", opt, value, address);
        }

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

示例6: startSocket

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void startSocket() throws InterruptedException {
    EventLoopGroup boss = new NioEventLoopGroup();
    EventLoopGroup worker = new NioEventLoopGroup();

    try {
        ServerBootstrap boot = new ServerBootstrap();
        boot.group(boss,worker);

        boot.channel(NioServerSocketChannel.class);
        boot.childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            protected void initChannel(SocketChannel ch) throws Exception {
                ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(1024*1024,0,4,-4,0,false));
                ch.pipeline().addLast(new ByteToPacketCodec());
                //ch.pipeline().addLast(new LoginChannelHandler(listener));
                ch.pipeline().addLast(new PacketChannelHandler(listener));
            }
        });

        boot.option(ChannelOption.SO_BACKLOG,128);
        boot.childOption(ChannelOption.SO_KEEPALIVE,true);
        channelFuture = boot.bind(port).sync();
        System.out.println("服務器"+port+"開啟成功...");
        channelFuture.channel().closeFuture().sync();
    }finally {
        boss.shutdownGracefully().sync();
        worker.shutdownGracefully().sync();
        channelFuture = null;
        System.out.println("服務器關閉成功...");
    }
}
 
開發者ID:werewolfKill,項目名稱:werewolf_server,代碼行數:32,代碼來源:ThreadServerSocket.java

示例7: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void start() throws Exception {
    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(boss, worker);
        bootstrap.channel(NioServerSocketChannel.class);
        bootstrap.handler(new LoggingHandler(LogLevel.INFO));
        bootstrap.childHandler(ProxyServerChannelInitializerFactory.getChannelInitializer(definition));
        bootstrap.childOption(ChannelOption.AUTO_READ, false);
        bootstrap.childOption(ChannelOption.SO_KEEPALIVE, true);
        server = bootstrap.bind(port).sync().channel();
        log.info("Started proxy server at port: " + port);
    } catch (Exception e) {
        log.error(String.format("Failed starting proxy server at port: %d", port), e);
    }
}
 
開發者ID:thebagchi,項目名稱:heimdall-proxy,代碼行數:16,代碼來源:TcpProxyServer.java

示例8: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
/**
 * Starts the network for a {@link Server}.
 * 
 * @param server The {@link Server} to use for building the network.
 * @return <True> If the network started successfully.
 */
public static void start() {
	EventLoopGroup boss = new NioEventLoopGroup();
	EventLoopGroup worker = new NioEventLoopGroup();
	ServerBootstrap bootstrap = new ServerBootstrap();

	bootstrap.group(boss, worker);
	bootstrap.channel(NioServerSocketChannel.class);
	bootstrap.childHandler(new ChannelInitializer<SocketChannel>() {

		@Override
		protected void initChannel(SocketChannel ch) throws Exception {
			ChannelPipeline pipeline = ch.pipeline();

			pipeline.addLast("decoder", new ConnectionDecoder());
			pipeline.addLast("encoder", new ConnectionEncoder());
			pipeline.addLast("adapter", new NetworkMessageHandler());
		}

	});
	bootstrap.childOption(ChannelOption.TCP_NODELAY, true);

	try {
		bootstrap.bind(Constants.HOST_NAME, Constants.HOST_PORT).sync();
	} catch (InterruptedException e) {
		e.printStackTrace();
	}

	System.out.println("Server successfully bootstrapped on port " + Constants.HOST_PORT + " and address " + Constants.HOST_NAME + ".");
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:36,代碼來源:NetworkExecutor.java

示例9: startAcceptingConnections

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
/**
 * Accepts incoming connections.
 */
private void startAcceptingConnections() throws InterruptedException {
    ServerBootstrap b = new ServerBootstrap();

    b.group(bossGroup, workerGroup).channel(serverChannelClass)
            .childHandler(new OnosCommunicationChannelInitializer());
    b.option(ChannelOption.SO_BACKLOG, 128);
    b.option(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
    b.option(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.childOption(ChannelOption.SO_KEEPALIVE, true);
    b.bind(ovsdbPort).sync();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:16,代碼來源:Controller.java

示例10: run

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
public void run() {
	ServerBootstrap b = new ServerBootstrap();// 引導輔助程序

	bossGroup = new NioEventLoopGroup(BIZGROUPSIZE);
	workerGroup = new NioEventLoopGroup(BIZTHREADSIZE);
	try {
		b.group(bossGroup, workerGroup);
		b.channel(NioServerSocketChannel.class);// 設置nio類型的channel
		b.childHandler(new ChannelInitializer<SocketChannel>() {// 有連接到達時會創建一個channel
			protected void initChannel(SocketChannel ch) throws Exception {
				logger.debug("客戶端:{} 初始化", ch.remoteAddress());
				// pipeline管理channel中的Handler,在channel隊列中添加一個handler來處理業務
				ch.pipeline().addLast("frameDecoder",
						new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
				ch.pipeline().addLast("frameEncoder", new LengthFieldPrepender(4));
				ch.pipeline().addLast("decoder", msgPackDecode);
				ch.pipeline().addLast("encoder", msgPackEncode);
				ch.pipeline().addLast(serverHandler);
			}
		});
		b.option(ChannelOption.SO_BACKLOG, 128);
		b.childOption(ChannelOption.SO_KEEPALIVE, true);
		logger.info("server start : {}", port);
		ChannelFuture f = b.bind(port).sync();// 配置完成,開始綁定server,通過調用sync同步方法阻塞直到綁定成功
		channel = f.channel();
		f.channel().closeFuture().sync();// 應用程序會一直等待,直到channel關閉
	} catch (Exception e) {
		e.printStackTrace();
	}

}
 
開發者ID:ctodb,項目名稱:push,代碼行數:32,代碼來源:MgsServer.java

示例11: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
@Override
public void start() {
    this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(//
        nettyServerConfig.getServerWorkerThreads(), //
        new ThreadFactory() {

            private AtomicInteger threadIndex = new AtomicInteger(0);


            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "NettyServerWorkerThread_" + this.threadIndex.incrementAndGet());
            }
        });

    ServerBootstrap childHandler = //
            this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupWorker)
                .channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 1024)
                .option(ChannelOption.SO_REUSEADDR, true).childOption(ChannelOption.TCP_NODELAY, true)
                .childOption(ChannelOption.SO_SNDBUF, NettySystemConfig.SocketSndbufSize)
                .childOption(ChannelOption.SO_RCVBUF, NettySystemConfig.SocketRcvbufSize)
                .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort()))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(
                            //
                            defaultEventExecutorGroup, //
                            encoder, //
                            decoder, //
                            new IdleStateHandler(0, 0, nettyServerConfig
                                .getServerChannelMaxIdleTimeSeconds()),//
                            new NettyConnetManageHandler(), //
                            handler);
                    }
                });

    if (NettySystemConfig.NettyPooledByteBufAllocatorEnable) {
        childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    }

    try {
        ChannelFuture sync = this.serverBootstrap.bind().sync();
        InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress();
        this.port = addr.getPort();
    }
    catch (InterruptedException e1) {
        throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1);
    }

    // 每隔1秒掃描下異步調用超時情況
    this.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            try {
                NettyRemotingServer.this.scanResponseTable();
            }
            catch (Exception e) {
                log.error("scanResponseTable exception", e);
            }
        }
    }, 1000 * 3, 1000);
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:65,代碼來源:NettyRemotingServer.java

示例12: doStart

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
@Override
protected void doStart() {
    boolean success = false;
    try {
        this.serverOpenChannels = new Netty4OpenChannelsHandler(logger);

        serverBootstrap = new ServerBootstrap();

        serverBootstrap.group(new NioEventLoopGroup(workerCount, daemonThreadFactory(settings,
            HTTP_SERVER_WORKER_THREAD_NAME_PREFIX)));
        serverBootstrap.channel(NioServerSocketChannel.class);

        serverBootstrap.childHandler(configureServerChannelHandler());

        serverBootstrap.childOption(ChannelOption.TCP_NODELAY, SETTING_HTTP_TCP_NO_DELAY.get(settings));
        serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, SETTING_HTTP_TCP_KEEP_ALIVE.get(settings));

        final ByteSizeValue tcpSendBufferSize = SETTING_HTTP_TCP_SEND_BUFFER_SIZE.get(settings);
        if (tcpSendBufferSize.getBytes() > 0) {
            serverBootstrap.childOption(ChannelOption.SO_SNDBUF, Math.toIntExact(tcpSendBufferSize.getBytes()));
        }

        final ByteSizeValue tcpReceiveBufferSize = SETTING_HTTP_TCP_RECEIVE_BUFFER_SIZE.get(settings);
        if (tcpReceiveBufferSize.getBytes() > 0) {
            serverBootstrap.childOption(ChannelOption.SO_RCVBUF, Math.toIntExact(tcpReceiveBufferSize.getBytes()));
        }

        serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
        serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);

        final boolean reuseAddress = SETTING_HTTP_TCP_REUSE_ADDRESS.get(settings);
        serverBootstrap.option(ChannelOption.SO_REUSEADDR, reuseAddress);
        serverBootstrap.childOption(ChannelOption.SO_REUSEADDR, reuseAddress);

        this.boundAddress = createBoundHttpAddress();
        if (logger.isInfoEnabled()) {
            logger.info("{}", boundAddress);
        }
        success = true;
    } finally {
        if (success == false) {
            doStop(); // otherwise we leak threads since we never moved to started
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:46,代碼來源:Netty4HttpServerTransport.java

示例13: createServerBootstrap

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
private void createServerBootstrap(String name, Settings settings) {
    if (logger.isDebugEnabled()) {
        logger.debug("using profile[{}], worker_count[{}], port[{}], bind_host[{}], publish_host[{}], compress[{}], "
                + "connect_timeout[{}], connections_per_node[{}/{}/{}/{}/{}], receive_predictor[{}->{}]",
            name, workerCount, settings.get("port"), settings.get("bind_host"), settings.get("publish_host"), compress,
            defaultConnectionProfile.getConnectTimeout(),
            defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.RECOVERY),
            defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.BULK),
            defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.REG),
            defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.STATE),
            defaultConnectionProfile.getNumConnectionsPerType(TransportRequestOptions.Type.PING),
            receivePredictorMin, receivePredictorMax);
    }

    final ThreadFactory workerFactory = daemonThreadFactory(this.settings, TRANSPORT_SERVER_WORKER_THREAD_NAME_PREFIX, name);

    final ServerBootstrap serverBootstrap = new ServerBootstrap();

    serverBootstrap.group(new NioEventLoopGroup(workerCount, workerFactory));
    serverBootstrap.channel(NioServerSocketChannel.class);

    serverBootstrap.childHandler(getServerChannelInitializer(name, settings));

    serverBootstrap.childOption(ChannelOption.TCP_NODELAY, TCP_NO_DELAY.get(settings));
    serverBootstrap.childOption(ChannelOption.SO_KEEPALIVE, TCP_KEEP_ALIVE.get(settings));

    final ByteSizeValue tcpSendBufferSize = TCP_SEND_BUFFER_SIZE.getDefault(settings);
    if (tcpSendBufferSize != null && tcpSendBufferSize.getBytes() > 0) {
        serverBootstrap.childOption(ChannelOption.SO_SNDBUF, Math.toIntExact(tcpSendBufferSize.getBytes()));
    }

    final ByteSizeValue tcpReceiveBufferSize = TCP_RECEIVE_BUFFER_SIZE.getDefault(settings);
    if (tcpReceiveBufferSize != null && tcpReceiveBufferSize.getBytes() > 0) {
        serverBootstrap.childOption(ChannelOption.SO_RCVBUF, Math.toIntExact(tcpReceiveBufferSize.bytesAsInt()));
    }

    serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);
    serverBootstrap.childOption(ChannelOption.RCVBUF_ALLOCATOR, recvByteBufAllocator);

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

    serverBootstrap.validate();

    serverBootstraps.put(name, serverBootstrap);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:48,代碼來源:Netty4Transport.java

示例14: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
@Override
public void start() {
    this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(
        nettyServerConfig.getServerWorkerThreads(),
        new ThreadFactory() {

            private AtomicInteger threadIndex = new AtomicInteger(0);

            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet());
            }
        });

    //netty 服務端
    ServerBootstrap childHandler =
        this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector)
             //這裏指定EpollServerSocketChannel或者NioServerSocketChannel類初始化channel用來接受客戶端請求。
            .channel(useEpoll() ? EpollServerSocketChannel.class : NioServerSocketChannel.class) 
            .option(ChannelOption.SO_BACKLOG, 1024)
            .option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.SO_KEEPALIVE, false)
            .childOption(ChannelOption.TCP_NODELAY, true)
            .childOption(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize())
            .childOption(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize())
            .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort())) //前麵有設置nettyServerConfig.setListenPort(9876)操作
            //通常會為新SocketChannel通過添加一些handler,來設置ChannelPipeline。ChannelInitializer 是一個特殊的handler,其中initChannel方法可以為SocketChannel 的pipeline添加指定handler。
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                public void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(
                        defaultEventExecutorGroup,
                        new NettyEncoder(),  //編碼
                        new NettyDecoder(),  //解碼
                        new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()), //心跳檢查
                        new NettyConnectManageHandler(),
                        new NettyServerHandler());
                }
            });

    if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) {
    	// 這個選項有可能會占用大量堆外內存,暫時不使用。
        childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    }

    try {
        ChannelFuture sync = this.serverBootstrap.bind().sync();//通過綁定,就可以對外提供服務了。
        InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress();
        this.port = addr.getPort();
        
        //奇怪為什麽沒有關閉???? 類似這樣的  sync.channel().closeFuture().sync();
    } catch (InterruptedException e1) {
        throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1);
    }

    if (this.channelEventListener != null) {
        this.nettyEventExecutor.start();
    }
    // 每隔1秒掃描下異步調用超時情況
    this.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            try {
                NettyRemotingServer.this.scanResponseTable();
            } catch (Exception e) {
                log.error("scanResponseTable exception", e);
            }
        }
    }, 1000 * 3, 1000);
}
 
開發者ID:lirenzuo,項目名稱:rocketmq-rocketmq-all-4.1.0-incubating,代碼行數:72,代碼來源:NettyRemotingServer.java

示例15: start

import io.netty.bootstrap.ServerBootstrap; //導入方法依賴的package包/類
@Override
public void start() {
    this.defaultEventExecutorGroup = new DefaultEventExecutorGroup(//
        nettyServerConfig.getServerWorkerThreads(), //
        new ThreadFactory() {

            private AtomicInteger threadIndex = new AtomicInteger(0);


            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "NettyServerCodecThread_" + this.threadIndex.incrementAndGet());
            }
        });

    ServerBootstrap childHandler = //
            this.serverBootstrap.group(this.eventLoopGroupBoss, this.eventLoopGroupSelector).channel(NioServerSocketChannel.class)
                //
                .option(ChannelOption.SO_BACKLOG, 1024)
                //
                .option(ChannelOption.SO_REUSEADDR, true)
                //
                .option(ChannelOption.SO_KEEPALIVE, false)
                //
                .childOption(ChannelOption.TCP_NODELAY, true)
                //
                .option(ChannelOption.SO_SNDBUF, nettyServerConfig.getServerSocketSndBufSize())
                //
                .option(ChannelOption.SO_RCVBUF, nettyServerConfig.getServerSocketRcvBufSize())
                //
                .localAddress(new InetSocketAddress(this.nettyServerConfig.getListenPort()))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(
                        //
                            defaultEventExecutorGroup, //
                            new NettyEncoder(), //
                            new NettyDecoder(), //
                            new IdleStateHandler(0, 0, nettyServerConfig.getServerChannelMaxIdleTimeSeconds()),//
                            new NettyConnetManageHandler(), //
                            new NettyServerHandler());
                    }
                });

    if (nettyServerConfig.isServerPooledByteBufAllocatorEnable()) {
        childHandler.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    }

    try {
        ChannelFuture sync = this.serverBootstrap.bind().sync();
        InetSocketAddress addr = (InetSocketAddress) sync.channel().localAddress();
        this.port = addr.getPort();
    }
    catch (InterruptedException e1) {
        throw new RuntimeException("this.serverBootstrap.bind().sync() InterruptedException", e1);
    }

    if (this.channelEventListener != null) {
        this.nettyEventExecuter.start();
    }

    this.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            try {
                NettyRemotingServer.this.scanResponseTable();
            }
            catch (Exception e) {
                log.error("scanResponseTable exception", e);
            }
        }
    }, 1000 * 3, 1000);
}
 
開發者ID:y123456yz,項目名稱:reading-and-annotate-rocketmq-3.4.6,代碼行數:76,代碼來源:NettyRemotingServer.java


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