Search in sources :

Example 1 with NamedThreadFactory

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());
    }
}
Also used : NamedThreadFactory(org.apache.cassandra.concurrent.NamedThreadFactory) InetSocketAddress(java.net.InetSocketAddress) io.netty.channel(io.netty.channel) Bootstrap(io.netty.bootstrap.Bootstrap) IOException(java.io.IOException) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with NamedThreadFactory

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();
    }
}
Also used : NamedThreadFactory(org.apache.cassandra.concurrent.NamedThreadFactory) Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with NamedThreadFactory

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));
}
Also used : DebuggableThreadPoolExecutor(org.apache.cassandra.concurrent.DebuggableThreadPoolExecutor) NamedThreadFactory(org.apache.cassandra.concurrent.NamedThreadFactory) FileStreamTask(org.apache.cassandra.streaming.FileStreamTask) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue)

Example 4 with NamedThreadFactory

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;
}
Also used : NamedThreadFactory(org.apache.cassandra.concurrent.NamedThreadFactory)

Aggregations

NamedThreadFactory (org.apache.cassandra.concurrent.NamedThreadFactory)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 HashMultimap (com.google.common.collect.HashMultimap)1 Multimap (com.google.common.collect.Multimap)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 io.netty.channel (io.netty.channel)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 TimeoutException (java.util.concurrent.TimeoutException)1 DebuggableThreadPoolExecutor (org.apache.cassandra.concurrent.DebuggableThreadPoolExecutor)1 FileStreamTask (org.apache.cassandra.streaming.FileStreamTask)1