當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。