本文整理汇总了Java中com.google.common.util.concurrent.ListeningScheduledExecutorService类的典型用法代码示例。如果您正苦于以下问题:Java ListeningScheduledExecutorService类的具体用法?Java ListeningScheduledExecutorService怎么用?Java ListeningScheduledExecutorService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListeningScheduledExecutorService类属于com.google.common.util.concurrent包,在下文中一共展示了ListeningScheduledExecutorService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ApacheThriftMethodInvoker
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
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");
}
示例2: testNoOpScheduledExecutorInvokeAll
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
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
}
}
示例3: getExecutor
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
/**
* 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;
}
}
示例4: testNoOpScheduledExecutorInvokeAll
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
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
}
}
示例5: get
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
@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();
}
示例6: configure
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
@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();
}
示例7: testNoOpScheduledExecutorShutdown
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
public void testNoOpScheduledExecutorShutdown() {
ListeningScheduledExecutorService executor = TestingExecutors.noOpScheduledExecutor();
assertFalse(executor.isShutdown());
assertFalse(executor.isTerminated());
executor.shutdown();
assertTrue(executor.isShutdown());
assertTrue(executor.isTerminated());
}
示例8: newScheduler
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
private static ListeningScheduledExecutorService newScheduler() {
final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1);
scheduler.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
scheduler.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
scheduler.setRemoveOnCancelPolicy(true);
return MoreExecutors.listeningDecorator(scheduler);
}
示例9: ByteStreamUploader
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
/**
* 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;
}
示例10: newScheduler
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
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));
}
示例11: decorate
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
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));
}
}
示例12: valueChanged
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
@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();
}
}
}
示例13: executor_Valid_SetsService
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
@Test
public void executor_Valid_SetsService() {
Key<ListeningScheduledExecutorService> executorServiceKey = Key.get(ListeningScheduledExecutorService.class);
builder.exectuor(executorServiceKey);
assertEquals(executorServiceKey, builder.getService());
}
示例14: MDCPropagatingScheduledExecutorService
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
public MDCPropagatingScheduledExecutorService(ScheduledExecutorService executorService) {
if (executorService instanceof ListeningScheduledExecutorService) {
this.executorService = (ListeningScheduledExecutorService)executorService;
} else {
this.executorService = MoreExecutors.listeningDecorator(executorService);
}
}
示例15: ByteStreamUploader
import com.google.common.util.concurrent.ListeningScheduledExecutorService; //导入依赖的package包/类
/**
* 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;
}