use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project java by wavefrontHQ.
the class RawLogsIngester method listen.
public void listen() throws InterruptedException {
ServerBootstrap serverBootstrap = new ServerBootstrap();
EventLoopGroup acceptorGroup;
EventLoopGroup handlerGroup;
Class<? extends ServerChannel> socketChannelClass;
if (Epoll.isAvailable()) {
logger.fine("Using native socket transport for port " + port);
acceptorGroup = new EpollEventLoopGroup(2);
handlerGroup = new EpollEventLoopGroup(10);
socketChannelClass = EpollServerSocketChannel.class;
} else {
logger.fine("Using NIO socket transport for port " + port);
acceptorGroup = new NioEventLoopGroup(2);
handlerGroup = new NioEventLoopGroup(10);
socketChannelClass = NioServerSocketChannel.class;
}
serverBootstrap.group(acceptorGroup, handlerGroup).channel(socketChannelClass).childHandler(new SocketInitializer()).option(ChannelOption.SO_BACKLOG, 5).option(ChannelOption.SO_KEEPALIVE, true);
serverBootstrap.bind(port).sync();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project herddb by diennea.
the class NetworkChannelTest method test.
@Test
public void test() throws Exception {
try (NettyChannelAcceptor acceptor = new NettyChannelAcceptor("localhost", 1111, true)) {
acceptor.setEnableJVMNetwork(false);
acceptor.setAcceptor(new ServerSideConnectionAcceptor() {
@Override
public ServerSideConnection createConnection(Channel channel) {
channel.setMessagesReceiver(new ChannelEventListener() {
@Override
public void messageReceived(Message message, Channel channel) {
channel.sendReplyMessage(message, Message.ACK("ciao"));
}
@Override
public void channelClosed(Channel channel) {
}
});
return new ServerSideConnection() {
@Override
public long getConnectionId() {
return new Random().nextLong();
}
};
}
});
acceptor.start();
ExecutorService executor = Executors.newCachedThreadPool();
try (Channel client = NettyConnector.connect("localhost", 1111, true, 0, 0, new ChannelEventListener() {
@Override
public void messageReceived(Message message, Channel channel) {
System.out.println("client messageReceived " + message);
}
@Override
public void channelClosed(Channel channel) {
System.out.println("client channelClosed");
}
}, executor, new NioEventLoopGroup(10, executor), new DefaultEventLoopGroup())) {
for (int i = 0; i < 100; i++) {
Message result = client.sendMessageWithReply(Message.ACK("clientId"), 10000);
assertEquals(Message.TYPE_ACK, result.type);
// System.out.println("result:" + result);
}
} finally {
executor.shutdown();
}
}
if (NetworkUtils.isEnableEpoolNative()) {
try (NettyChannelAcceptor acceptor = new NettyChannelAcceptor("localhost", 1111, true)) {
acceptor.setEnableJVMNetwork(false);
acceptor.setAcceptor(new ServerSideConnectionAcceptor() {
@Override
public ServerSideConnection createConnection(Channel channel) {
channel.setMessagesReceiver(new ChannelEventListener() {
@Override
public void messageReceived(Message message, Channel channel) {
channel.sendReplyMessage(message, Message.ACK("ciao"));
}
@Override
public void channelClosed(Channel channel) {
}
});
return new ServerSideConnection() {
@Override
public long getConnectionId() {
return new Random().nextLong();
}
};
}
});
acceptor.start();
ExecutorService executor = Executors.newCachedThreadPool();
try (Channel client = NettyConnector.connect("localhost", 1111, true, 0, 0, new ChannelEventListener() {
@Override
public void messageReceived(Message message, Channel channel) {
System.out.println("client messageReceived " + message);
}
@Override
public void channelClosed(Channel channel) {
System.out.println("client channelClosed");
}
}, executor, new EpollEventLoopGroup(10, executor), new DefaultEventLoopGroup())) {
for (int i = 0; i < 100; i++) {
Message result = client.sendMessageWithReply(Message.ACK("clientId"), 10000);
assertEquals(Message.TYPE_ACK, result.type);
// System.out.println("result:" + result);
}
} finally {
executor.shutdown();
}
}
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project pravega by pravega.
the class AbstractConnectionListener method startListening.
/**
* Initializes the connection listener internals and starts listening.
*/
public void startListening() {
final AtomicReference<SslContext> sslCtx = this.enableTls ? new AtomicReference<>(TLSHelper.newServerSslContext(pathToTlsCertFile, pathToTlsKeyFile, tlsProtocolVersion)) : null;
boolean nio = false;
try {
bossGroup = new EpollEventLoopGroup(1);
workerGroup = new EpollEventLoopGroup();
} catch (ExceptionInInitializerError | UnsatisfiedLinkError | NoClassDefFoundError e) {
nio = true;
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
}
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(nio ? NioServerSocketChannel.class : EpollServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
// Add SslHandler to the channel's pipeline, if TLS is enabled.
if (enableTls) {
SslHandler sslHandler = sslCtx.get().newHandler(ch.alloc());
// We add a name to SSL/TLS handler, unlike the other handlers added later, to make it
// easier to find and replace the handler.
p.addLast(TLSHelper.TLS_HANDLER_NAME, sslHandler);
}
// Configure the class-specific encoder stack and request processors.
ServerConnectionInboundHandler lsh = new ServerConnectionInboundHandler();
createEncodingStack(ch.remoteAddress().toString()).forEach(p::addLast);
lsh.setRequestProcessor(createRequestProcessor(new TrackedConnection(lsh, connectionTracker)));
p.addLast(lsh);
}
});
if (enableTls && enableTlsReload) {
enableTlsContextReload(sslCtx);
}
// Start the server.
serverChannel = b.bind(host, port).awaitUninterruptibly().channel();
if (healthServiceManager != null) {
healthServiceManager.register(new ConnectionListenerHealthContributor(this));
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project pravega by pravega.
the class ConnectionPoolingTest method setUp.
@Before
public void setUp() throws Exception {
// Configure SSL.
port = TestUtils.getAvailableListenPort();
final SslContext sslCtx;
if (ssl) {
try {
sslCtx = SslContextBuilder.forServer(new File(SecurityConfigDefaults.TLS_SERVER_CERT_PATH), new File(SecurityConfigDefaults.TLS_SERVER_PRIVATE_KEY_PATH)).build();
} catch (SSLException e) {
throw new RuntimeException(e);
}
} else {
sslCtx = null;
}
boolean nio = false;
EventLoopGroup bossGroup;
EventLoopGroup workerGroup;
try {
bossGroup = new EpollEventLoopGroup(1);
workerGroup = new EpollEventLoopGroup();
} catch (ExceptionInInitializerError | UnsatisfiedLinkError | NoClassDefFoundError e) {
nio = true;
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
}
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(nio ? NioServerSocketChannel.class : EpollServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
SslHandler handler = sslCtx.newHandler(ch.alloc());
SSLEngine sslEngine = handler.engine();
SSLParameters sslParameters = sslEngine.getSSLParameters();
sslParameters.setEndpointIdentificationAlgorithm("LDAPS");
sslEngine.setSSLParameters(sslParameters);
p.addLast(handler);
}
p.addLast(new CommandEncoder(null, NO_OP_METRIC_NOTIFIER), new LengthFieldBasedFrameDecoder(MAX_WIRECOMMAND_SIZE, 4, 4), new CommandDecoder(), new EchoServerHandler());
}
});
// Start the server.
serverChannel = b.bind("localhost", port).awaitUninterruptibly().channel();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.netty.channel.epoll.EpollEventLoopGroup in project beam by apache.
the class ManagedChannelFactory method forDescriptor.
public ManagedChannel forDescriptor(ApiServiceDescriptor apiServiceDescriptor) {
ManagedChannelBuilder<?> channelBuilder;
switch(type) {
case EPOLL:
SocketAddress address = SocketAddressFactory.createFrom(apiServiceDescriptor.getUrl());
channelBuilder = NettyChannelBuilder.forAddress(address).channelType(address instanceof DomainSocketAddress ? EpollDomainSocketChannel.class : EpollSocketChannel.class).eventLoopGroup(new EpollEventLoopGroup());
break;
case DEFAULT:
channelBuilder = ManagedChannelBuilder.forTarget(apiServiceDescriptor.getUrl());
break;
case IN_PROCESS:
channelBuilder = InProcessChannelBuilder.forName(apiServiceDescriptor.getUrl());
break;
default:
throw new IllegalStateException("Unknown type " + type);
}
channelBuilder = channelBuilder.usePlaintext().maxInboundMessageSize(Integer.MAX_VALUE).intercept(interceptors);
if (directExecutor) {
channelBuilder = channelBuilder.directExecutor();
}
return channelBuilder.build();
}
Aggregations