當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。