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


Java EpollServerSocketChannel类代码示例

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


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

示例1: initEventLoopGroup

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
private void initEventLoopGroup() {
    // try Epoll first and if that does work, use nio.
    try {
        clientGroup = new EpollEventLoopGroup();
        serverGroup = new EpollEventLoopGroup();
        serverChannelClass = EpollServerSocketChannel.class;
        clientChannelClass = EpollSocketChannel.class;
        return;
    } catch (Throwable t) {
        log.warn("Failed to initialize native (epoll) transport. Reason: {}. Proceeding with nio.", t.getMessage());
    }
    clientGroup = new NioEventLoopGroup();
    serverGroup = new NioEventLoopGroup();
    serverChannelClass = NioServerSocketChannel.class;
    clientChannelClass = NioSocketChannel.class;
}
 
开发者ID:ravikumaran2015,项目名称:ravikumaran201504,代码行数:17,代码来源:NettyMessagingService.java

示例2: AbstractNettyServer

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的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

示例3: PluginGrpcServer

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
public PluginGrpcServer(int port) {
    this.pluginConnections = new HashMap<>();

    PlayerEvents playerEvents = new PlayerEvents(this);

    this.server = NettyServerBuilder.forPort(port)
            .keepAliveTime(1, TimeUnit.MINUTES)
            .keepAliveTimeout(5, TimeUnit.SECONDS)

            .addService(playerEvents)

            .directExecutor()
            .channelType(EpollServerSocketChannel.class)
            .bossEventLoopGroup(new EpollEventLoopGroup())
            .workerEventLoopGroup(new EpollEventLoopGroup())
            .build();

    // demoPluginConnections();
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:20,代码来源:PluginGrpcServer.java

示例4: start

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
public void start() throws Exception {
    UnknownPandaServer.getLogger().info("Loading protocol");
    Protocol protocol = ProtocolSpecification.getProtocol();
    protocol.load();

    UnknownPandaServer.getLogger().info("Binding UniverseServer at *::" + port + " [tcp]");
    this.channel = new ServerBootstrap()
            .group(Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup())
            .channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            //.childOption(ChannelOption.TCP_NODELAY, true)
            .childHandler(new ConnectionInitializer(this))
            .localAddress("", port)
            .bind()
            .addListeners(this)
            .sync()
            .channel();
}
 
开发者ID:dzikoysk,项目名称:UnknownPandaServer,代码行数:18,代码来源:ConnectionProvider.java

示例5: groups

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
private void groups(ServerBootstrap b) {
    if (StandardSystemProperty.OS_NAME.value().equals("Linux")) {
        bossGroup = new EpollEventLoopGroup(1);
        workerGroup = new EpollEventLoopGroup();
        b.channel(EpollServerSocketChannel.class)
                .group(bossGroup, workerGroup)
                .option(EpollChannelOption.TCP_CORK, true);
    } else {
        bossGroup = new NioEventLoopGroup(1);
        workerGroup = new NioEventLoopGroup();
        b.channel(NioServerSocketChannel.class)
                .group(bossGroup, workerGroup);
    }
    b.option(ChannelOption.TCP_NODELAY, true)
            .option(ChannelOption.SO_REUSEADDR, true)
            .option(ChannelOption.SO_BACKLOG, 100);
    logger.info("Bootstrap configuration: " + b.toString());
}
 
开发者ID:paullyphang,项目名称:nebo,代码行数:19,代码来源:NettyEmbeddedServletContainer.java

示例6: run

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
public void run() throws Exception {
    ServerBootstrap b = new ServerBootstrap();
    try {
        if (isEpollAvailable) {
            b.group(new EpollEventLoopGroup(this.conf.getEventLoopThreadCount()))
             .channel(EpollServerSocketChannel.class);
        } else {
            b.group(new NioEventLoopGroup(this.conf.getEventLoopThreadCount()))
             .channel(NioServerSocketChannel.class);
        }
        b.childHandler(new DefaultServerInitializer(conf, context))
         .option(ChannelOption.SO_BACKLOG, conf.getBacklog())
         .option(ChannelOption.SO_REUSEADDR, true);

        Channel ch = b.bind(conf.getPort()).sync().channel();
        ch.closeFuture().sync();
    } finally {

    }
}
 
开发者ID:compasses,项目名称:elastic-rabbitmq,代码行数:21,代码来源:HttpServerBoot.java

示例7: init

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@Override
public void init(final InetAddress address, final int port, final boolean useEpoll)
{
    final Class<? extends ServerSocketChannel> socketChannelClass;
    final LazyValue<? extends EventLoopGroup> lazyInit;
    if ((Epoll.isAvailable()) && useEpoll)
    {
        socketChannelClass = EpollServerSocketChannel.class;
        lazyInit = this.epollEventLoopGroupLazyValue;
        CoreMain.debug("[Netty] Using epoll channel type");
    }
    else
    {
        socketChannelClass = NioServerSocketChannel.class;
        lazyInit = this.nioEventLoopGroupLazyValue;
        CoreMain.debug("[Netty] Using default channel type");
    }
    this.channelFuture = new ServerBootstrap().channel(socketChannelClass).childHandler(new ServerConnectionChannel(this)).group(lazyInit.get()).localAddress(address, port).bind().syncUninterruptibly();
}
 
开发者ID:Diorite,项目名称:Diorite-old,代码行数:20,代码来源:ServerConnection.java

示例8: initialise

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@Override
public void initialise(NetworkChannelHandler channelHandler) {
    this.channelHandler = channelHandler;

    final boolean useEpoll = this.configuration.getBoolean("epoll") && Epoll.isAvailable();

    EventLoopGroup acceptGroup = useEpoll ? new EpollEventLoopGroup(this.configuration.getInt("acceptGroup")) :
            new NioEventLoopGroup(this.configuration.getInt("acceptGroup"));

    EventLoopGroup ioGroup = useEpoll ? new EpollEventLoopGroup(this.configuration.getInt("ioGroup")) :
            new NioEventLoopGroup(this.configuration.getInt("ioGroup"));

    EventLoopGroup channelGroup = useEpoll ? new EpollEventLoopGroup(this.configuration.getInt("channelGroup")) :
            new NioEventLoopGroup(this.configuration.getInt("channelGroup"));

    this.serverBootstrap = new ServerBootstrap()
            .group(acceptGroup, ioGroup)
            .channel(useEpoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            .childHandler(new ChannelInitialiser(channelGroup, this.channelHandler, null))
            .option(ChannelOption.SO_BACKLOG, this.configuration.getInt("backlog"))
            .option(ChannelOption.TCP_NODELAY, true)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .option(ChannelOption.MESSAGE_SIZE_ESTIMATOR, DefaultMessageSizeEstimator.DEFAULT)
            .childOption(ChannelOption.TCP_NODELAY, this.configuration.getBoolean("tcpNoDelay"))
            .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
}
 
开发者ID:LeonHartley,项目名称:Coerce,代码行数:27,代码来源:NettyNetworkingService.java

示例9: bind

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@Override
public boolean bind() {
    ChannelFuture future = new ServerBootstrap()
            .channel(Epoll.isAvailable() ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
            .group(group)
            .childHandler(this)
            .bind(server.getConfiguration().getRcon().getHost(), server.getConfiguration().getRcon().getPort())
            .awaitUninterruptibly();

    if (future.isSuccess()) {
        this.channel = future.channel();
        return true;
    }

    return false;
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:18,代码来源:RconNetworkListener.java

示例10: main

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    EventLoopGroup bossGroup = new EpollEventLoopGroup(1);
    EventLoopGroup workerGroup = new EpollEventLoopGroup();
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup)
         .channel(EpollServerSocketChannel.class)
         .childHandler(new ChannelInitializer<SocketChannel>() {
            @Override
            public void initChannel(SocketChannel ch) {
                ChannelPipeline p = ch.pipeline();
                p.addLast(new EchoServerHandler());
            }
        });

        ChannelFuture f = b.bind(8888).sync();

        f.channel().closeFuture().sync();
    }
    finally {
        workerGroup.shutdownGracefully();
        bossGroup.shutdownGracefully();
    }
}
 
开发者ID:krisjey,项目名称:netty.book.kor,代码行数:25,代码来源:EpollEchoServer.java

示例11: initChannel

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
public void initChannel() throws Exception {
	bossGroup = new EpollEventLoopGroup();
	workerGroup = new EpollEventLoopGroup(pushListenerWorkerNum,
			new ThreadFactoryWithName(NettyPushListener.class));
	serverBootstarp = new ServerBootstrap()
			.group(bossGroup, workerGroup)
			.channel(EpollServerSocketChannel.class)
			.option(ChannelOption.SO_TIMEOUT, sockTimout)
			.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
			.option(ChannelOption.TCP_NODELAY, true)
			.childOption(ChannelOption.ALLOCATOR,
					PooledByteBufAllocator.DEFAULT)
			.childOption(ChannelOption.TCP_NODELAY, true)
			.childHandler(pushListenerChannelInitializer);

	serverBootstarp.bind(port).sync();

	logger.info("Netty TCP Push Listener nio provider: {} with {} workers", serverBootstarp
			.getClass().getCanonicalName(), pushListenerWorkerNum);
}
 
开发者ID:taojiaenx,项目名称:taojiane_push,代码行数:21,代码来源:NettyPushListener.java

示例12: createBootstrap

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
@Override
    public ServerBootstrap createBootstrap() {
        bootstrap = new ServerBootstrap();
        if (isEpollAvailable) {
            this.parentGroup = new EpollEventLoopGroup();
            this.childGroup = new EpollEventLoopGroup();
            bootstrap.channel(EpollServerSocketChannel.class);
        } else {
            this.parentGroup = new NioEventLoopGroup();
            this.childGroup = new NioEventLoopGroup();
            bootstrap.channel(NioServerSocketChannel.class);
        }
        bootstrap.group(parentGroup(), childGroup());
        bootstrap.childHandler(newChannelInitializer());

        bootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
//        bootstrap.option(ChannelOption.SO_REUSEADDR, true);
//        bootstrap.childOption(ChannelOption.TCP_NODELAY, true);
        bootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);

        return bootstrap;
    }
 
开发者ID:ogcs,项目名称:Okra,代码行数:23,代码来源:TcpProtocolServer.java

示例13: initEventLoopGroup

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
private void initEventLoopGroup() {
  // try Epoll first and if that does work, use nio.
  try {
    clientGroup = new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-client-%d", log));
    serverGroup = new EpollEventLoopGroup(0, namedThreads("netty-messaging-event-epoll-server-%d", log));
    serverChannelClass = EpollServerSocketChannel.class;
    clientChannelClass = EpollSocketChannel.class;
    return;
  } catch (Throwable e) {
    log.debug("Failed to initialize native (epoll) transport. "
        + "Reason: {}. Proceeding with nio.", e.getMessage());
  }
  clientGroup = new NioEventLoopGroup(0, namedThreads("netty-messaging-event-nio-client-%d", log));
  serverGroup = new NioEventLoopGroup(0, namedThreads("netty-messaging-event-nio-server-%d", log));
  serverChannelClass = NioServerSocketChannel.class;
  clientChannelClass = NioSocketChannel.class;
}
 
开发者ID:atomix,项目名称:atomix,代码行数:18,代码来源:NettyMessagingService.java

示例14: createServerBootstrap

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
private synchronized ServerBootstrap createServerBootstrap(final ChannelPipelineInitializer initializer) {
    final ServerBootstrap serverBootstrap = new ServerBootstrap();
    if (Epoll.isAvailable()) {
        serverBootstrap.channel(EpollServerSocketChannel.class);
        serverBootstrap.childOption(EpollChannelOption.EPOLL_MODE, EpollMode.LEVEL_TRIGGERED);
    } else {
        serverBootstrap.channel(NioServerSocketChannel.class);
    }
    final ChannelHandler serverChannelHandler = BGPChannel.createServerChannelHandler(initializer);
    serverBootstrap.childHandler(serverChannelHandler);

    serverBootstrap.option(ChannelOption.SO_BACKLOG, SOCKET_BACKLOG_SIZE);
    serverBootstrap.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    serverBootstrap.childOption(ChannelOption.WRITE_BUFFER_WATER_MARK, WATER_MARK);

    // Make sure we are doing round-robin processing
    serverBootstrap.option(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(FIX_BUFFER_SIZE));

    if (serverBootstrap.config().group() == null) {
        serverBootstrap.group(this.bossGroup, this.workerGroup);
    }
    return serverBootstrap;
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:24,代码来源:BGPDispatcherImpl.java

示例15: addEndpoint

import io.netty.channel.epoll.EpollServerSocketChannel; //导入依赖的package包/类
public static void addEndpoint(final SocketAddress address){
    ServerBootstrap bootstrap = new ServerBootstrap();
    if(epollSupported && !disableEpoll){
        bootstrap.channel(EpollServerSocketChannel.class);
    }else{
        bootstrap.channel(NioServerSocketChannel.class);
    }
    bootstrap.localAddress(address);
    bootstrap.childHandler(NettyChannelInitializer.INSTANCE);
    bootstrap.group(workers);
    logger.info("Opening endpoint " + address.toString());
    bootstrap.bind().syncUninterruptibly().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future){
            endpoints.add(future.channel());
            logger.info("Endpoint " + address.toString() + " started");
        }
    });
}
 
开发者ID:nailed,项目名称:nailed,代码行数:20,代码来源:NailedNetworkManager.java


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