use of com.google.common.util.concurrent.ThreadFactoryBuilder in project hbase by apache.
the class Replication method initialize.
public void initialize(final Server server, final FileSystem fs, final Path logDir, final Path oldLogDir) throws IOException {
this.server = server;
this.conf = this.server.getConfiguration();
this.replicationForBulkLoadData = isReplicationForBulkLoadDataEnabled(this.conf);
this.scheduleThreadPool = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat(server.getServerName().toShortString() + "Replication Statistics #%d").setDaemon(true).build());
if (this.replicationForBulkLoadData) {
if (conf.get(HConstants.REPLICATION_CLUSTER_ID) == null || conf.get(HConstants.REPLICATION_CLUSTER_ID).isEmpty()) {
throw new IllegalArgumentException(HConstants.REPLICATION_CLUSTER_ID + " cannot be null/empty when " + HConstants.REPLICATION_BULKLOAD_ENABLE_KEY + " is set to true.");
}
}
try {
this.replicationQueues = ReplicationFactory.getReplicationQueues(new ReplicationQueuesArguments(conf, this.server, server.getZooKeeper()));
this.replicationQueues.init(this.server.getServerName().toString());
this.replicationPeers = ReplicationFactory.getReplicationPeers(server.getZooKeeper(), this.conf, this.server);
this.replicationPeers.init();
this.replicationTracker = ReplicationFactory.getReplicationTracker(server.getZooKeeper(), this.replicationPeers, this.conf, this.server, this.server);
} catch (Exception e) {
throw new IOException("Failed replication handler create", e);
}
UUID clusterId = null;
try {
clusterId = ZKClusterId.getUUIDForCluster(this.server.getZooKeeper());
} catch (KeeperException ke) {
throw new IOException("Could not read cluster id", ke);
}
this.replicationManager = new ReplicationSourceManager(replicationQueues, replicationPeers, replicationTracker, conf, this.server, fs, logDir, oldLogDir, clusterId);
this.statsThreadPeriod = this.conf.getInt("replication.stats.thread.period.seconds", 5 * 60);
LOG.debug("ReplicationStatisticsThread " + this.statsThreadPeriod);
this.replicationLoad = new ReplicationLoad();
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project hbase by apache.
the class ThriftServerRunner method createExecutor.
ExecutorService createExecutor(BlockingQueue<Runnable> callQueue, int minWorkers, int maxWorkers) {
ThreadFactoryBuilder tfb = new ThreadFactoryBuilder();
tfb.setDaemon(true);
tfb.setNameFormat("thrift-worker-%d");
ThreadPoolExecutor threadPool = new THBaseThreadPoolExecutor(minWorkers, maxWorkers, Long.MAX_VALUE, TimeUnit.SECONDS, callQueue, tfb.build(), metrics);
threadPool.allowCoreThreadTimeOut(true);
return threadPool;
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project druid by druid-io.
the class ExecsTest method runTest.
private static void runTest(final int capacity) throws Exception {
final int nTasks = (capacity + 1) * 3;
final ExecutorService blockingExecutor = Execs.newBlockingSingleThreaded("ExecsTest-Blocking-%d", capacity);
final CountDownLatch queueShouldBeFullSignal = new CountDownLatch(capacity + 1);
final CountDownLatch taskCompletedSignal = new CountDownLatch(nTasks);
final CountDownLatch taskStartSignal = new CountDownLatch(1);
final AtomicInteger producedCount = new AtomicInteger();
final AtomicInteger consumedCount = new AtomicInteger();
final ExecutorService producer = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("ExecsTest-Producer-%d").build());
producer.submit(new Runnable() {
public void run() {
for (int i = 0; i < nTasks; i++) {
final int taskID = i;
System.out.println("Produced task" + taskID);
blockingExecutor.submit(new Runnable() {
@Override
public void run() {
log.info("Starting task: %s", taskID);
try {
taskStartSignal.await();
consumedCount.incrementAndGet();
taskCompletedSignal.countDown();
} catch (Exception e) {
throw Throwables.propagate(e);
}
log.info("Completed task: %s", taskID);
}
});
producedCount.incrementAndGet();
queueShouldBeFullSignal.countDown();
}
}
});
queueShouldBeFullSignal.await();
// Verify that the producer blocks. I don't think it's possible to be sure that the producer is blocking (since
// it could be doing nothing for any reason). But waiting a short period of time and checking that it hasn't done
// anything should hopefully be sufficient.
Thread.sleep(500);
Assert.assertEquals(capacity + 1, producedCount.get());
// let the tasks run
taskStartSignal.countDown();
// wait until all tasks complete
taskCompletedSignal.await();
// verify all tasks consumed
Assert.assertEquals(nTasks, consumedCount.get());
// cleanup
blockingExecutor.shutdown();
producer.shutdown();
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project druid by druid-io.
the class PrioritizedListenableFutureTask method create.
public static PrioritizedExecutorService create(Lifecycle lifecycle, DruidProcessingConfig config) {
final PrioritizedExecutorService service = new PrioritizedExecutorService(new ThreadPoolExecutor(config.getNumThreads(), config.getNumThreads(), 0L, TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>(), new ThreadFactoryBuilder().setDaemon(true).setNameFormat(config.getFormatString()).build()), config);
lifecycle.addHandler(new Lifecycle.Handler() {
@Override
public void start() throws Exception {
}
@Override
public void stop() {
service.shutdownNow();
}
});
return service;
}
use of com.google.common.util.concurrent.ThreadFactoryBuilder in project hbase by apache.
the class BulkAssigner method bulkAssign.
/**
* Run the bulk assign.
*
* @param sync
* Whether to assign synchronously.
* @throws InterruptedException
* @return True if done.
* @throws IOException
*/
public boolean bulkAssign(boolean sync) throws InterruptedException, IOException {
boolean result = false;
ThreadFactoryBuilder builder = new ThreadFactoryBuilder();
builder.setDaemon(true);
builder.setNameFormat(getThreadNamePrefix() + "-%1$d");
builder.setUncaughtExceptionHandler(getUncaughtExceptionHandler());
int threadCount = getThreadCount();
java.util.concurrent.ExecutorService pool = Executors.newFixedThreadPool(threadCount, builder.build());
try {
populatePool(pool);
// RIT monitor should do fixup.
if (sync)
result = waitUntilDone(getTimeoutOnRIT());
} finally {
// We're done with the pool. It'll exit when its done all in queue.
pool.shutdown();
}
return result;
}
Aggregations