io.netty.channel.DefaultEventLoop源码实例Demo

类io.netty.channel.DefaultEventLoop源码实例Demo

下面列出了io.netty.channel.DefaultEventLoop 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: armeria   文件: DnsEndpointGroupBuilderTest.java
@Test
void eventLoop() {
    assertThat(builder().eventLoop()).isNotNull();
    final EventLoop loop = new NioEventLoopGroup().next();
    assertThat(builder().eventLoop(loop).eventLoop()).isSameAs(loop);
    assertThatThrownBy(() -> builder().eventLoop(new DefaultEventLoop()))
            .isInstanceOf(IllegalArgumentException.class).hasMessageContaining("unsupported");
}
 
@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(channel.eventLoop()).thenReturn(new DefaultEventLoop(Executors.newSingleThreadExecutor()));
}
 
@BeforeClass
public static void init() {
    group = new DefaultEventLoop();
}
 
源代码4 项目: nettythrift   文件: ServerBootstrap.java
public ServerBootstrap(ThriftServerDef serverDef) {
	this(serverDef, new DefaultChannelGroup(new DefaultEventLoop()));
}
 
源代码5 项目: armeria   文件: EventLoopJmhExecutor.java
@Override
protected EventLoop newChild(Executor executor, Object... args) throws Exception {
    final EventLoop eventLoop = new DefaultEventLoop(this, executor);
    eventLoop.submit(() -> CURRENT_EVENT_LOOP.set(eventLoop)).syncUninterruptibly();
    return eventLoop;
}
 
源代码6 项目: blade   文件: NettyServer.java
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("[email protected]"));
            this.workerGroup = new NioEventLoopGroup(ioThreadCount, new NamedThreadFactory("[email protected]"));
            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));
    }
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法