List of usage examples for io.netty.channel.epoll EpollEventLoopGroup EpollEventLoopGroup
public EpollEventLoopGroup()
From source file:at.yawk.dbus.protocol.DbusConnector.java
/** * Connect to the dbus server at the given {@link SocketAddress}. *///from w w w. jav a2 s .c o m public DbusChannel connect(SocketAddress address) throws Exception { Bootstrap localBootstrap = bootstrap.clone(); if (address instanceof DomainSocketAddress) { localBootstrap.group(new EpollEventLoopGroup()); localBootstrap.channel(EpollDomainSocketChannel.class); } else { localBootstrap.group(new NioEventLoopGroup()); localBootstrap.channel(NioSocketChannel.class); } Channel channel = localBootstrap.connect(address).sync().channel(); AuthClient authClient = new AuthClient(); if (LoggingInboundAdapter.isEnabled()) { channel.pipeline().addLast(new LoggingInboundAdapter()); } channel.pipeline().addLast("auth", authClient); channel.config().setAutoRead(true); log.trace("Pipeline is now {}", channel.pipeline()); // I really don't get why dbus does this channel.write(Unpooled.wrappedBuffer(new byte[] { 0 })); if (authMechanism == null) { authMechanism = new ExternalAuthMechanism(); } CompletionStage<?> completionPromise = authClient.startAuth(channel, authMechanism); SwappableMessageConsumer swappableConsumer = new SwappableMessageConsumer(initialConsumer); completionPromise.toCompletableFuture().thenRun(() -> { channel.pipeline().replace("auth", "main", new DbusMainProtocol(swappableConsumer)); log.trace("Pipeline is now {}", channel.pipeline()); }).get(); DbusChannelImpl dbusChannel = new DbusChannelImpl(channel, swappableConsumer); dbusChannel.write(MessageFactory.methodCall("/", "org.freedesktop.DBus", "org.freedesktop.DBus", "Hello")); return dbusChannel; }
From source file:at.yawk.dbus.protocol.DbusConnectorTest.java
@Test(enabled = false) public void testServer() throws Exception { ServerBootstrap bootstrap = new ServerBootstrap(); bootstrap.channel(EpollServerDomainSocketChannel.class); bootstrap.group(new EpollEventLoopGroup()); bootstrap.childHandler(new ChannelInitializer<Channel>() { @Override/*from w w w .j a v a 2 s.c o m*/ protected void initChannel(Channel ch) throws Exception { ch.pipeline().addLast(new CommandCodec()).addLast(new ChannelDuplexHandler() { @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof NegotiateUnixFd) { ch.writeAndFlush(new Error("error")); } if (msg instanceof Begin) { ch.pipeline().addLast(new LoggingInboundAdapter()) .addLast(new DbusMainProtocol(new MessageConsumer() { @Override public boolean requireAccept(MessageHeader header) { return true; } @Override public void accept(DbusMessage message) { DbusMessage response = new DbusMessage(); MessageHeader header = new MessageHeader(); header.setMessageType(MessageType.ERROR); header.addHeader(HeaderField.REPLY_SERIAL, BasicObject.createUint32(message.getHeader().getSerial())); //header.addHeader(HeaderField.SIGNATURE, SignatureObject.create( // Collections.singletonList(BasicType.VARIANT))); header.addHeader(HeaderField.ERROR_NAME, BasicObject.createString("Error")); response.setHeader(header); MessageBody body = new MessageBody(); //body.add(VariantObject.create(BasicObject.createString("testing!"))); response.setBody(body); ch.writeAndFlush(response); } })); ch.pipeline().remove((Class) getClass()); ch.pipeline().remove(CommandCodec.class); } } }); ch.writeAndFlush(new Ok(UUID.randomUUID())); } }); bootstrap.bind(new DomainSocketAddress(new File("test"))); try { DbusUtil.callCommand(("dbus-send --address=unix:path=" + new File(".").getAbsolutePath() + "/test --dest=org.freedesktop.UPower --print-reply " + "/org/freedesktop/UPower/devices/DisplayDevice org.freedesktop.DBus.Properties.Get string:org" + ".freedesktop.UPower.Device string:State").split(" ")); } catch (Exception e) { e.printStackTrace(); } TimeUnit.DAYS.sleep(1); }
From source file:com.ancun.netty.common.NettyBootstrapFactory.java
License:Apache License
private Bootstrap newEpollClientBootstrap() { workerGroup = new EpollEventLoopGroup(); return new Bootstrap().group(workerGroup).channel(EpollSocketChannel.class); }
From source file:com.codahale.grpcproxy.util.Netty.java
License:Apache License
public static EventLoopGroup newBossEventLoopGroup() { if (Epoll.isAvailable()) { return new EpollEventLoopGroup(); }/*from w w w. j a v a2s. c o m*/ return new NioEventLoopGroup(); }
From source file:com.github.mrstampy.kitchensync.netty.Bootstrapper.java
License:Open Source License
/** * Gets the event loop group based upon the class name. If the class is * neither an <a href=/*w w w .j a v a 2 s.co m*/ * "http://netty.io/4.0/api/io/netty/channel/socket/nio/NioDatagramChannel.html" * >NioDatagramChannel</a> nor <a href= * "http://netty.io/4.0/api/io/netty/channel/socket/oio/OioDatagramChannel.html" * >OioDatagramChannel</a> (or on Linux, <a href= * "http://netty.io/4.0/api/io/netty/channel/epoll/EpollDatagramChannel.html" * >EpollDatagramChannel</a>) then an exception is thrown. * * @param <CHANNEL> * the generic type * @param clazz * the clazz * @return the event loop group */ protected <CHANNEL extends DatagramChannel> EventLoopGroup getEventLoopGroup(Class<? extends CHANNEL> clazz) { if (NioDatagramChannel.class.equals(clazz)) return new NioEventLoopGroup(); if (OioDatagramChannel.class.equals(clazz)) return new OioEventLoopGroup(); // Linux only if (EpollDatagramChannel.class.equals(clazz)) return new EpollEventLoopGroup(); throw new UnsupportedOperationException("No default event loop group defined for " + clazz.getName()); }
From source file:com.github.thinker0.mesos.MesosHealthCheckerServer.java
License:Apache License
/** * Starts the web server./* w ww .j a v a2 s .c o m*/ * * @throws Exception */ public EventLoopGroup start() throws Exception { if (Epoll.isAvailable()) { eventLoopGroup = new EpollEventLoopGroup(); start(new EpollEventLoopGroup(), EpollServerSocketChannel.class); } else { eventLoopGroup = new NioEventLoopGroup(); start(new NioEventLoopGroup(), NioServerSocketChannel.class); } return eventLoopGroup; }
From source file:com.kixeye.kixmpp.client.KixmppClient.java
License:Apache License
/** * Creates a new {@link KixmppClient}./*from www .j ava2s . co m*/ * * @param eventLoopGroup * @param eventEngine * @param sslContext * @param type */ public KixmppClient(EventLoopGroup eventLoopGroup, KixmppEventEngine eventEngine, SslContext sslContext, Type type) { if (sslContext != null) { assert sslContext.isClient() : "The given SslContext must be a client context."; } if (eventLoopGroup == null) { if (OS.indexOf("nux") >= 0) { eventLoopGroup = new EpollEventLoopGroup(); } else { eventLoopGroup = new NioEventLoopGroup(); } } this.type = type; this.sslContext = sslContext; this.eventEngine = eventEngine; // set modules to be registered this.modulesToRegister.add(MucKixmppClientModule.class.getName()); this.modulesToRegister.add(PresenceKixmppClientModule.class.getName()); this.modulesToRegister.add(MessageKixmppClientModule.class.getName()); this.modulesToRegister.add(ErrorKixmppClientModule.class.getName()); if (eventLoopGroup instanceof EpollEventLoopGroup) { this.bootstrap = new Bootstrap().group(eventLoopGroup).channel(EpollSocketChannel.class) .option(ChannelOption.TCP_NODELAY, false).option(ChannelOption.SO_KEEPALIVE, true); } else { this.bootstrap = new Bootstrap().group(eventLoopGroup).channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, false).option(ChannelOption.SO_KEEPALIVE, true); } switch (type) { case TCP: bootstrap.handler(new KixmppClientChannelInitializer()); break; case WEBSOCKET: bootstrap.handler(new KixmppClientWebSocketChannelInitializer()); break; } }
From source file:com.kixeye.kixmpp.server.KixmppServer.java
License:Apache License
/** * Creates a new {@link KixmppServer} with the given ssl engine. * /*from w w w . j a va 2 s .c o m*/ * @param bindAddress * @param domain */ public KixmppServer(InetSocketAddress bindAddress, String domain, InetSocketAddress clusterAddress, NodeDiscovery clusterDiscovery, boolean useEpollIfAvailable) { if (useEpollIfAvailable && OS.indexOf("nux") >= 0) { this.bootstrap = new ServerBootstrap().group(new EpollEventLoopGroup(), new EpollEventLoopGroup()) .channel(EpollServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() { protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new KixmppCodec()); ch.pipeline().addLast(new KixmppServerMessageHandler()); } }); } else { this.bootstrap = new ServerBootstrap().group(new NioEventLoopGroup(), new NioEventLoopGroup()) .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() { protected void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new KixmppCodec()); ch.pipeline().addLast(new KixmppServerMessageHandler()); } }); } this.cluster = new ClusterClient(this, clusterAddress.getHostName(), clusterAddress.getPort(), clusterDiscovery, 300000, bootstrap.group()); this.cluster.getMessageRegistry().addCustomMessage(1, RoomBroadcastTask.class); this.cluster.getMessageRegistry().addCustomMessage(2, RoomPresenceBroadcastTask.class); this.cluster.getMessageRegistry().addCustomMessage(3, PrivateChatTask.class); this.cluster.getMessageRegistry().addCustomMessage(4, GetMucRoomNicknamesRequest.class); this.cluster.getMessageRegistry().addCustomMessage(5, GetMucRoomNicknamesResponse.class); this.mapReduce = new MapReduceTracker(this, bootstrap.group()); this.channels = new DefaultChannelGroup("All Channels", GlobalEventExecutor.INSTANCE); this.bindAddress = bindAddress; this.domain = domain.toLowerCase(); this.eventEngine = new KixmppEventEngine(); this.modulesToRegister.add(FeaturesKixmppServerModule.class.getName()); this.modulesToRegister.add(SaslKixmppServerModule.class.getName()); this.modulesToRegister.add(BindKixmppServerModule.class.getName()); this.modulesToRegister.add(SessionKixmppServerModule.class.getName()); this.modulesToRegister.add(PresenceKixmppServerModule.class.getName()); this.modulesToRegister.add(MucKixmppServerModule.class.getName()); this.modulesToRegister.add(RosterKixmppServerModule.class.getName()); this.modulesToRegister.add(DiscoKixmppServerModule.class.getName()); this.modulesToRegister.add(ChatKixmppServerModule.class.getName()); }
From source file:herddb.client.HDBClient.java
License:Apache License
private void init() { int corePoolSize = configuration.getInt(ClientConfiguration.PROPERTY_CLIENT_CALLBACKS, ClientConfiguration.PROPERTY_CLIENT_CALLBACKS_DEFAULT); this.thredpool = new ThreadPoolExecutor(corePoolSize, Integer.MAX_VALUE, 120L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), (Runnable r) -> { Thread t = new FastThreadLocalThread(r, "hdb-client"); t.setDaemon(true);/*from w ww.j a v a2 s .co m*/ return t; }); this.networkGroup = NetworkUtils.isEnableEpoolNative() ? new EpollEventLoopGroup() : new NioEventLoopGroup(); this.localEventsGroup = new DefaultEventLoopGroup(); String mode = configuration.getString(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_LOCAL); switch (mode) { case ClientConfiguration.PROPERTY_MODE_LOCAL: case ClientConfiguration.PROPERTY_MODE_STANDALONE: this.clientSideMetadataProvider = new StaticClientSideMetadataProvider( configuration.getString(ClientConfiguration.PROPERTY_SERVER_ADDRESS, ClientConfiguration.PROPERTY_SERVER_ADDRESS_DEFAULT), configuration.getInt(ClientConfiguration.PROPERTY_SERVER_PORT, ClientConfiguration.PROPERTY_SERVER_PORT_DEFAULT), configuration.getBoolean(ClientConfiguration.PROPERTY_SERVER_SSL, ClientConfiguration.PROPERTY_SERVER_SSL_DEFAULT)); break; case ClientConfiguration.PROPERTY_MODE_CLUSTER: this.clientSideMetadataProvider = new ZookeeperClientSideMetadataProvider( configuration.getString(ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, ClientConfiguration.PROPERTY_ZOOKEEPER_ADDRESS_DEFAULT), configuration.getInt(ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, ClientConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT_DEFAULT), configuration.getString(ClientConfiguration.PROPERTY_ZOOKEEPER_PATH, ClientConfiguration.PROPERTY_ZOOKEEPER_PATH_DEFAULT)); break; default: throw new IllegalStateException(mode); } }
From source file:io.blobkeeper.server.BlobKeeperServer.java
License:Apache License
@Override protected void doStart() { fileWriterService.start();//from ww w . j a v a 2 s .c o m clusterMembershipService.start(serverConfiguration.getServerName()); bossGroup = new EpollEventLoopGroup(); // FIXME: add to config workerGroup = new EpollEventLoopGroup(512); bootstrap = new ServerBootstrap(); bootstrap.option(ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.group(bossGroup, workerGroup).channel(EpollServerSocketChannel.class) .childHandler(serverInitializer); bootstrap.childOption(SO_LINGER, -1); bootstrap.childOption(TCP_NODELAY, true); bootstrap.childOption(SO_REUSEADDR, true); bootstrap.childOption(ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.childOption(EpollChannelOption.SO_REUSEPORT, true); bootstrap.childOption(EpollChannelOption.TCP_CORK, true); try { serverChannel = bootstrap.bind(serverConfiguration.getServerPort()).sync(); notifyStarted(); } catch (InterruptedException e) { notifyFailed(e); throw new RuntimeException(e); } }