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.locationtech.geogig.data.retrieve.BackgroundingIterator.java

public BackgroundingIterator(Iterator<T> underlyingIterator, int queueSize) {
    if (underlyingIterator == null) {
        throw new IllegalArgumentException("underlyingIterator is null");
    }//  w w w .j a  va 2s.  c om
    queue = new ArrayBlockingQueue<Object>(queueSize);
    producer = new Producer(underlyingIterator, queue);
    ThreadFactory nameThreadFactory = new ThreadFactoryBuilder().setNameFormat("backgrounding-iterator-%d")
            .build();
    executorService = Executors.newSingleThreadExecutor(nameThreadFactory);
    future = executorService.submit(producer);
}

From source file:com.facebook.swift.service.ThriftServer.java

@Inject
public ThriftServer(TProcessor processor, ThriftServerConfig config, @ThriftServerTimer Timer timer) {
    TProcessorFactory processorFactory = new TProcessorFactory(processor);

    port = getSpecifiedOrRandomPort(config);

    workerThreads = config.getWorkerThreads();

    workerExecutor = newFixedThreadPool(workerThreads,
            new ThreadFactoryBuilder().setNameFormat("thrift-worker-%s").build());
    acceptorExecutor = newCachedThreadPool(
            new ThreadFactoryBuilder().setNameFormat("thrift-acceptor-%s").build());
    ioExecutor = newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat("thrift-io-%s").build());

    ThriftServerDef thriftServerDef = ThriftServerDef.newBuilder().name("thrift").listen(port)
            .limitFrameSizeTo((int) config.getMaxFrameSize().toBytes())
            .clientIdleTimeout(config.getClientIdleTimeout()).withProcessorFactory(processorFactory)
            .using(workerExecutor).build();

    transport = new NettyServerTransport(thriftServerDef, new NettyConfigBuilder(), allChannels, timer);
}

From source file:org.apache.hedwig.client.netty.HedwigClientImpl.java

protected HedwigClientImpl(ClientConfiguration cfg) {
    this(cfg,//from  w w  w .  j  a v  a 2s. c om
            new NioClientSocketChannelFactory(
                    Executors.newCachedThreadPool(
                            new ThreadFactoryBuilder().setNameFormat("HedwigClient-NIOBoss-%d").build()),
                    Executors.newCachedThreadPool(
                            new ThreadFactoryBuilder().setNameFormat("HedwigClient-NIOWorker-%d").build())));
    ownChannelFactory = true;
}

From source file:com.ibasco.agql.core.session.DefaultSessionManager.java

@SuppressWarnings("unchecked")
public DefaultSessionManager(AbstractSessionIdFactory factory) {
    sessionTimer = new HashedWheelTimer(
            new ThreadFactoryBuilder().setNameFormat("timeout-%d").setDaemon(true).build());
    directory = new HashMap<>();
    this.factory = (factory != null) ? factory : new DefaultSessionIdFactory();
    this.factory.setLookup(directory);
}

From source file:io.jsondb.events.EventListenerList.java

public void addCollectionFileChangeListener(CollectionFileChangeListener listener) {
    if (null == listeners) {
        listeners = new ArrayList<CollectionFileChangeListener>();

        listeners.add(listener);/*from w  ww.  j  av a  2  s  .c o  m*/

        collectionFilesWatcherExecutor = Executors.newSingleThreadExecutor(
                new ThreadFactoryBuilder().setNameFormat("jsondb-files-watcher-thread-%d").build());

        try {
            watcher = dbConfig.getDbFilesPath().getFileSystem().newWatchService();
            dbConfig.getDbFilesPath().register(watcher, StandardWatchEventKinds.ENTRY_CREATE,
                    StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
        } catch (IOException e) {
            logger.error("Failed to create the WatchService for the dbFiles location", e);
            throw new JsonDBException("Failed to create the WatchService for the dbFiles location", e);
        }

        collectionFilesWatcherExecutor.execute(new CollectionFilesWatcherRunnable());
    } else {
        listeners.add(listener);
    }
}

From source file:com.ibasco.agql.core.transport.NettyTransport.java

public NettyTransport(ChannelType channelType) {
    this(channelType, Executors.newFixedThreadPool(8,
            new ThreadFactoryBuilder().setNameFormat("transport-el-%d").setDaemon(true).build()));
}

From source file:org.excalibur.core.workflow.flow.WorkflowExecutor.java

public WorkflowExecutor(WorkflowContext context, TaskRepository taskRepository, UserRepository userRepository,
        RegionRepository regionRepository, VirtualMachine node) {
    this.context_ = checkNotNull(context);
    checkNotNull(context.getWorkflowCoordinator(), "The coordinator might not be null!");
    checkNotNull(context.getWorkflowExecutionStrategy(), "The workflow execution policy might not be null!");

    ThreadFactory threadFactory = new ThreadFactoryBuilder()
            .setNameFormat("wket-" + context.getWorkflow().getDescription().getName() + "-%d").build();

    this.taskRepository_ = taskRepository;
    this.userRepository_ = userRepository;
    this.regionRepository_ = regionRepository;

    this.executor_ = DynamicExecutors.newScalingThreadPool(1, context.getWorkflow().getActivities().length, 5,
            TimeUnit.MINUTES, threadFactory);
    context.registerExecutors(this.executor_);
    this.node_ = node;
}

From source file:io.bitsquare.common.util.Utilities.java

public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name, int corePoolSize,
        int maximumPoolSize, long keepAliveTimeInSec) {
    final ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat(name).setDaemon(true)
            .setPriority(Thread.MIN_PRIORITY).build();
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
    executor.setKeepAliveTime(keepAliveTimeInSec, TimeUnit.SECONDS);
    executor.allowCoreThreadTimeOut(true);
    executor.setMaximumPoolSize(maximumPoolSize);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.setRejectedExecutionHandler((r, e) -> {
        log.debug("RejectedExecutionHandler called");
    });// w  w w  .  j  a va 2s. c  o  m
    return executor;
}

From source file:com.codeabovelab.dm.cluman.ds.kv.etcd.EtcdClientWrapper.java

public EtcdClientWrapper(EtcdClient etcd, String prefix) {
    this.etcd = etcd;
    this.prefix = prefix;
    //possibly we need to create better id ob bus
    this.bus = MessageBusImpl
            .builder(KvStorageEvent.class,
                    (s) -> new ConditionalMessageBusWrapper<>(s, KvStorageEvent::getKey, KvUtils::predicate))
            .id(getClass().getName()).build();
    this.executor = Executors.newSingleThreadExecutor(
            new ThreadFactoryBuilder().setNameFormat(getClass().getName() + "-bus-%d").setDaemon(true).build());
    eventWhirligig(-1);/*from   w w  w.j a v  a2 s  .c o  m*/
}

From source file:com.cloudera.livy.rsc.RSCClient.java

RSCClient(RSCClientFactory factory, RSCConf conf, ContextInfo ctx) throws IOException {
    this.ctx = ctx;
    this.factory = factory;
    this.conf = conf;
    this.jobs = Maps.newConcurrentMap();
    this.protocol = new ClientProtocol();
    this.eventLoopGroup = new NioEventLoopGroup(conf.getInt(RPC_MAX_THREADS), new ThreadFactoryBuilder()
            .setNameFormat("Client-RPC-Handler-" + ctx.getClientId() + "-%d").setDaemon(true).build());

    try {/*  w  w  w. j a  va  2  s  .  c o  m*/
        this.driverRpc = Rpc.createClient(conf, eventLoopGroup, ctx.getRemoteAddress(), ctx.getRemotePort(),
                ctx.getClientId(), ctx.getSecret(), protocol).get();
    } catch (Throwable e) {
        ctx.dispose(true);
        throw Throwables.propagate(e);
    }

    driverRpc.addListener(new Rpc.Listener() {
        @Override
        public void rpcClosed(Rpc rpc) {
            if (isAlive) {
                LOG.warn("Client RPC channel closed unexpectedly.");
                isAlive = false;
            }
        }
    });

    isAlive = true;
    LOG.debug("Connected to context {} ({}).", ctx.getClientId(), driverRpc.getChannel());
}