use of org.apache.cassandra.concurrent.NamedThreadFactory in project cassandra by apache.
the class SimpleClient method establishConnection.
@VisibleForTesting
void establishConnection() throws IOException {
// Configure the client.
bootstrap = new Bootstrap().group(new NioEventLoopGroup(new NamedThreadFactory("SimpleClient-nioEventLoopGroup"))).channel(io.netty.channel.socket.nio.NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true);
// Configure the pipeline factory.
if (encryptionOptions.isEnabled()) {
bootstrap.handler(new SecureInitializer(largeMessageThreshold));
} else {
bootstrap.handler(new Initializer(largeMessageThreshold));
}
ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
// Wait until the connection attempt succeeds or fails.
channel = future.awaitUninterruptibly().channel();
if (!future.isSuccess()) {
bootstrap.group().shutdownGracefully();
throw new IOException("Connection Error", future.cause());
}
}
use of org.apache.cassandra.concurrent.NamedThreadFactory in project cassandra by apache.
the class AssertUtil method assertTimeoutPreemptively.
private static <T> T assertTimeoutPreemptively(StackTraceElement caller, Duration timeout, ThrowingSupplier<T> supplier) {
String[] split = caller.getClassName().split("\\.");
String simpleClassName = split[split.length - 1];
ExecutorService executorService = Executors.newSingleThreadExecutor(new NamedThreadFactory("TimeoutTest-" + simpleClassName + "#" + caller.getMethodName()));
try {
Future<T> future = executorService.submit(() -> {
try {
return supplier.get();
} catch (Throwable throwable) {
throw Throwables.throwAsUncheckedException(throwable);
}
});
long timeoutInNanos = timeout.toNanos();
try {
return future.get(timeoutInNanos, TimeUnit.NANOSECONDS);
} catch (TimeoutException ex) {
future.cancel(true);
Map<Thread, StackTraceElement[]> threadDump = Thread.getAllStackTraces();
StringBuilder sb = new StringBuilder("execution timed out after ").append(TimeUnit.NANOSECONDS.toMillis(timeoutInNanos)).append(" ms\n");
Multimap<List<StackTraceElement>, Thread> groupCommonThreads = HashMultimap.create();
for (Map.Entry<Thread, StackTraceElement[]> e : threadDump.entrySet()) groupCommonThreads.put(Arrays.asList(e.getValue()), e.getKey());
for (Map.Entry<List<StackTraceElement>, Collection<Thread>> e : groupCommonThreads.asMap().entrySet()) {
sb.append("Threads: ");
Joiner.on(", ").appendTo(sb, e.getValue().stream().map(Thread::getName).iterator());
sb.append("\n");
for (StackTraceElement elem : e.getKey()) sb.append("\t").append(elem.getClassName()).append(".").append(elem.getMethodName()).append("[").append(elem.getLineNumber()).append("]\n");
sb.append("\n");
}
throw new AssertionError(sb.toString());
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw Throwables.throwAsUncheckedException(e);
} catch (ExecutionException ex) {
throw Throwables.throwAsUncheckedException(ex.getCause());
} catch (Throwable ex) {
throw Throwables.throwAsUncheckedException(ex);
}
} finally {
executorService.shutdownNow();
}
}
use of org.apache.cassandra.concurrent.NamedThreadFactory in project eiger by wlloyd.
the class MessagingService method stream.
/**
* Stream a file from source to destination. This is highly optimized
* to not hold any of the contents of the file in memory.
* @param header Header contains file to stream and other metadata.
* @param to endpoint to which we need to stream the file.
*/
public void stream(StreamHeader header, InetAddress to) {
DebuggableThreadPoolExecutor executor = streamExecutors.get(to);
if (executor == null) {
// Using a core pool size of 0 is important. See documentation of streamExecutors.
executor = new DebuggableThreadPoolExecutor(0, 1, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("Streaming to " + to));
DebuggableThreadPoolExecutor old = streamExecutors.putIfAbsent(to, executor);
if (old != null) {
executor.shutdown();
executor = old;
}
}
executor.execute(new FileStreamTask(header, to));
}
use of org.apache.cassandra.concurrent.NamedThreadFactory in project cassandra by apache.
the class SSTableReader method initSyncExecutor.
private static ScheduledThreadPoolExecutor initSyncExecutor() {
if (DatabaseDescriptor.isClientOrToolInitialized())
return null;
// Do NOT start this thread pool in client mode
ScheduledThreadPoolExecutor syncExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("read-hotness-tracker"));
// Immediately remove readMeter sync task when cancelled.
syncExecutor.setRemoveOnCancelPolicy(true);
return syncExecutor;
}
Aggregations