Search in sources :

Example 1 with NettyInitializers

use of org.infinispan.server.core.transport.NettyInitializers in project infinispan by infinispan.

the class SinglePortEndpointRouter method getInitializer.

@Override
public ChannelInitializer<Channel> getInitializer() {
    Map<String, ProtocolServer<?>> upgradeServers = new HashMap<>();
    RestServer restServer = routingTable.streamRoutes(SinglePortRouteSource.class, RestServerRouteDestination.class).findFirst().map(r -> r.getRouteDestination().getProtocolServer()).orElseThrow(() -> new IllegalStateException("There must be a REST route!"));
    routingTable.streamRoutes(SinglePortRouteSource.class, HotRodServerRouteDestination.class).findFirst().ifPresent(r -> upgradeServers.put("HR", r.getRouteDestination().getProtocolServer()));
    routingTable.streamRoutes(SinglePortRouteSource.class, RespServerRouteDestination.class).findFirst().ifPresent(r -> upgradeServers.put("RP", r.getRouteDestination().getProtocolServer()));
    SinglePortChannelInitializer restChannelInitializer = new SinglePortChannelInitializer(this, transport, restServer, upgradeServers);
    return new NettyInitializers(restChannelInitializer);
}
Also used : RestServer(org.infinispan.rest.RestServer) RouterLogger(org.infinispan.server.router.logging.RouterLogger) SinglePortRouterConfiguration(org.infinispan.server.router.configuration.SinglePortRouterConfiguration) HotRodServerRouteDestination(org.infinispan.server.router.routes.hotrod.HotRodServerRouteDestination) NettyTransport(org.infinispan.server.core.transport.NettyTransport) SecurityActions.getGlobalComponentRegistry(org.infinispan.server.router.router.impl.singleport.SecurityActions.getGlobalComponentRegistry) RestServer(org.infinispan.rest.RestServer) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) HashMap(java.util.HashMap) InetAddress(java.net.InetAddress) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) AbstractProtocolServer(org.infinispan.server.core.AbstractProtocolServer) ProtocolServer(org.infinispan.server.core.ProtocolServer) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) Map(java.util.Map) ChannelMatcher(io.netty.channel.group.ChannelMatcher) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) ChannelInitializer(io.netty.channel.ChannelInitializer) ChannelOutboundHandler(io.netty.channel.ChannelOutboundHandler) RespServerRouteDestination(org.infinispan.server.router.routes.resp.RespServerRouteDestination) RoutingTable(org.infinispan.server.router.RoutingTable) InetSocketAddress(java.net.InetSocketAddress) UnknownHostException(java.net.UnknownHostException) Channel(io.netty.channel.Channel) NettyInitializers(org.infinispan.server.core.transport.NettyInitializers) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination) EndpointRouter(org.infinispan.server.router.router.EndpointRouter) AbstractProtocolServer(org.infinispan.server.core.AbstractProtocolServer) ProtocolServer(org.infinispan.server.core.ProtocolServer) HashMap(java.util.HashMap) SinglePortRouteSource(org.infinispan.server.router.routes.singleport.SinglePortRouteSource) NettyInitializers(org.infinispan.server.core.transport.NettyInitializers) RestServerRouteDestination(org.infinispan.server.router.routes.rest.RestServerRouteDestination)

Example 2 with NettyInitializers

use of org.infinispan.server.core.transport.NettyInitializers in project infinispan by infinispan.

the class RecoveryOp method initializeChannel.

private Channel initializeChannel() {
    Bootstrap bootstrap = new Bootstrap();
    bootstrap.group(eventLoopGroup);
    bootstrap.handler(new NettyInitializers(new ClientChannelInitializer(this, rspTimeoutSeconds, sslEngine, protocolVersion)));
    bootstrap.channel(NioSocketChannel.class);
    bootstrap.option(ChannelOption.TCP_NODELAY, true);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    // Make a new connection.
    ChannelFuture connectFuture = bootstrap.connect(new InetSocketAddress(host, port));
    // Wait until the connection is made successfully.
    Channel ch = connectFuture.syncUninterruptibly().channel();
    assertTrue(connectFuture.isSuccess());
    return ch;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) NettyInitializers(org.infinispan.server.core.transport.NettyInitializers)

Example 3 with NettyInitializers

use of org.infinispan.server.core.transport.NettyInitializers in project infinispan by infinispan.

the class HotRodTestingUtil method startHotRodServer.

public static HotRodServer startHotRodServer(EmbeddedCacheManager manager, String host, int port, HotRodServerConfigurationBuilder builder) {
    log.infof("Start server in port %d", port);
    HotRodServer server = new HotRodServer() {

        @Override
        public ChannelInitializer<Channel> getInitializer() {
            if (configuration.idleTimeout() > 0)
                return new NettyInitializers(new NettyChannelInitializer<>(this, transport, getEncoder(), getDecoder()), new TimeoutEnabledChannelInitializer<>(this), new TestHandlersChannelInitializer());
            else
                // Idle timeout logic is disabled with -1 or 0 values
                return new NettyInitializers(new NettyChannelInitializer<>(this, transport, getEncoder(), getDecoder()), new TestHandlersChannelInitializer());
        }
    };
    String shortTestName = TestResourceTracker.getCurrentTestShortName();
    if (!builder.name().contains(shortTestName)) {
        // Only set the name once if HotRodClientTestingUtil.startHotRodServer() retries
        builder.name(shortTestName + builder.name());
    }
    builder.host(host).port(port);
    builder.ioThreads(3);
    try {
        server.start(builder.build(), manager);
        return server;
    } catch (Throwable t) {
        server.stop();
        throw t;
    }
}
Also used : TestHandlersChannelInitializer(org.infinispan.server.hotrod.transport.TestHandlersChannelInitializer) NettyChannelInitializer(org.infinispan.server.core.transport.NettyChannelInitializer) HotRodServer(org.infinispan.server.hotrod.HotRodServer) Channel(io.netty.channel.Channel) NettyInitializers(org.infinispan.server.core.transport.NettyInitializers) TimeoutEnabledChannelInitializer(org.infinispan.server.hotrod.transport.TimeoutEnabledChannelInitializer)

Aggregations

Channel (io.netty.channel.Channel)3 NettyInitializers (org.infinispan.server.core.transport.NettyInitializers)3 InetSocketAddress (java.net.InetSocketAddress)2 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelInboundHandler (io.netty.channel.ChannelInboundHandler)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOutboundHandler (io.netty.channel.ChannelOutboundHandler)1 ChannelMatcher (io.netty.channel.group.ChannelMatcher)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 BasicComponentRegistry (org.infinispan.factories.impl.BasicComponentRegistry)1 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)1 RestServer (org.infinispan.rest.RestServer)1 AbstractProtocolServer (org.infinispan.server.core.AbstractProtocolServer)1 ProtocolServer (org.infinispan.server.core.ProtocolServer)1 NettyChannelInitializer (org.infinispan.server.core.transport.NettyChannelInitializer)1