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:org.wso2.carbon.cluster.coordinator.rdbms.RDBMSMemberEventProcessor.java

public RDBMSMemberEventProcessor(String nodeId, DataSource dataSource) {
    this.communicationBusContext = new RDBMSCommunicationBusContextImpl(dataSource);
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder().setNameFormat("ClusterEventReaderTask-%d")
            .build();/* w  w w.  j a  v a  2 s  . c  om*/
    this.clusterMembershipReaderTaskScheduler = Executors.newSingleThreadScheduledExecutor(namedThreadFactory);
    addNewListenerTask(nodeId, dataSource);
}

From source file:org.eclipse.che.ide.extension.maven.server.core.MavenClassPathBuilder.java

@Inject
public MavenClassPathBuilder(ResourcesPlugin resourcesPlugin, ProjectManager projectManager) {
    this.projectManager = projectManager;
    JavaModelManager.getJavaModelManager().containerInitializersCache.put(MavenClasspathContainer.CONTAINER_ID,
            new MavenClasspathContainerInitializer());

    ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat(MavenClassPathBuilder.class.getSimpleName() + "-%d").build();

    executorService = Executors.newFixedThreadPool(5, threadFactory);
}

From source file:org.apache.tajo.rpc.NettyUtils.java

public static EventLoopGroup createEventLoopGroup(String name, int threads) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Create " + name + " EventLoopGroup. threads:" + threads);
    }/*from   w w  w  . jav  a2s .com*/

    ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
    ThreadFactory clientFactory = builder.setNameFormat(name + " #%d").build();

    return createEventLoopGroup(threads, clientFactory);
}

From source file:eu.eubrazilcc.lvl.core.concurrent.TaskScheduler.java

private TaskScheduler() {
    final ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(
            Math.max(MIN_NUM_THREADS, Runtime.getRuntime().availableProcessors()),
            new ThreadFactoryBuilder().setNameFormat(THREAD_NAME_PATTERN).setDaemon(false)
                    .setUncaughtExceptionHandler(TASK_UNCAUGHT_EXCEPTION_HANDLER).build());
    scheduledThreadPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    scheduledThreadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    scheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true);
    scheduler = listeningDecorator(scheduledThreadPoolExecutor);
}

From source file:org.diorite.impl.client.connection.ClientConnection.java

@SuppressWarnings("resource")
public ClientConnection(final DioriteCore core) {
    this.core = core;
    this.setDaemon(true);
    this.setName("{DioritOS|ClientCon}");
    this.nioEventLoopGroupLazyValue = new LazyValue<>(() -> new NioEventLoopGroup(0,
            new ThreadFactoryBuilder().setNameFormat("DioritOS-Netty#%d").setDaemon(true).build()));
    this.epollEventLoopGroupLazyValue = new LazyValue<>(() -> new EpollEventLoopGroup(0,
            new ThreadFactoryBuilder().setNameFormat("DioritOS-Netty#%d").setDaemon(true).build()));
}

From source file:org.graylog2.streams.StreamRouter.java

private ExecutorService executorService() {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("stream-router-%d")
            .setDaemon(true).build();/*  ww  w  .  j a v a 2 s  .c o m*/
    return Executors.newCachedThreadPool(threadFactory);
}

From source file:io.airlift.discovery.store.Replicator.java

@PostConstruct
public synchronized void start() {
    if (future == null) {
        executor = Executors.newSingleThreadScheduledExecutor(
                new ThreadFactoryBuilder().setNameFormat("replicator-" + name + "-%d").setDaemon(true).build());

        future = executor.scheduleAtFixedRate(new Runnable() {
            @Override/*from   w  ww  .  j  a  va2  s.  co  m*/
            public void run() {
                try {
                    synchronize();
                } catch (Throwable t) {
                    log.warn(t, "Error replicating state");
                }
            }
        }, 0, replicationInterval.toMillis(), TimeUnit.MILLISECONDS);
    }

    // TODO: need fail-safe recurrent scheduler with variable delay
}

From source file:org.wso2.andes.kernel.distrupter.DisruptorBasedInboundEventManager.java

public DisruptorBasedInboundEventManager(SubscriptionStore subscriptionStore, MessagingEngine messagingEngine) {

    Integer bufferSize = AndesConfigurationManager
            .readValue(AndesConfiguration.PERFORMANCE_TUNING_PUBLISHING_BUFFER_SIZE);
    Integer writeHandlerCount = AndesConfigurationManager
            .readValue(AndesConfiguration.PERFORMANCE_TUNING_PARALLEL_MESSAGE_WRITERS);
    Integer ackHandlerCount = AndesConfigurationManager
            .readValue(AndesConfiguration.PERFORMANCE_TUNING_ACK_HANDLER_COUNT);
    Integer writerBatchSize = AndesConfigurationManager
            .readValue(AndesConfiguration.PERFORMANCE_TUNING_MESSAGE_WRITER_BATCH_SIZE);
    Integer ackHandlerBatchSize = AndesConfigurationManager
            .readValue(AndesConfiguration.PERFORMANCE_TUNING_ACKNOWLEDGEMENT_HANDLER_BATCH_SIZE);

    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
            .setNameFormat("Disruptor Inbound Event Thread %d").build();
    ExecutorService executorPool = Executors.newCachedThreadPool(namedThreadFactory);

    Disruptor<InboundEvent> disruptor;
    disruptor = new Disruptor<InboundEvent>(InboundEvent.getFactory(), executorPool,
            new MultiThreadedClaimStrategy(bufferSize), new BlockingWaitStrategy());

    // Pre processor runs first then Write handlers and ack handlers run in parallel. State event handler comes
    // after them
    SequenceBarrier barrier = disruptor.handleEventsWith(new MessagePreProcessor(subscriptionStore))
            .asSequenceBarrier();/*from   w  w w.  j  a  v  a2 s .  com*/

    ConcurrentBatchProcessor[] processors = new ConcurrentBatchProcessor[writeHandlerCount + ackHandlerCount];

    for (int turn = 0; turn < writeHandlerCount; turn++) {
        processors[turn] = new ConcurrentBatchProcessor(disruptor.getRingBuffer(), barrier,
                new MessageWriter(messagingEngine, writerBatchSize), turn, writeHandlerCount, writerBatchSize,
                InboundEvent.Type.MESSAGE_EVENT);
    }

    for (int turn = 0; turn < ackHandlerCount; turn++) {
        processors[writeHandlerCount + turn] = new ConcurrentBatchProcessor(disruptor.getRingBuffer(), barrier,
                new AckHandler(), turn, ackHandlerCount, ackHandlerBatchSize,
                InboundEvent.Type.ACKNOWLEDGEMENT_EVENT);
    }

    disruptor.handleEventsWith(processors);

    // State event handler should run at last.
    // State event handler update the state of Andes after other handlers work is done.
    disruptor.after(processors).handleEventsWith(new StateEventHandler(messagingEngine));

    disruptor.handleExceptionsWith(new IgnoreExceptionHandler());
    ringBuffer = disruptor.start();
}

From source file:org.geoserver.cluster.hazelcast.HzSynchronizer.java

ScheduledExecutorService getNewExecutor() {
    return Executors.newSingleThreadScheduledExecutor(
            new ThreadFactoryBuilder().setNameFormat("HzSynchronizer-%d").build());
}

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

public Fetcher(URI uri, File file) {
    this.uri = uri;
    this.file = file;

    String scheme = uri.getScheme() == null ? "http" : uri.getScheme();
    this.host = uri.getHost() == null ? "localhost" : uri.getHost();
    this.port = uri.getPort();
    if (port == -1) {
        if (scheme.equalsIgnoreCase("http")) {
            this.port = 80;
        } else if (scheme.equalsIgnoreCase("https")) {
            this.port = 443;
        }//from ww  w.  j a  v a  2s.  c o  m
    }

    ThreadFactory bossFactory = new ThreadFactoryBuilder().setNameFormat("Fetcher Netty Boss #%d").build();
    ThreadFactory workerFactory = new ThreadFactoryBuilder().setNameFormat("Fetcher Netty Worker #%d").build();

    factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(bossFactory),
            Executors.newCachedThreadPool(workerFactory));

    bootstrap = new ClientBootstrap(factory);
    bootstrap.setOption("connectTimeoutMillis", 5000L); // set 5 sec
    bootstrap.setOption("receiveBufferSize", 1048576); // set 1M
    bootstrap.setOption("tcpNoDelay", true);

    ChannelPipelineFactory factory = new HttpClientPipelineFactory(file);
    bootstrap.setPipelineFactory(factory);
}