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


Java Epoll类代码示例

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


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

示例1: start

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
public void start() throws InterruptedException {
	final EventLoopGroup workerGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();

	try {
		Bootstrap bootstrap = new Bootstrap();
		bootstrap.group(workerGroup)
				.channel(Epoll.isAvailable() ? EpollSocketChannel.class : NioSocketChannel.class)
				.handler(new OpenCloudChannelInitializer(this))
				.connect(this.host, this.port).sync().channel().closeFuture().syncUninterruptibly();
	} catch (Exception ex) {
		if (ex.getClass().getSimpleName().equals("AnnotatedConnectException")) {
			System.err.println("Cannot connect to master!");
			channel.close();
		} else {
			ex.printStackTrace();
		}
	} finally {
		workerGroup.shutdownGracefully();
		System.out.println("Netty client stopped");
		Runtime.getRuntime().halt(0);
	}
}
 
开发者ID:CentauriCloud,项目名称:CentauriCloud,代码行数:23,代码来源:Client.java

示例2: AbstractNettyServer

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

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

示例4: initialize

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
/**
 * Initializes this socket and binds its internal udp socket to a free port.
 * If the socket is already initialized any invocation of this method will
 * result in an IllegalStateException.
 *
 * @throws SocketException Thrown in case the socket could not be initialized
 */
public void initialize() throws SocketException {
    if ( this.isInitialized() ) {
        throw new IllegalStateException( "Cannot re-initialized ClientSocket" );
    }

    this.udpSocket = new Bootstrap();
    this.udpSocket.group( Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup() );
    this.udpSocket.channel( Epoll.isAvailable() ? EpollDatagramChannel.class : NioDatagramChannel.class );
    this.udpSocket.handler( new ChannelInboundHandlerAdapter() {
        @Override
        public void channelRead( ChannelHandlerContext ctx, Object msg ) throws Exception {
            io.netty.channel.socket.DatagramPacket packet = (io.netty.channel.socket.DatagramPacket) msg;
            PacketBuffer content = new PacketBuffer( packet.content() );
            InetSocketAddress sender = packet.sender();

            if ( !receiveDatagram( sender, content ) ) {
                // Push datagram to update queue:
                handleDatagram( sender, content, System.currentTimeMillis() );
            }
        }
    } );

    try {
        this.channel = this.udpSocket.bind( ThreadLocalRandom.current().nextInt( 45000, 65000 ) ).sync().channel();
    } catch ( InterruptedException e ) {
        SocketException exception = new SocketException( "Could not bind to socket" );
        exception.initCause( e );
        throw exception;
    }

    this.afterInitialize();
}
 
开发者ID:GoMint,项目名称:jRakNet,代码行数:40,代码来源:ClientSocket.java

示例5: init

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

示例6: init

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

示例7: connect

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
public void connect(String apiKey) {
  Bootstrap bootstrap = new Bootstrap();
  Class<? extends Channel> channelClazz;

  if (Epoll.isAvailable()) {
    channelClazz = EpollSocketChannel.class;
    eventLoopGroup = new EpollEventLoopGroup();
  } else {
    channelClazz = NioSocketChannel.class;
    eventLoopGroup = new NioEventLoopGroup();
  }

  bootstrap.group(eventLoopGroup)
      .channel(channelClazz)
      .option(ChannelOption.SO_KEEPALIVE, true)
      // TODO: add function to get data class by topic and add handler
      .remoteAddress(host, port)
      .connect();
}
 
开发者ID:vast-framework,项目名称:vast-pubsub,代码行数:20,代码来源:PubSubClient.java

示例8: initialise

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

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
public McpeOverRakNetNetworkListener(VoxelwindServer voxelwindServer, String host, int port, boolean useSoReuseport) {
    this.server = voxelwindServer;
    this.address = new InetSocketAddress(host, port);
    this.useSoReuseport = useSoReuseport;
    if (Epoll.isAvailable()) {
        bootstrap = new Bootstrap()
                .channel(EpollDatagramChannel.class)
                .group(new EpollEventLoopGroup(0, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Voxelwind MCPE Listener - #%d").build()))
                .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .handler(this);
        if (useSoReuseport) {
            bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
        }
    } else {
        bootstrap = new Bootstrap()
                .channel(NioDatagramChannel.class)
                .group(new NioEventLoopGroup(0, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("Voxelwind MCPE Listener - #%d").build()))
                .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)
                .handler(this);
    }
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:22,代码来源:McpeOverRakNetNetworkListener.java

示例10: bind

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

示例11: main

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
public static void main(String... args) throws Exception {
    // RakNet doesn't really like IPv6
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.ADVANCED);
    System.setProperty("java.net.preferIPv4Stack", "true");

    // Load native libraries early.
    boolean partiallySupportedLinux = Epoll.isAvailable();
    boolean fullySupportedLinux = NativeCodeFactory.cipher.load();

    if (partiallySupportedLinux) {
        NativeCodeFactory.zlib.load();
        if (fullySupportedLinux) {
            NativeCodeFactory.hash.load();
        } else {
            LOGGER.warn("You are running x64 Linux, but you are not using a fully-supported distribution. Server throughput and performance will be affected. Visit https://wiki.voxelwind.com/why_linux for more information.");
        }
    } else {
        LOGGER.warn("You are not running x64 Linux. Server throughput and performance will be affected. Visit https://wiki.voxelwind.com/why_linux for more information.");
    }

    VoxelwindServer server = new VoxelwindServer();
    server.boot();
}
 
开发者ID:voxelwind,项目名称:voxelwind,代码行数:24,代码来源:VoxelwindServer.java

示例12: init

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
/**
 * Initializes the network server.
 *
 * @param address The address to bind the server to
 * @param useEpollWhenAvailable Whether you want to use epoll if it's available
 * @return The channel future
 */
public final ChannelFuture init(SocketAddress address, boolean useEpollWhenAvailable) {
    if (this.initialized) {
        throw new IllegalStateException("The network server can only be initialized once.");
    }
    boolean epoll = false;
    if (epollAvailabilityLogged) {
        epoll = Epoll.isAvailable() && useEpollWhenAvailable;
    } else if (useEpollWhenAvailable) {
        if (Epoll.isAvailable()) {
            epoll = true;
            Lantern.getLogger().info("Epoll is enabled.");
        } else {
            // Debug the reason why it is unavailable
            Lantern.getLogger().debug("Epoll is unavailable.", Epoll.unavailabilityCause());
        }
        epollAvailabilityLogged = true;
    }
    final ChannelFuture future = init0(address, epoll);
    this.initialized = true;
    return future;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:29,代码来源:ServerBase.java

示例13: createServerBootstrap

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

示例14: setUp

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
@Before
public void setUp() throws BGPDocumentedException {
    if (!Epoll.isAvailable()) {
        this.boss = new NioEventLoopGroup();
        this.worker = new NioEventLoopGroup();
    }
    this.registry = new StrictBGPPeerRegistry();
    this.clientListener = new SimpleSessionListener();
    this.serverListener = new SimpleSessionListener();
    final BGPExtensionProviderContext ctx = ServiceLoaderBGPExtensionProviderContext.getSingletonInstance();
    this.serverDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);

    this.clientAddress = InetSocketAddressUtil.getRandomLoopbackInetSocketAddress();
    final IpAddress clientPeerIp = new IpAddress(new Ipv4Address(this.clientAddress.getAddress().getHostAddress()));
    this.registry.addPeer(clientPeerIp, this.clientListener, createPreferences(this.clientAddress));
    this.clientDispatcher = new BGPDispatcherImpl(ctx.getMessageRegistry(), this.boss, this.worker, this.registry);
}
 
开发者ID:opendaylight,项目名称:bgpcep,代码行数:18,代码来源:AbstractBGPDispatcherTest.java

示例15: func_181124_a

import io.netty.channel.epoll.Epoll; //导入依赖的package包/类
public static NetworkManager func_181124_a(InetAddress p_181124_0_, int p_181124_1_, boolean p_181124_2_)
{
    final NetworkManager networkmanager = new NetworkManager(EnumPacketDirection.CLIENTBOUND);
    Class <? extends SocketChannel > oclass;
    LazyLoadBase <? extends EventLoopGroup > lazyloadbase;

    if (Epoll.isAvailable() && p_181124_2_)
    {
        oclass = EpollSocketChannel.class;
        lazyloadbase = field_181125_e;
    }
    else
    {
        oclass = NioSocketChannel.class;
        lazyloadbase = CLIENT_NIO_EVENTLOOP;
    }

    ((Bootstrap)((Bootstrap)((Bootstrap)(new Bootstrap()).group((EventLoopGroup)lazyloadbase.getValue())).handler(new ChannelInitializer<Channel>()
    {
        protected void initChannel(Channel p_initChannel_1_) throws Exception
        {
            try
            {
                p_initChannel_1_.config().setOption(ChannelOption.TCP_NODELAY, Boolean.valueOf(true));
            }
            catch (ChannelException var3)
            {
                ;
            }

            p_initChannel_1_.pipeline().addLast((String)"timeout", (ChannelHandler)(new ReadTimeoutHandler(30))).addLast((String)"splitter", (ChannelHandler)(new MessageDeserializer2())).addLast((String)"decoder", (ChannelHandler)(new MessageDeserializer(EnumPacketDirection.CLIENTBOUND))).addLast((String)"prepender", (ChannelHandler)(new MessageSerializer2())).addLast((String)"encoder", (ChannelHandler)(new MessageSerializer(EnumPacketDirection.SERVERBOUND))).addLast((String)"packet_handler", (ChannelHandler)networkmanager);
        }
    })).channel(oclass)).connect(p_181124_0_, p_181124_1_).syncUninterruptibly();
    return networkmanager;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:36,代码来源:NetworkManager.java


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