Java 类com.google.common.util.concurrent.ListeningScheduledExecutorService 实例源码

项目:drift    文件:ApacheThriftMethodInvoker.java   
public ApacheThriftMethodInvoker(
        ListeningExecutorService executorService,
        ListeningScheduledExecutorService delayService,
        TTransportFactory transportFactory,
        TProtocolFactory protocolFactory,
        Duration connectTimeout,
        Duration requestTimeout,
        Optional<HostAndPort> socksProxy,
        Optional<SSLContext> sslContext)
{
    this.executorService = requireNonNull(executorService, "executorService is null");
    this.delayService = requireNonNull(delayService, "delayService is null");
    this.transportFactory = requireNonNull(transportFactory, "transportFactory is null");
    this.protocolFactory = requireNonNull(protocolFactory, "protocolFactory is null");
    this.connectTimeoutMillis = Ints.saturatedCast(requireNonNull(connectTimeout, "connectTimeout is null").toMillis());
    this.requestTimeoutMillis = Ints.saturatedCast(requireNonNull(requestTimeout, "requestTimeout is null").toMillis());
    this.socksProxy = requireNonNull(socksProxy, "socksProxy is null");
    this.sslContext = requireNonNull(sslContext, "sslContext is null");
}
项目:guava-mock    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task = new Callable<Boolean>() {
    @Override public Boolean call() {
      taskDone = true;
      return taskDone;
    }
  };
  List<Future<Boolean>> futureList = executor.invokeAll(
      ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:googles-monorepo-demo    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task = new Callable<Boolean>() {
    @Override public Boolean call() {
      taskDone = true;
      return taskDone;
    }
  };
  List<Future<Boolean>> futureList = executor.invokeAll(
      ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:bazel-buildfarm    文件:ByteStreamUploader.java   
/**
 * Creates a new instance.
 *
 * @param instanceName the instance name to be prepended to resource name of the {@code Write}
 *     call. See the {@code ByteStream} service definition for details
 * @param channel the {@link io.grpc.Channel} to use for calls
 * @param callCredentials the credentials to use for authentication. May be {@code null}, in which
 *     case no authentication is performed
 * @param callTimeoutSecs the timeout in seconds after which a {@code Write} gRPC call must be
 *     complete. The timeout resets between retries
 * @param retrier the {@link Retrier} whose backoff strategy to use for retry timings.
 * @param retryService the executor service to schedule retries on. It's the responsibility of the
 *     caller to properly shutdown the service after use. Users should avoid shutting down the
 *     service before {@link #shutdown()} has been called
 */
public ByteStreamUploader(
    @Nullable String instanceName,
    Channel channel,
    @Nullable CallCredentials callCredentials,
    long callTimeoutSecs,
    Retrier retrier,
    ListeningScheduledExecutorService retryService) {
  checkArgument(callTimeoutSecs > 0, "callTimeoutSecs must be gt 0.");

  this.instanceName = instanceName;
  this.channel = channel;
  this.callCredentials = callCredentials;
  this.callTimeoutSecs = callTimeoutSecs;
  this.retrier = retrier;
  this.retryService = retryService;
}
项目:knowledgestore    文件:Data.java   
/**
 * Returns the executor shared by KnowledgeStore components. If no executor is setup using
 * {@link #setExecutor(ScheduledExecutorService)}, an executor is automatically created using
 * the thread number and naming given by system properties
 * {@code eu.fbk.knowledgestore.threadCount} and {@code eu.fbk.knowledgestore.threadNumber}.
 *
 * @return the shared executor
 */
public static ListeningScheduledExecutorService getExecutor() {
    synchronized (executorPrivate) {
        if (executor == null) {
            final String threadName = MoreObjects.firstNonNull(
                    System.getProperty("eu.fbk.knowledgestore.threadName"), "worker-%02d");
            int threadCount = 32;
            try {
                threadCount = Integer.parseInt(System
                        .getProperty("eu.fbk.knowledgestore.threadCount"));
            } catch (final Throwable ex) {
                // ignore
            }
            executor = Util.newScheduler(threadCount, threadName, true);
            executorPrivate.set(true);
        }
        return executor;
    }
}
项目:guava-libraries    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task = new Callable<Boolean>() {
    @Override public Boolean call() {
      taskDone = true;
      return taskDone;
    }
  };
  List<Future<Boolean>> futureList = executor.invokeAll(
      ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:guava    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task =
      new Callable<Boolean>() {
        @Override
        public Boolean call() {
          taskDone = true;
          return taskDone;
        }
      };
  List<Future<Boolean>> futureList =
      executor.invokeAll(ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:guava    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorInvokeAll() throws ExecutionException, InterruptedException {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  taskDone = false;
  Callable<Boolean> task =
      new Callable<Boolean>() {
        @Override
        public Boolean call() {
          taskDone = true;
          return taskDone;
        }
      };
  List<Future<Boolean>> futureList =
      executor.invokeAll(ImmutableList.of(task), 10, TimeUnit.MILLISECONDS);
  Future<Boolean> future = futureList.get(0);
  assertFalse(taskDone);
  assertTrue(future.isDone());
  try {
    future.get();
    fail();
  } catch (CancellationException e) {
    // pass
  }
}
项目:bazel    文件:ByteStreamUploader.java   
/**
 * Creates a new instance.
 *
 * @param instanceName the instance name to be prepended to resource name of the {@code Write}
 *     call. See the {@code ByteStream} service definition for details
 * @param channel the {@link io.grpc.Channel} to use for calls
 * @param callCredentials the credentials to use for authentication. May be {@code null}, in which
 *     case no authentication is performed
 * @param callTimeoutSecs the timeout in seconds after which a {@code Write} gRPC call must be
 *     complete. The timeout resets between retries
 * @param retrier the {@link RemoteRetrier} whose backoff strategy to use for retry timings.
 * @param retryService the executor service to schedule retries on. It's the responsibility of the
 *     caller to properly shutdown the service after use. Users should avoid shutting down the
 *     service before {@link #shutdown()} has been called
 */
public ByteStreamUploader(
    @Nullable String instanceName,
    Channel channel,
    @Nullable CallCredentials callCredentials,
    long callTimeoutSecs,
    RemoteRetrier retrier,
    ListeningScheduledExecutorService retryService) {
  checkArgument(callTimeoutSecs > 0, "callTimeoutSecs must be gt 0.");

  this.instanceName = instanceName;
  this.channel = channel;
  this.callCredentials = callCredentials;
  this.callTimeoutSecs = callTimeoutSecs;
  this.retrier = retrier;
  this.retryService = retryService;
}
项目:zookeeper-lite    文件:ListeningExecutorServiceFactory.java   
@SuppressWarnings("unchecked")
public synchronized <T extends ExecutorService> T get(Class<T> type) {
    if (instances.containsKey(checkNotNull(type))) {
        return (T) instances.get(type).get();
    }
    Factory<? extends ExecutorService> factory = factories.get(type);
    checkArgument(factory != null, type);
    ListeningExecutorService instance = MoreExecutors.listeningDecorator(factory.get());
    ImmutableList<Class<? extends ExecutorService>> types;
    if (instance instanceof ScheduledExecutorService) {
        types = ImmutableList.<Class<? extends ExecutorService>>of(
                ScheduledExecutorService.class,
                ListeningScheduledExecutorService.class);
    } else {
        types = ImmutableList.<Class<? extends ExecutorService>>of(
                ExecutorService.class,
                ListeningExecutorService.class);
    }
    ExecutorServiceService<ListeningExecutorService> service = ExecutorServiceService.newInstance(instance);
    service.startAsync().awaitRunning();
    for (Class<? extends ExecutorService> t: types) {
        instances.put(t, service);
    }
    return (T) service.get();
}
项目:cloudata    文件:BlockStoreModule.java   
@Override
protected void configure() {
    int threads = 16; // TODO: Link to number of cores
    ListeningScheduledExecutorService scheduledExecutor = MoreExecutors.listeningDecorator(Executors
            .newScheduledThreadPool(threads));
    ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());

    ThreadPools executors = new ThreadPools(scheduledExecutor, executor);
    bind(ThreadPools.class).toInstance(executors);

    RedisKeyValueStore redis = new RedisKeyValueStore(redisAddress, executor);
    KeyValueService keyValueService = new RedisKeyValueService(redis);
    bind(KeyValueService.class).toInstance(keyValueService);

    BlobService blobService = new LocalBlobService(executor, basePath);
    bind(BlobService.class).toInstance(blobService);

    bind(VolumeProvider.class).to(CloudVolumeProvider.class).asEagerSingleton();
}
项目:guava-mock    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorShutdown() {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  assertFalse(executor.isShutdown());
  assertFalse(executor.isTerminated());
  executor.shutdown();
  assertTrue(executor.isShutdown());
  assertTrue(executor.isTerminated());
}
项目:ProjectAres    文件:MatchRealtimeScheduler.java   
private static ListeningScheduledExecutorService newScheduler() {
    final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1);
    scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    scheduler.setRemoveOnCancelPolicy(true);
    return MoreExecutors.listeningDecorator(scheduler);
}
项目:googles-monorepo-demo    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorShutdown() {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  assertFalse(executor.isShutdown());
  assertFalse(executor.isTerminated());
  executor.shutdown();
  assertTrue(executor.isShutdown());
  assertTrue(executor.isTerminated());
}
项目:knowledgestore    文件:Util.java   
public static ListeningScheduledExecutorService newScheduler(final int numThreads,
        final String nameFormat, final boolean daemon) {
    final ThreadFactory factory = new ThreadFactoryBuilder().setDaemon(daemon)
            .setNameFormat(nameFormat)
            .setUncaughtExceptionHandler(new UncaughtExceptionHandler() {

                @Override
                public void uncaughtException(final Thread thread, final Throwable ex) {
                    LOGGER.error("Uncaught exception in thread " + thread.getName(), ex);
                }

            }).build();
    return decorate(Executors.newScheduledThreadPool(numThreads, factory));
}
项目:knowledgestore    文件:Util.java   
public static ListeningScheduledExecutorService decorate(
        final ScheduledExecutorService executor) {
    if (executor instanceof MDCScheduledExecutorService) {
        return (MDCScheduledExecutorService) executor;
    } else if (executor instanceof ListeningScheduledExecutorService) {
        return new MDCScheduledExecutorService((ListeningScheduledExecutorService) executor);
    } else {
        // return MoreExecutors.listeningDecorator(executor);
        return new MDCScheduledExecutorService(MoreExecutors.listeningDecorator(executor));
    }
}
项目:guava-libraries    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorShutdown() {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  assertFalse(executor.isShutdown());
  assertFalse(executor.isTerminated());
  executor.shutdown();
  assertTrue(executor.isShutdown());
  assertTrue(executor.isTerminated());
}
项目:otroslogviewer    文件:JumpToCodeSelectionListener.java   
@Override
public void valueChanged(ListSelectionEvent e) {
  boolean hasFocus = otrosApplication.getApplicationJFrame().isFocused();
  final boolean enabled = otrosApplication.getConfiguration().getBoolean(ConfKeys.JUMP_TO_CODE_AUTO_JUMP_ENABLED, false);
  if (hasFocus && enabled && !e.getValueIsAdjusting()) {
    try {
      final LogData logData = dataTableModel.getLogData(table.convertRowIndexToModel(e.getFirstIndex()));
      Optional<Integer> line = Optional.empty();
      if (StringUtils.isNotBlank(logData.getLine()) && StringUtils.isAlphanumeric(logData.getLine())) {
        line = Optional.of(Integer.valueOf(logData.getLine()));
      }
      final LocationInfo li = new LocationInfo(
        Optional.ofNullable(logData.getClazz()).orElseGet(logData::getLoggerName),
        logData.getMethod(), logData.getFile(),
        line,
        Optional.ofNullable(logData.getMessage()));
      final JumpToCodeService jumpToCodeService = otrosApplication.getServices().getJumpToCodeService();
      final boolean ideAvailable = jumpToCodeService.isIdeAvailable();
      if (ideAvailable) {
        scheduledJump.map(input -> {
          input.cancel(false);
          return Boolean.TRUE;
        });
        ListeningScheduledExecutorService scheduledExecutorService = otrosApplication.getServices().getTaskSchedulerService().getListeningScheduledExecutorService();
        delayMs = 300;
        ListenableScheduledFuture<?> jump = scheduledExecutorService.schedule(
          new JumpRunnable(li, jumpToCodeService), delayMs, TimeUnit.MILLISECONDS
        );

        scheduledJump = Optional.of(jump);
      }
    } catch (Exception e1) {
      LOGGER.warn("Can't perform jump to code: " + e1.getMessage(), e1);
      e1.printStackTrace();
    }

  }
}
项目:guava    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorShutdown() {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  assertFalse(executor.isShutdown());
  assertFalse(executor.isTerminated());
  executor.shutdown();
  assertTrue(executor.isShutdown());
  assertTrue(executor.isTerminated());
}
项目:guava    文件:TestingExecutorsTest.java   
public void testNoOpScheduledExecutorShutdown() {
  ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
  assertFalse(executor.isShutdown());
  assertFalse(executor.isTerminated());
  executor.shutdown();
  assertTrue(executor.isShutdown());
  assertTrue(executor.isTerminated());
}
项目:cultivar_old    文件:AbstractReaperModuleBuilderTest.java   
@Test
public void executor_Valid_SetsService() {
    Key<ListeningScheduledExecutorService> executorServiceKey = Key.get(ListeningScheduledExecutorService.class);
    builder.exectuor(executorServiceKey);

    assertEquals(executorServiceKey, builder.getService());
}
项目:incubator-gobblin    文件:MDCPropagatingScheduledExecutorService.java   
public MDCPropagatingScheduledExecutorService(ScheduledExecutorService executorService) {
  if (executorService instanceof ListeningScheduledExecutorService) {
    this.executorService = (ListeningScheduledExecutorService)executorService;
  } else {
    this.executorService = MoreExecutors.listeningDecorator(executorService);
  }
}
项目:cultivar    文件:AbstractReaperModuleBuilderTest.java   
@Test
public void executor_Valid_SetsService() {
    Key<ListeningScheduledExecutorService> executorServiceKey = Key.get(ListeningScheduledExecutorService.class);
    builder.exectuor(executorServiceKey);

    assertEquals(executorServiceKey, builder.getService());
}
项目:zookeeper-lite    文件:ListeningExecutorServiceFactory.java   
public static ListeningExecutorServiceFactory newInstance(
        Factory<? extends ExecutorService> executorFactory,
        Factory<? extends ScheduledExecutorService> scheduledFactory) {
    return new ListeningExecutorServiceFactory(
            ImmutableMap.<Class<? extends ExecutorService>, Factory<? extends ExecutorService>>of(
                    ExecutorService.class, executorFactory,
                    ListeningExecutorService.class, executorFactory,
                    ScheduledExecutorService.class, scheduledFactory,
                    ListeningScheduledExecutorService.class, scheduledFactory));
}
项目:intellij    文件:ConcurrencyUtil.java   
public static ListeningScheduledExecutorService getAppExecutorService() {
  return executor;
}
项目:knowledgestore    文件:Util.java   
MDCScheduledExecutorService(final ListeningScheduledExecutorService delegate) {
    super(Preconditions.checkNotNull(delegate));
}
项目:knowledgestore    文件:Util.java   
@Override
ListeningScheduledExecutorService delegate() {
    return (ListeningScheduledExecutorService) super.delegate();
}
项目:otroslogviewer    文件:TaskSchedulerServiceImpl.java   
@Override
public ListeningScheduledExecutorService getListeningScheduledExecutorService() {
  return listeningScheduledExecutorService;
}
项目:cultivar_old    文件:AbstractReaperModuleBuilderTest.java   
@Test
public void executor_Valid_ReturnsSelf() {
    assertEquals(builder, builder.exectuor(Key.get(ListeningScheduledExecutorService.class)));
}
项目:testgrid    文件:AbstractAgentPlugin.java   
public ListeningScheduledExecutorService getPluginPool() {
    return pluginPool;
}
项目:testgrid    文件:AbstractAgentPlugin.java   
public void setPluginPool(ListeningScheduledExecutorService pluginPool) {
    this.pluginPool = pluginPool;
}
项目:cultivar    文件:AbstractReaperModuleBuilderTest.java   
@Test
public void executor_Valid_ReturnsSelf() {
    assertEquals(builder, builder.exectuor(Key.get(ListeningScheduledExecutorService.class)));
}
项目:cloudbreak    文件:CloudReactorConfiguration.java   
@Bean
ListeningScheduledExecutorService listeningScheduledExecutorService() {
    return MoreExecutors
            .listeningDecorator(new MDCCleanerScheduledExecutor(executorServicePoolSize,
                    new ThreadFactoryBuilder().setNameFormat("cloud-reactor-%d").build()));
}
项目:cloudbreak    文件:TestApplicationContext.java   
@Bean
public ListeningScheduledExecutorService listeningScheduledExecutorService() {
    return MoreExecutors.listeningDecorator(new ScheduledThreadPoolExecutor(1));
}
项目:cloudata    文件:ThreadPools.java   
public ThreadPools(ListeningScheduledExecutorService scheduledExecutor, ListeningExecutorService executor) {
    this.scheduledExecutor = scheduledExecutor;
    this.executor = executor;
}
项目:guava-mock    文件:TestingExecutors.java   
/**
 * Returns a {@link ScheduledExecutorService} that never executes anything.
 *
 * <p>The {@code shutdownNow} method of the returned executor always returns an empty list despite
 * the fact that everything is still technically awaiting execution.
 * The {@code getDelay} method of any {@link ScheduledFuture} returned by the executor will always
 * return the max long value instead of the time until the user-specified delay.
 */
public static ListeningScheduledExecutorService noOpScheduledExecutor() {
  return new NoOpScheduledExecutorService();
}
项目:googles-monorepo-demo    文件:TestingExecutors.java   
/**
 * Returns a {@link ScheduledExecutorService} that never executes anything.
 *
 * <p>The {@code shutdownNow} method of the returned executor always returns an empty list despite
 * the fact that everything is still technically awaiting execution.
 * The {@code getDelay} method of any {@link ScheduledFuture} returned by the executor will always
 * return the max long value instead of the time until the user-specified delay.
 */
public static ListeningScheduledExecutorService noOpScheduledExecutor() {
  return new NoOpScheduledExecutorService();
}
项目:guava-libraries    文件:TestingExecutors.java   
/**
 * Returns a {@link ScheduledExecutorService} that never executes anything.
 *
 * <p>The {@code shutdownNow} method of the returned executor always returns an empty list despite
 * the fact that everything is still technically awaiting execution.
 * The {@code getDelay} method of any {@link ScheduledFuture} returned by the executor will always
 * return the max long value instead of the time until the user-specified delay.
 */
public static ListeningScheduledExecutorService noOpScheduledExecutor() {
  return new NoOpScheduledExecutorService();
}
项目:guava    文件:TestingExecutors.java   
/**
 * Returns a {@link ScheduledExecutorService} that never executes anything.
 *
 * <p>The {@code shutdownNow} method of the returned executor always returns an empty list despite
 * the fact that everything is still technically awaiting execution. The {@code getDelay} method
 * of any {@link ScheduledFuture} returned by the executor will always return the max long value
 * instead of the time until the user-specified delay.
 */
public static ListeningScheduledExecutorService noOpScheduledExecutor() {
  return new NoOpScheduledExecutorService();
}
项目:guava    文件:TestingExecutors.java   
/**
 * Returns a {@link ScheduledExecutorService} that never executes anything.
 *
 * <p>The {@code shutdownNow} method of the returned executor always returns an empty list despite
 * the fact that everything is still technically awaiting execution. The {@code getDelay} method
 * of any {@link ScheduledFuture} returned by the executor will always return the max long value
 * instead of the time until the user-specified delay.
 */
public static ListeningScheduledExecutorService noOpScheduledExecutor() {
  return new NoOpScheduledExecutorService();
}