Example usage for com.google.common.util.concurrent MoreExecutors listeningDecorator

List of usage examples for com.google.common.util.concurrent MoreExecutors listeningDecorator

Introduction

In this page you can find the example usage for com.google.common.util.concurrent MoreExecutors listeningDecorator.

Prototype

@GwtIncompatible("TODO")
public static ListeningScheduledExecutorService listeningDecorator(ScheduledExecutorService delegate) 

Source Link

Document

Creates a ScheduledExecutorService whose submit and invokeAll methods submit ListenableFutureTask instances to the given delegate executor.

Usage

From source file:org.apache.tez.dag.app.dag.RootInputInitializerRunner.java

@SuppressWarnings("rawtypes")
public RootInputInitializerRunner(String dagName, String vertexName, TezVertexID vertexID,
        EventHandler eventHandler, UserGroupInformation dagUgi, int numTasks) {
    this.dagName = dagName;
    this.vertexName = vertexName;
    this.vertexID = vertexID;
    this.eventHandler = eventHandler;
    this.numTasks = numTasks;
    this.rawExecutor = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true)
            .setNameFormat("InputInitializer [" + this.vertexName + "] #%d").build());
    this.executor = MoreExecutors.listeningDecorator(rawExecutor);
    this.dagUgi = dagUgi;
}

From source file:io.druid.query.ChainedExecutionQueryRunner.java

public ChainedExecutionQueryRunner(ExecutorService exec, Ordering<T> ordering, QueryWatcher queryWatcher,
        Iterable<QueryRunner<T>> queryables) {
    // listeningDecorator will leave PrioritizedExecutorService unchanged,
    // since it already implements ListeningExecutorService
    this.exec = MoreExecutors.listeningDecorator(exec);
    this.ordering = ordering;
    this.queryables = Iterables.unmodifiableIterable(queryables);
    this.queryWatcher = queryWatcher;
}

From source file:de.matzefratze123.heavyspleef.persistence.handler.ForwardingAsyncReadWriteHandler.java

public ForwardingAsyncReadWriteHandler(ReadWriteHandler delegate, final Plugin plugin, boolean forceAsync) {
    this.delegate = delegate;
    this.forceAsync = forceAsync;
    this.plugin = plugin;

    final UncaughtExceptionHandler exceptionHandler = new UncaughtExceptionHandler() {

        @Override//from   ww w.ja  v a2 s .  c o m
        public void uncaughtException(Thread thread, Throwable e) {
            plugin.getLogger().log(Level.SEVERE, "Uncaught exception in database thread:", e);
        }
    };

    final ThreadFactory threadFactory = new ThreadFactory() {

        @Override
        public Thread newThread(Runnable runnable) {
            Thread thread = new Thread(runnable);
            thread.setUncaughtExceptionHandler(exceptionHandler);
            thread.setName("Persistence-Thread");

            return thread;
        }
    };

    ExecutorService plainService = Executors.newFixedThreadPool(1, threadFactory);
    this.executorService = MoreExecutors.listeningDecorator(plainService);
}

From source file:com.sk89q.worldguard.WorldGuard.java

public void setup() {
    executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(0, 1, 20));

    File cacheDir = new File(getPlatform().getConfigDir().toFile(), "cache");
    cacheDir.mkdirs();//from   w  w  w . j a va 2 s.c  om

    try {
        profileCache = new SQLiteCache(new File(cacheDir, "profiles.sqlite"));
    } catch (IOException e) {
        WorldGuard.logger.log(Level.WARNING, "Failed to initialize SQLite profile cache");
        profileCache = new HashMapCache();
    }

    profileService = new CacheForwardingService(
            new CombinedProfileService(BukkitPlayerService.getInstance(), HttpRepositoryService.forMinecraft()),
            profileCache);

    getPlatform().load();
}

From source file:org.apache.druid.query.ChainedExecutionQueryRunner.java

public ChainedExecutionQueryRunner(ExecutorService exec, QueryWatcher queryWatcher,
        Iterable<QueryRunner<T>> queryables) {
    // listeningDecorator will leave PrioritizedExecutorService unchanged,
    // since it already implements ListeningExecutorService
    this.exec = MoreExecutors.listeningDecorator(exec);
    this.queryables = Iterables.unmodifiableIterable(queryables);
    this.queryWatcher = queryWatcher;
}

From source file:com.linkedin.pinot.core.query.scheduler.QueryScheduler.java

public QueryScheduler(@Nonnull Configuration schedulerConfig, QueryExecutor queryExecutor) {
    Preconditions.checkNotNull(schedulerConfig);
    numQueryRunnerThreads = schedulerConfig.getInt(QUERY_RUNNER_CONFIG_KEY, DEFAULT_QUERY_RUNNER_THREADS);
    numQueryWorkerThreads = schedulerConfig.getInt(QUERY_WORKER_CONFIG_KEY, DEFAULT_QUERY_WORKER_THREADS);
    queryRunners = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryRunnerThreads));
    queryWorkers = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numQueryWorkerThreads));
    this.queryExecutor = queryExecutor;
}

From source file:org.openhab.binding.flicbutton.handler.FlicDaemonBridgeHandler.java

private void listenToFlicDaemonAsync() throws UnknownHostException {
    FlicDaemonBridgeEventListener flicDaemonEventListener = new FlicDaemonBridgeEventListener(this);
    FlicDaemonClientRunner flicClientService = new FlicDaemonClientRunner(flicDaemonEventListener,
            cfg.getHostname(), cfg.getPort());

    ListeningExecutorService listeningExecutor = MoreExecutors.listeningDecorator(scheduler);
    flicClientFuture = listeningExecutor.submit(flicClientService);
}

From source file:com.newlandframework.rpc.netty.MessageRecvExecutor.java

public static void submit(Callable<Boolean> task, final ChannelHandlerContext ctx, final MessageRequest request,
        final MessageResponse response) {
    if (threadPoolExecutor == null) {
        synchronized (MessageRecvExecutor.class) {
            if (threadPoolExecutor == null) {
                threadPoolExecutor = MoreExecutors
                        .listeningDecorator((ThreadPoolExecutor) (RpcSystemConfig.isMonitorServerSupport()
                                ? RpcThreadPool.getExecutorWithJmx(threadNums, queueNums)
                                : RpcThreadPool.getExecutor(threadNums, queueNums)));
            }//  ww  w . j  av a2s .c o  m
        }
    }

    ListenableFuture<Boolean> listenableFuture = threadPoolExecutor.submit(task);
    Futures.addCallback(listenableFuture, new FutureCallback<Boolean>() {
        public void onSuccess(Boolean result) {
            ctx.writeAndFlush(response).addListener(new ChannelFutureListener() {
                public void operationComplete(ChannelFuture channelFuture) throws Exception {
                    System.out.println("RPC Server Send message-id respone:" + request.getMessageId());
                }
            });
        }

        public void onFailure(Throwable t) {
            t.printStackTrace();
        }
    }, threadPoolExecutor);
}

From source file:org.opendaylight.controller.sal.binding.impl.MountPointManagerImpl.java

private synchronized BindingMountPointImpl createOrGetMountPointImpl(final InstanceIdentifier<?> path) {
    BindingMountPointImpl potential = getMountPoint(path);
    if (potential != null) {
        return potential;
    }//from w ww . ja  va  2 s  .c o m
    RpcProviderRegistryImpl rpcRegistry = new RpcProviderRegistryImpl("mount");
    NotificationBrokerImpl notificationBroker = new NotificationBrokerImpl(getNotificationExecutor());
    DataBrokerImpl dataBroker = new DataBrokerImpl();
    dataBroker.setExecutor(MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()));
    BindingMountPointImpl mountInstance = new BindingMountPointImpl(path, rpcRegistry, notificationBroker,
            dataBroker);
    mountPoints.putIfAbsent(path, mountInstance);
    notifyMountPointCreated(path);
    return mountInstance;
}

From source file:com.voxelplugineering.voxelsniper.service.eventbus.AsyncEventBus.java

/**
 * Creates a new {@link AsyncEventBus}.//from   w  ww .j  a v  a  2  s. co m
 * 
 * @param context The context
 * @param executorService The {@link ExecutorService} to use for asynchronous task delegation
 */
public AsyncEventBus(Context context, ExecutorService executorService) {
    this(context);
    checkNotNull(executorService);
    this.executor = MoreExecutors.listeningDecorator(executorService);
    this.explicitExecutor = true;
}