本文整理匯總了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);
}
}
示例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());
}
});
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}