Search in sources :

Example 6 with DefaultEventLoop

use of io.netty.channel.DefaultEventLoop in project zuul by Netflix.

the class DefaultClientChannelManagerTest method updateServerRefOnValidDiscoveryResult.

@Test
public void updateServerRefOnValidDiscoveryResult() {
    OriginName originName = OriginName.fromVip("vip", "test");
    final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    final DynamicServerResolver resolver = mock(DynamicServerResolver.class);
    final InstanceInfo instanceInfo = Builder.newBuilder().setAppName("server-equality").setHostName("server-equality").setPort(7777).build();
    final DiscoveryResult discoveryResult = DiscoveryResult.from(instanceInfo, false);
    when(resolver.resolve(any())).thenReturn(discoveryResult);
    final DefaultClientChannelManager clientChannelManager = new DefaultClientChannelManager(originName, clientConfig, resolver, new DefaultRegistry());
    final AtomicReference<DiscoveryResult> serverRef = new AtomicReference<>();
    // TODO(argha-c) capture and assert on the promise once we have a dummy with ServerStats initialized
    clientChannelManager.acquire(new DefaultEventLoop(), null, CurrentPassport.create(), serverRef, new AtomicReference<>());
    Truth.assertThat(serverRef.get()).isSameInstanceAs(discoveryResult);
}
Also used : OriginName(com.netflix.zuul.origins.OriginName) DiscoveryResult(com.netflix.zuul.discovery.DiscoveryResult) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) DefaultEventLoop(io.netty.channel.DefaultEventLoop) DynamicServerResolver(com.netflix.zuul.discovery.DynamicServerResolver) AtomicReference(java.util.concurrent.atomic.AtomicReference) InstanceInfo(com.netflix.appinfo.InstanceInfo) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) Test(org.junit.Test)

Example 7 with DefaultEventLoop

use of io.netty.channel.DefaultEventLoop in project blade by biezhi.

the class NettyServer method startServer.

private void startServer(long startMs) throws Exception {
    ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
    boolean SSL = environment.getBoolean(ENV_KEY_SSL, false);
    // Configure SSL.
    SslContext sslCtx = null;
    if (SSL) {
        String certFilePath = environment.get(ENV_KEY_SSL_CERT, null);
        String privateKeyPath = environment.get(ENE_KEY_SSL_PRIVATE_KEY, null);
        String privateKeyPassword = environment.get(ENE_KEY_SSL_PRIVATE_KEY_PASS, null);
        log.info("{}SSL CertChainFile  Path: {}", getStartedSymbol(), certFilePath);
        log.info("{}SSL PrivateKeyFile Path: {}", getStartedSymbol(), privateKeyPath);
        sslCtx = SslContextBuilder.forServer(new File(certFilePath), new File(privateKeyPath), privateKeyPassword).build();
    }
    var bootstrap = new ServerBootstrap();
    int acceptThreadCount = environment.getInt(ENC_KEY_NETTY_ACCEPT_THREAD_COUNT, DEFAULT_ACCEPT_THREAD_COUNT);
    int ioThreadCount = environment.getInt(ENV_KEY_NETTY_IO_THREAD_COUNT, DEFAULT_IO_THREAD_COUNT);
    // enable epoll
    if (BladeKit.epollIsAvailable()) {
        log.info("{}Use EpollEventLoopGroup", getStartedSymbol());
        bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
        NettyServerGroup nettyServerGroup = EpollKit.group(acceptThreadCount, ioThreadCount);
        this.bossGroup = nettyServerGroup.getBoosGroup();
        this.workerGroup = nettyServerGroup.getWorkerGroup();
        bootstrap.group(bossGroup, workerGroup).channel(nettyServerGroup.getSocketChannel());
    } else {
        log.info("{}Use NioEventLoopGroup", getStartedSymbol());
        this.bossGroup = new NioEventLoopGroup(acceptThreadCount, new NamedThreadFactory("boss@"));
        this.workerGroup = new NioEventLoopGroup(ioThreadCount, new NamedThreadFactory("worker@"));
        bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class);
    }
    scheduleEventLoop = new DefaultEventLoop();
    bootstrap.childHandler(new HttpServerInitializer(sslCtx, blade, scheduleEventLoop));
    String address = environment.get(ENV_KEY_SERVER_ADDRESS, DEFAULT_SERVER_ADDRESS);
    Integer port = environment.getInt(ENV_KEY_SERVER_PORT, DEFAULT_SERVER_PORT);
    channel = bootstrap.bind(address, port).sync().channel();
    String appName = environment.get(ENV_KEY_APP_NAME, "Blade");
    String url = Ansi.BgRed.and(Ansi.Black).format(" %s:%d ", address, port);
    String protocol = SSL ? "https" : "http";
    log.info("{}{} initialize successfully, Time elapsed: {} ms", getStartedSymbol(), appName, (System.currentTimeMillis() - startMs));
    log.info("{}Blade start with {}", getStartedSymbol(), url);
    log.info("{}Open browser access {}://{}:{} ⚡\r\n", getStartedSymbol(), protocol, address.replace(DEFAULT_SERVER_ADDRESS, LOCAL_IP_ADDRESS), port);
    blade.eventManager().fireEvent(EventType.SERVER_STARTED, new Event().attribute("blade", blade));
}
Also used : lombok.var(lombok.var) DefaultEventLoop(io.netty.channel.DefaultEventLoop) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Event(com.blade.event.Event) File(java.io.File) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

DefaultEventLoop (io.netty.channel.DefaultEventLoop)7 Bootstrap (io.netty.bootstrap.Bootstrap)3 LocalAddress (io.netty.channel.local.LocalAddress)3 Test (org.junit.jupiter.api.Test)3 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)2 DefaultRegistry (com.netflix.spectator.api.DefaultRegistry)2 DiscoveryResult (com.netflix.zuul.discovery.DiscoveryResult)2 DynamicServerResolver (com.netflix.zuul.discovery.DynamicServerResolver)2 OriginName (com.netflix.zuul.origins.OriginName)2 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)2 Channel (io.netty.channel.Channel)2 EventLoop (io.netty.channel.EventLoop)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2 Event (com.blade.event.Event)1 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1