当前位置: 首页>>代码示例>>Java>>正文


Java ServerBootstrap类代码示例

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


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

示例1: stopInternal

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Override
@SuppressForbidden(reason = "debug")
protected void stopInternal() {
    Releasables.close(serverOpenChannels, () -> {
        final List<Tuple<String, Future<?>>> serverBootstrapCloseFutures = new ArrayList<>(serverBootstraps.size());
        for (final Map.Entry<String, ServerBootstrap> entry : serverBootstraps.entrySet()) {
            serverBootstrapCloseFutures.add(
                Tuple.tuple(entry.getKey(), entry.getValue().config().group().shutdownGracefully(0, 5, TimeUnit.SECONDS)));
        }
        for (final Tuple<String, Future<?>> future : serverBootstrapCloseFutures) {
            future.v2().awaitUninterruptibly();
            if (!future.v2().isSuccess()) {
                logger.debug(
                    (Supplier<?>) () -> new ParameterizedMessage(
                        "Error closing server bootstrap for profile [{}]", future.v1()), future.v2().cause());
            }
        }
        serverBootstraps.clear();

        if (bootstrap != null) {
            bootstrap.config().group().shutdownGracefully(0, 5, TimeUnit.SECONDS).awaitUninterruptibly();
            bootstrap = null;
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:26,代码来源:Netty4Transport.java

示例2: start

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Override
public void start() throws EmbeddedServletContainerException {
    ServerBootstrap b = new ServerBootstrap();
    groups(b);
    servletExecutor = new DefaultEventExecutorGroup(50);
    b.childHandler(new NettyEmbeddedServletInitializer(servletExecutor, context));

    // Don't yet need the complexity of lifecycle state, listeners etc, so tell the context it's initialised here
    context.setInitialised(true);

    ChannelFuture future = b.bind(address).awaitUninterruptibly();
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable cause = future.cause();
    if (null != cause) {
        throw new EmbeddedServletContainerException("Could not start Netty server", cause);
    }
    logger.info(context.getServerInfo() + " started on port: " + getPort());
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:19,代码来源:NettyEmbeddedServletContainer.java

示例3: Server

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
Server(
    AddressResolver addressResolver,
    EventLoopGroup eventLoopGroup,
    boolean customEventLoop,
    Timer timer,
    boolean customTimer,
    long bindTimeoutInNanos,
    StubStore stubStore,
    boolean activityLogging,
    ServerBootstrap serverBootstrap) {
  // custom constructor onyl made to help facilitate testing with a custom bootstrap.
  this.addressResolver = addressResolver;
  this.timer = timer;
  this.customTimer = customTimer;
  this.eventLoopGroup = eventLoopGroup;
  this.customEventLoop = customEventLoop;
  this.serverBootstrap = serverBootstrap;
  this.bindTimeoutInNanos = bindTimeoutInNanos;
  this.stubStore = stubStore;
  this.activityLogging = activityLogging;
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:22,代码来源:Server.java

示例4: start

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
public void start(SlaveNode slaveNode) {
    if(slaveNode==null){
        throw new IllegalArgumentException("slaveNode is null");
    }
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new SlaveServerInitializer());

        ChannelFuture future = b.bind(slaveNode.getPort()).sync();
        LOGGER.info("SlaveServer Startup at port:{}",slaveNode.getPort());

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOGGER.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:27,代码来源:SlaveServer.java

示例5: start

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new ServerInitializer());

        ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
        logger.info("NettyServer Startup at port:{}",CommonConstants.SERVER_PORT);

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        logger.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:24,代码来源:NettyServer.java

示例6: bind

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Override
public void bind(int port) {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);  
    EventLoopGroup workerGroup = new NioEventLoopGroup();  
    ServerBootstrap bootstrap = new ServerBootstrap()
            .group(bossGroup, workerGroup)
            .channel(NioServerSocketChannel.class).localAddress(new InetSocketAddress(8888))
            .childHandler(new ChannelInitializer<SocketChannel>() {

                @Override
                protected void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline().addLast(new Encoder(serializer), new Decoder(serializer), new ProviderHandler());
                }
                
            });
    
    bootstrap.bind(port);
}
 
开发者ID:DanceFirstThinkLater,项目名称:PetiteRPC,代码行数:19,代码来源:NettyAcceptor.java

示例7: start

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Override
public void start() throws Exception {
    try {
        ServerBootstrap b = new ServerBootstrap()
                .group(bossGroup, workGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(serverInitializer);

        logger.info("Starting TcpChatServer... Port: " + port);

        channelFuture = b.bind(port).sync();

    } finally {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                shutdown();
            }
        });
    }
}
 
开发者ID:onsoul,项目名称:os,代码行数:22,代码来源:TcpChatServer.java

示例8: start

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Override
public void start() throws Exception {
    try {
        ServerBootstrap b = new ServerBootstrap()
                .group(bossGroup, workGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(serverInitializer);

        logger.info("Starting WebSocketChatServer... Port: " + port);

        channelFuture = b.bind(port).sync();
    } finally {
        Runtime.getRuntime().addShutdownHook(new Thread() {
            @Override
            public void run() {
                shutdown();
            }
        });
    }
}
 
开发者ID:onsoul,项目名称:os,代码行数:21,代码来源:WebSocketChatServer.java

示例9: main

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
public static void main(String[] args) throws Exception {

        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_REUSEADDR, true)
                .childHandler(new ChannelInitializer<NioSocketChannel>() {
                    @Override
                    protected void initChannel(NioSocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new SimpleServerHandler());
                    }
                });
        b.bind(8090).sync().channel().closeFuture().sync();
    }
 
开发者ID:alamby,项目名称:upgradeToy,代码行数:17,代码来源:SimpleServer.java

示例10: AbstractNettyServer

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
protected AbstractNettyServer(String serverName) {
	this.serverName = Objects.requireNonNull(serverName, "server name");
	bootstrap = new ServerBootstrap();
	if (Epoll.isAvailable()) {
		bootstrap.option(ChannelOption.SO_BACKLOG, 1024).channel(EpollServerSocketChannel.class)
				.childOption(ChannelOption.SO_LINGER, 0).childOption(ChannelOption.SO_REUSEADDR, true)
				.childOption(ChannelOption.SO_KEEPALIVE, true);
		log.info(serverName + " epoll init");
	} else {
		bootstrap.channel(NioServerSocketChannel.class);
		log.info(serverName + " nio init");
	}
	bootstrap.group(bossGroup, workerGroup).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
			.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
			.childOption(ChannelOption.TCP_NODELAY, true).childHandler(new ChannelInitializer<SocketChannel>() {

				@Override
				protected void initChannel(SocketChannel ch) throws Exception {
					initPipeline(ch.pipeline());
				}
			});
}
 
开发者ID:HankXV,项目名称:Limitart,代码行数:23,代码来源:AbstractNettyServer.java

示例11: 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

示例12: start

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
/**
 * 启动服务
 *
 * @throws Exception 异常
 */
public void start() throws Exception {
    try {
        ServerBootstrap bootstrap = new ServerBootstrap();
        bootstrap.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(channelInitializer)
                .option(ChannelOption.SO_BACKLOG, aceServerConfig.getBackSize())
                .childOption(ChannelOption.SO_KEEPALIVE, true)
                .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
        ChannelFuture future = bootstrap.bind(aceServerConfig.getPort()).sync();
        System.out.println("ace server starter on port : " + aceServerConfig.getPort());
        future.channel().closeFuture().sync();
    } finally {
        close();
    }


}
 
开发者ID:ChenXun1989,项目名称:ace,代码行数:24,代码来源:DefaultServer.java

示例13: start

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
@Override
public void start(Config config) throws Exception {
    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();
    int port = config.getPort();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
                .channel(NioServerSocketChannel.class)
                .option(ChannelOption.SO_BACKLOG, 1024)
                .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
                .childHandler(new SocksServerInitializer(config));

        log.info("Socks5 server bind port: {}", port);

        b.bind(port).sync().channel().closeFuture().sync();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:biezhi,项目名称:probe,代码行数:22,代码来源:Socks5ProxyServer.java

示例14: Receiver

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
public Receiver ( final ReceiverHandlerFactory factory, final SocketAddress addr )
{
    this.factory = factory;

    this.bossGroup = new NioEventLoopGroup ();
    this.workerGroup = new NioEventLoopGroup ();
    this.bootstrap = new ServerBootstrap ();
    this.bootstrap.group ( this.bossGroup, this.workerGroup );
    this.bootstrap.channel ( NioServerSocketChannel.class );
    this.bootstrap.option ( ChannelOption.SO_BACKLOG, 5 );
    this.bootstrap.option ( ChannelOption.SO_REUSEADDR, true );
    this.bootstrap.childHandler ( new ChannelInitializer<SocketChannel> () {

        @Override
        protected void initChannel ( final SocketChannel ch ) throws Exception
        {
            handleInitChannel ( ch );
        }
    } );

    this.channel = this.bootstrap.bind ( addr ).channel ();

    logger.info ( "Receiver running ..." );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:Receiver.java

示例15: bindToSslSocket

import io.netty.bootstrap.ServerBootstrap; //导入依赖的package包/类
private ChannelFuture bindToSslSocket()
        throws InterruptedException, CertificateException, UnrecoverableKeyException, NoSuchAlgorithmException,
        KeyStoreException, KeyManagementException, IOException {
    String hostname = configuration.getHostName();
    int port = Integer.parseInt(configuration.getSsl().getPort());

    ServerBootstrap b = new ServerBootstrap();
    b.group(bossGroup, workerGroup)
     .channel(NioServerSocketChannel.class)
     .childHandler(new SslSocketChannelInitializer(ioExecutors, new SslHandlerFactory(configuration)))
     .option(ChannelOption.SO_BACKLOG, 128)
     .childOption(ChannelOption.SO_KEEPALIVE, true);

    // Bind and start to accept incoming connections.
    ChannelFuture future = b.bind(hostname, port).sync();
    LOGGER.info("Listening AMQP/" + configuration.getSsl().getProtocol() + " on " + hostname + ":" + port);
    return future;
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:19,代码来源:Server.java


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