Example usage for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder

List of usage examples for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder

Introduction

In this page you can find the example usage for com.google.common.util.concurrent ThreadFactoryBuilder ThreadFactoryBuilder.

Prototype

public ThreadFactoryBuilder() 

Source Link

Document

Creates a new ThreadFactory builder.

Usage

From source file:io.druid.java.util.http.client.HttpClientInit.java

public static HttpClient createClient(HttpClientConfig config, Lifecycle lifecycle) {
    try {/*from w  ww  .  j a  v a  2s.com*/
        // We need to use the full constructor in order to set a ThreadNameDeterminer. The other parameters are taken
        // from the defaults in HashedWheelTimer's other constructors.
        final HashedWheelTimer timer = new HashedWheelTimer(
                new ThreadFactoryBuilder().setDaemon(true).setNameFormat("HttpClient-Timer-%s").build(),
                ThreadNameDeterminer.CURRENT, 100, TimeUnit.MILLISECONDS, 512);
        lifecycle.addMaybeStartHandler(new Lifecycle.Handler() {
            @Override
            public void start() {
                timer.start();
            }

            @Override
            public void stop() {
                timer.stop();
            }
        });
        return lifecycle.addMaybeStartManagedInstance(new NettyHttpClient(
                new ResourcePool<>(
                        new ChannelResourceFactory(
                                createBootstrap(
                                        lifecycle, timer, config.getBossPoolSize(), config.getWorkerPoolSize()),
                                config.getSslContext(), timer,
                                config.getSslHandshakeTimeout() == null ? -1
                                        : config.getSslHandshakeTimeout().getMillis()),
                        new ResourcePoolConfig(config.getNumConnections(),
                                config.getUnusedConnectionTimeoutDuration().getMillis())),
                config.getReadTimeout(), config.getCompressionCodec(), timer));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.metamx.druid.client.ClientInventoryManager.java

public ClientInventoryManager(final InventoryManagerConfig config, final PhoneBook yp,
        final MutableServerView serverView) {
    super(log, config, yp);

    this.serverView = serverView;

    this.exec = Executors.newFixedThreadPool(1,
            new ThreadFactoryBuilder().setDaemon(true).setNameFormat("CIV-Execution-%d").build());

    setStrategy(new InventoryManagementStrategy<DruidServer>() {
        @Override/*from w w  w.ja va 2  s  .  c o m*/
        public Class<DruidServer> getContainerClass() {
            return DruidServer.class;
        }

        @Override
        public Pair<String, PhoneBookPeon<?>> makeSubListener(final DruidServer server) {
            ClientInventoryManager.this.serverView.addServer(server);

            return Pair.<String, PhoneBookPeon<?>>of(server.getName(), new PhoneBookPeon<DataSegment>() {
                @Override
                public Class<DataSegment> getObjectClazz() {
                    return DataSegment.class;
                }

                @Override
                public void newEntry(String segmentId, DataSegment segment) {
                    exec.execute(new AddSegmentRunnable(server, segment));
                    server.addDataSegment(segmentId, segment);
                }

                @Override
                public void entryRemoved(String segmentId) {
                    exec.execute(new RemoveSegmentRunnable(server, segmentId));
                    server.removeDataSegment(segmentId);
                }
            });
        }

        @Override
        public void objectRemoved(DruidServer server) {
            ClientInventoryManager.this.serverView.removeServer(server);
        }

        @Override
        public boolean doesSerde() {
            return false;
        }

        @Override
        public DruidServer deserialize(String name, Map<String, String> properties) {
            throw new UnsupportedOperationException();
        }
    });
}

From source file:org.eclipse.che.plugin.maven.server.core.BufferOutputFixedRateSender.java

public BufferOutputFixedRateSender(String channel, long delay) {
    this.channel = channel;
    ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat(BufferOutputFixedRateSender.class.getSimpleName() + "-%d")
            .setUncaughtExceptionHandler(LoggingUncaughtExceptionHandler.getInstance()).setDaemon(true).build();

    executor = Executors.newScheduledThreadPool(1, threadFactory);

    executor.scheduleAtFixedRate(this::sendMessage, 1_000, delay, MILLISECONDS);
}

From source file:org.graylog2.radio.inputs.tcp.TCPInput.java

@Override
public void run() {
    final ExecutorService bossThreadPool = Executors
            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("input-tcp-boss-%d").build());

    final ExecutorService workerThreadPool = Executors
            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("input-tcp-worker-%d").build());

    ServerBootstrap tcpBootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(bossThreadPool, workerThreadPool));

    tcpBootstrap.setPipelineFactory(new TCPPipelineFactory(radio, config));

    try {//from w w  w .j a  v  a2  s .c o  m
        tcpBootstrap.bind(config.getAddress());
    } catch (ChannelException e) {
        LOG.error("Could not bind TCP input {}", config.getAddress(), e);
    }
}

From source file:components.execution.ExecutionModule.java

@Override
protected void configure() {

    bindInterceptor(Matchers.subclassesOf(Runnable.class), Matchers.annotatedWith(Loop.class),
            new LoopRunnableInterceptor());
    bindInterceptor(Matchers.subclassesOf(Runnable.class), Matchers.annotatedWith(Transactional.class),
            new TransactionalRunnableInterceptor(getProvider(JPAApi.class)));

    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("ExecutionService-%d").build();

    bind(ExecutionService.class).toInstance(new StableScheduledThreadExecutor(
            new ScheduledThreadPoolExecutorExecutionService(new LoggingScheduledThreadPoolExecutor(
                    configuration.getInt("colosseum.execution.thread", 10), threadFactory))));
    bind(ExecutionSystemInitialization.class).asEagerSingleton();

    Multibinder.newSetBinder(binder(), Runnable.class);
    Multibinder.newSetBinder(binder(), Schedulable.class);
}

From source file:org.apache.tajo.worker.DeletionService.java

public DeletionService(int defaultThreads, int debugDelay) {
    ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("DeletionService #%d").build();

    sched = new ScheduledThreadPoolExecutor(defaultThreads, tf);
    sched.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    sched.setKeepAliveTime(60L, TimeUnit.SECONDS);
    this.debugDelay = debugDelay;
}

From source file:org.graylog2.inputs.http.GELFHttpInput.java

@Override
public void initialize(final Map<String, String> configuration, GraylogServer graylogServer) {
    final InetSocketAddress socketAddress = new InetSocketAddress(configuration.get("listen_address"),
            Integer.parseInt(configuration.get("listen_port")));

    final ExecutorService bossExecutor = Executors
            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("input-gelfhttp-boss-%d").build());

    final ExecutorService workerExecutor = Executors
            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("input-gelfhttp-worker-%d").build());

    final ServerBootstrap httpBootstrap = new ServerBootstrap(
            new NioServerSocketChannelFactory(bossExecutor, workerExecutor));
    httpBootstrap.setPipelineFactory(new GELFHttpPipelineFactory((Core) graylogServer));

    try {//from w  w  w  .j  a v  a 2 s  .  c  om
        httpBootstrap.bind(socketAddress);
        LOG.debug("Started HTTP GELF server on {}", socketAddress);
    } catch (final ChannelException e) {
        LOG.error("Could not bind HTTP GELF server to address " + socketAddress, e);
    }
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            httpBootstrap.releaseExternalResources();
        }
    });
}

From source file:co.paralleluniverse.fibers.httpclient.FiberHttpClientBuilder.java

/**
 * @param ioThreadCount/*from w w w  . j  ava  2s . co  m*/
 * @return
 */
public static FiberHttpClientBuilder create(int ioThreadCount) {
    return new FiberHttpClientBuilder(HttpAsyncClientBuilder.create()
            .setThreadFactory(new ThreadFactoryBuilder().setDaemon(true).build())
            .setDefaultIOReactorConfig(IOReactorConfig.custom().setIoThreadCount(ioThreadCount).build()));
}

From source file:com.torodb.packaging.guice.ExecutorServicesModule.java

@Override
protected void configure() {

    bind(Integer.class).annotatedWith(ParallelLevel.class)
            .toInstance(Runtime.getRuntime().availableProcessors());

    ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("torodb-%d").build();

    bind(ThreadFactory.class).toInstance(threadFactory);

    bind(ThreadFactory.class).annotatedWith(TorodbIdleService.class).toInstance(threadFactory);

    bind(ThreadFactory.class).annotatedWith(TorodbRunnableService.class).toInstance(threadFactory);

    bind(ThreadFactory.class).annotatedWith(MongoWp.class).toInstance(threadFactory);

    bind(ForkJoinWorkerThreadFactory.class).toInstance(ForkJoinPool.defaultForkJoinWorkerThreadFactory);

    bind(DefaultConcurrentToolsFactory.BlockerThreadFactoryFunction.class)
            .toInstance(new CustomBlockerThreadFactoryFunction());

    bind(DefaultConcurrentToolsFactory.ForkJoinThreadFactoryFunction.class)
            .toInstance(new CustomForkJoinThreadFactoryFunction());
}

From source file:org.eclipse.rdf4j.http.client.SesameClientImpl.java

public SesameClientImpl() {
    this.executor = Executors
            .newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("rdf4j-sesameclientimpl-%d").build());
}