当前位置: 首页>>代码示例>>Java>>正文


Java DefaultThreadFactory类代码示例

本文整理汇总了Java中io.netty.util.concurrent.DefaultThreadFactory的典型用法代码示例。如果您正苦于以下问题:Java DefaultThreadFactory类的具体用法?Java DefaultThreadFactory怎么用?Java DefaultThreadFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultThreadFactory类属于io.netty.util.concurrent包,在下文中一共展示了DefaultThreadFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ZooKeeperCommandExecutor

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
private ZooKeeperCommandExecutor(String replicaId, CommandExecutor delegate, CuratorFramework curator,
                                 String zkPath, boolean createPathIfNotExist, File revisionFile,
                                 int numWorkers, int maxLogCount, long minLogAgeMillis) {
    super(replicaId);

    this.delegate = delegate;
    this.revisionFile = revisionFile;
    this.curator = curator;
    this.zkPath = zkPath;
    this.createPathIfNotExist = createPathIfNotExist;
    this.maxLogCount = maxLogCount;
    this.minLogAgeMillis = minLogAgeMillis;

    final ThreadPoolExecutor executor = new ThreadPoolExecutor(
            numWorkers, numWorkers,
            60, TimeUnit.SECONDS, new LinkedTransferQueue<>(),
            new DefaultThreadFactory("zookeeper-command-executor", true));
    executor.allowCoreThreadTimeOut(true);
    this.executor = executor;

    logWatcher = new PathChildrenCache(curator, absolutePath(LOG_PATH), true);
    logWatcher.getListenable().addListener(this, MoreExecutors.directExecutor());
    oldLogRemover = new OldLogRemover();
    leaderSelector = new LeaderSelector(curator, absolutePath(LEADER_PATH), oldLogRemover);
    leaderSelector.autoRequeue();
}
 
开发者ID:line,项目名称:centraldogma,代码行数:27,代码来源:ZooKeeperCommandExecutor.java

示例2: start

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public void start(SlaveNode slaveNode) {
    if(slaveNode==null){
        throw new IllegalArgumentException("slaveNode is null");
    }
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new SlaveServerInitializer());

        ChannelFuture future = b.bind(slaveNode.getPort()).sync();
        LOGGER.info("SlaveServer Startup at port:{}",slaveNode.getPort());

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOGGER.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:27,代码来源:SlaveServer.java

示例3: start

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new MasterServerInitializer());

        ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
        LOGGER.info("MasterServer Startup at port:{}",CommonConstants.SERVER_PORT);

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        LOGGER.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:24,代码来源:MasterServer.java

示例4: start

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public void start() {
    EventLoopGroup bossGroup = new NioEventLoopGroup(CommonConstants.BOSS_GROUP_SIZE, new DefaultThreadFactory("boss", true));
    EventLoopGroup workerGroup = new NioEventLoopGroup(CommonConstants.WORKER_GROUP_SIZE, new DefaultThreadFactory("worker", true));
    try {
        ServerBootstrap b = new ServerBootstrap();
        b.option(ChannelOption.SO_BACKLOG, 1024);
        b.group(bossGroup, workerGroup)
         .channel(NioServerSocketChannel.class)
         .handler(new LoggingHandler(LogLevel.INFO))
         .childHandler(new ServerInitializer());

        ChannelFuture future = b.bind(CommonConstants.SERVER_PORT).sync();
        logger.info("NettyServer Startup at port:{}",CommonConstants.SERVER_PORT);

        // 等待服务端Socket关闭
        future.channel().closeFuture().sync();
    } catch (InterruptedException e) {
        logger.error("InterruptedException:",e);
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
 
开发者ID:all4you,项目名称:redant,代码行数:24,代码来源:NettyServer.java

示例5: start

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public synchronized void start(CommandExecutor commandExecutor) {
    if (isStarted()) {
        return;
    }

    this.commandExecutor = requireNonNull(commandExecutor, "commandExecutor");

    scheduler = MoreExecutors.listeningDecorator(Executors.newSingleThreadScheduledExecutor(
            new DefaultThreadFactory("mirroring-scheduler", true)));

    worker = MoreExecutors.listeningDecorator(
            new ThreadPoolExecutor(0, numThreads, 1, TimeUnit.MINUTES, new SynchronousQueue<>(),
                                   new DefaultThreadFactory("mirroring-worker", true)));

    final ListenableScheduledFuture<?> future = scheduler.scheduleWithFixedDelay(
            this::schedulePendingMirrors,
            TICK.getSeconds(), TICK.getSeconds(), TimeUnit.SECONDS);

    FuturesExtra.addFailureCallback(
            future,
            cause -> logger.error("Git-to-CD mirroring scheduler stopped due to an unexpected exception:",
                                  cause));
}
 
开发者ID:line,项目名称:centraldogma,代码行数:24,代码来源:DefaultMirroringService.java

示例6: NettyClientImpl

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public NettyClientImpl(URL url) {
    super(url);

    this.remoteAddress = new InetSocketAddress(url.getHost(), url.getPort());
    this.timeout = url.getIntParameter(URLParam.requestTimeout.getName(), URLParam.requestTimeout.getIntValue());

    this.scheduledExecutorService = Executors.newScheduledThreadPool(5,
            new DefaultThreadFactory(String.format("%s-%s", Constants.FRAMEWORK_NAME, "future")));

    this.scheduledExecutorService.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            scanRpcFutureTable();
        }
    }, 0, 5000, TimeUnit.MILLISECONDS);
}
 
开发者ID:TFdream,项目名称:mango,代码行数:17,代码来源:NettyClientImpl.java

示例7: createEpollServer

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
@SuppressWarnings("unused")
private void createEpollServer(Listener listener) {
    EpollEventLoopGroup eventLoopGroup = new EpollEventLoopGroup(
            1, new DefaultThreadFactory(ThreadNames.T_GATEWAY_WORKER)
    );
    eventLoopGroup.setIoRatio(100);
    createServer(listener, eventLoopGroup, EpollDatagramChannel::new);
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:9,代码来源:NettyUDPConnector.java

示例8: doStart

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
@Override
protected void doStart(Listener listener) throws Throwable {
    workerGroup = new NioEventLoopGroup(http_work, new DefaultThreadFactory(ThreadNames.T_HTTP_CLIENT));
    b = new Bootstrap();
    b.group(workerGroup);
    b.channel(NioSocketChannel.class);
    b.option(ChannelOption.SO_KEEPALIVE, true);
    b.option(ChannelOption.TCP_NODELAY, true);
    b.option(ChannelOption.SO_REUSEADDR, true);
    b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 4000);
    b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    b.handler(new ChannelInitializer<SocketChannel>() {
        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            ch.pipeline().addLast("decoder", new HttpResponseDecoder());
            ch.pipeline().addLast("aggregator", new HttpObjectAggregator(maxContentLength));
            ch.pipeline().addLast("encoder", new HttpRequestEncoder());
            ch.pipeline().addLast("handler", new HttpClientHandler(NettyHttpClient.this));
        }
    });
    timer = new HashedWheelTimer(new NamedThreadFactory(T_HTTP_TIMER), 1, TimeUnit.SECONDS, 64);
    listener.onSuccess();
}
 
开发者ID:mpusher,项目名称:mpush,代码行数:24,代码来源:NettyHttpClient.java

示例9: startServers

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public void startServers() throws Exception {
	int bossThreadCount = Settings.INSTANCE.getInt("netty.bossThreadCount", 0);
	int workerThreadCount = Settings.INSTANCE.getInt("netty.workerThreadCount", 0);

	ThreadFactory bossThreadFactory = new DefaultThreadFactory("lannister/boss");
	ThreadFactory workerThreadFactory = new DefaultThreadFactory("lannister/worker");

	if (Literals.NETTY_EPOLL.equals(Settings.INSTANCE.nettyTransportMode())) {
		bossGroup = new EpollEventLoopGroup(bossThreadCount, bossThreadFactory);
		workerGroup = new EpollEventLoopGroup(workerThreadCount, workerThreadFactory);
	}
	else {
		bossGroup = new NioEventLoopGroup(bossThreadCount, bossThreadFactory);
		workerGroup = new NioEventLoopGroup(workerThreadCount, workerThreadFactory);
	}

	mqttServer = new MqttServer(bossGroup, workerGroup);
	mqttServer.start();

	webServer = new WebServer(bossGroup, workerGroup);
	webServer.start("net.anyflow");
}
 
开发者ID:anyflow,项目名称:lannister,代码行数:23,代码来源:Application.java

示例10: testDoubleIpAddress

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
@Test
public void testDoubleIpAddress() throws Exception {
    String serviceUrl = "pulsar://non-existing-dns-name:" + BROKER_PORT;

    ClientConfiguration conf = new ClientConfiguration();
    EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, new DefaultThreadFactory("test"));
    ConnectionPool pool = Mockito.spy(new ConnectionPool(conf, eventLoop));
    PulsarClientImpl client = new PulsarClientImpl(serviceUrl, conf, eventLoop, pool);

    List<InetAddress> result = Lists.newArrayList();

    // Add a non existent IP to the response to check that we're trying the 2nd address as well
    result.add(InetAddress.getByName("127.0.0.99"));
    result.add(InetAddress.getByName("127.0.0.1"));
    Mockito.when(pool.resolveName("non-existing-dns-name")).thenReturn(CompletableFuture.completedFuture(result));

    // Create producer should succeed by trying the 2nd IP
    client.createProducer("persistent://sample/standalone/ns/my-topic");
    client.close();
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:21,代码来源:ConnectionPoolTest.java

示例11: PulsarClientImpl

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public PulsarClientImpl(String serviceUrl, ClientConfiguration conf, EventLoopGroup eventLoopGroup,
        ConnectionPool cnxPool)
        throws PulsarClientException {
    if (isBlank(serviceUrl) || conf == null || eventLoopGroup == null) {
        throw new PulsarClientException.InvalidConfigurationException("Invalid client configuration");
    }
    this.eventLoopGroup = eventLoopGroup;
    this.conf = conf;
    conf.getAuthentication().start();
    this.cnxPool = cnxPool;
    if (serviceUrl.startsWith("http")) {
        lookup = new HttpLookupService(serviceUrl, conf, eventLoopGroup);
    } else {
        lookup = new BinaryProtoLookupService(this, serviceUrl, conf.isUseTls());
    }
    timer = new HashedWheelTimer(new DefaultThreadFactory("pulsar-timer"), 1, TimeUnit.MILLISECONDS);
    externalExecutorProvider = new ExecutorProvider(conf.getListenerThreads(), "pulsar-external-listener");
    producers = Maps.newIdentityHashMap();
    consumers = Maps.newIdentityHashMap();
    state.set(State.Open);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:22,代码来源:PulsarClientImpl.java

示例12: NettyConnector

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public NettyConnector(InetSocketAddress isa, final TransportConfig transportConfig) {
    workerGroup = new NioEventLoopGroup(1, new DefaultThreadFactory("N4C-Work"));
    clientBoot = new Bootstrap().group(workerGroup).channel(NioSocketChannel.class);
    clientBoot.option(ChannelOption.TCP_NODELAY, true);
    clientBoot.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, transportConfig.getConnectTimeout());
    clientBoot.option(ChannelOption.SO_RCVBUF, 8 * 1024).option(ChannelOption.SO_SNDBUF, 8 * 1024);
    clientBoot.handler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
            TransportProtocolDecoder decoder = new TransportProtocolDecoder();
            decoder.setMaxObjectSize(transportConfig.getMaxSize());
            TransportProtocolEncoder encoder = new TransportProtocolEncoder();
            encoder.setMaxObjectSize(transportConfig.getMaxSize());
            ch.pipeline().addLast("TransportProtocolDecoder", decoder);
            ch.pipeline().addLast("TransportProtocolEncoder", encoder);

            int intervalSeconds = transportConfig.getHeartbeatIntervalSeconds();
            ch.pipeline().addLast("IdleStateHandler", new IdleStateHandler(0, intervalSeconds, 0));
            ch.pipeline().addLast("NettyClientHandler", new NettyClientHandler());
        }
    });

    clientBoot.remoteAddress(isa);
}
 
开发者ID:dinstone,项目名称:jrpc,代码行数:26,代码来源:NettyConnector.java

示例13: run

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
public void run() throws Exception {
    final ThreadFactory connectFactory = new DefaultThreadFactory("rendezvous");
    final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
            connectFactory, NioUdtProvider.BYTE_PROVIDER);
    try {
        final Bootstrap bootstrap = new Bootstrap();
        bootstrap.group(connectGroup)
                .channelFactory(NioUdtProvider.BYTE_RENDEZVOUS)
                .handler(new ChannelInitializer<UdtChannel>() {
                    @Override
                    protected void initChannel(UdtChannel ch) throws Exception {
                        ch.pipeline().addLast(
                                new LoggingHandler(LogLevel.INFO),
                                new ByteEchoPeerHandler(messageSize));
                    }
                });
        final ChannelFuture future = bootstrap.connect(peerAddress, myAddress).sync();
        future.channel().closeFuture().sync();
    } finally {
        connectGroup.shutdownGracefully();
    }
}
 
开发者ID:cowthan,项目名称:JavaAyo,代码行数:23,代码来源:ByteEchoPeerBase.java

示例14: NettyCenter

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
/**
 * 私有构造函数
 */
private NettyCenter() {
    int maybeThreadSize = Runtime.getRuntime().availableProcessors();
    if (maybeThreadSize == 1) maybeThreadSize += 2;
    else if (maybeThreadSize == 8) maybeThreadSize = 2;
    else if (maybeThreadSize > 8) maybeThreadSize /= 2;
    /**
     * 构造事件循环组
     */
    eventLoopGroup = new NioEventLoopGroup(maybeThreadSize, new DefaultThreadFactory("NettyNioLoopGroup"));
    /**
     * 构造定时器
     */
    hashedWheelTimer = new HashedWheelTimer(new DefaultThreadFactory("NettyHashedWheelTimer"));
    /**
     * 构造 SSL 环境
     */
    try {
        SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
        sslContextBuilder.clientAuth(ClientAuth.OPTIONAL);
        simpleClientSslContext = sslContextBuilder.build();
    } catch (Throwable e) {
        log.error("NettyCenter :: initialize client sslcontext error!", e);
    }
}
 
开发者ID:316181444,项目名称:GameServerFramework,代码行数:28,代码来源:NettyCenter.java

示例15: ApiServerChannelInitializer

import io.netty.util.concurrent.DefaultThreadFactory; //导入依赖的package包/类
@Inject
    public ApiServerChannelInitializer(ObjectMapper objectMapper,
                                       ApiProtocolSwitcher apiProtocolSwitcher,
//                                       ObservableEncoder rxjavaHandler,
                                       GeneratedJaxRsModuleHandler jaxRsModuleHandler) {
        this.apiProtocolSwitcher = apiProtocolSwitcher;
//        this.rxjavaHandler = rxjavaHandler;
        this.jaxRsHandlers =  jaxRsModuleHandler;
        SimpleModule nettyModule = new SimpleModule("Netty", PackageVersion.VERSION);
        nettyModule.addSerializer(new ByteBufSerializer());
        objectMapper.registerModule(nettyModule);
        // TODO: allow customization of the thread pool!
//        rxJavaGroup = new DefaultEventExecutorGroup(4, new DefaultThreadFactory("rxjava"));
        jaxRsGroup = new DefaultEventExecutorGroup(Runtime.getRuntime().availableProcessors(),
                new DefaultThreadFactory("jax-rs"));
    }
 
开发者ID:kalixia,项目名称:kha,代码行数:17,代码来源:ApiServerChannelInitializer.java


注:本文中的io.netty.util.concurrent.DefaultThreadFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。