com.google.common.util.concurrent.ListeningScheduledExecutorService Java Examples
The following examples show how to use
com.google.common.util.concurrent.ListeningScheduledExecutorService.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistenceShutdownHook.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Inject PersistenceShutdownHook(final @NotNull ClientSessionPersistence clientSessionPersistence, final @NotNull ClientSessionSubscriptionPersistence clientSessionSubscriptionPersistence, final @NotNull IncomingMessageFlowPersistence incomingMessageFlowPersistence, final @NotNull RetainedMessagePersistence retainedMessagePersistence, final @NotNull PublishPayloadPersistence payloadPersistence, final @NotNull ClientQueuePersistence clientQueuePersistence, final @NotNull @Persistence ListeningExecutorService persistenceExecutorService, final @NotNull @Persistence ListeningScheduledExecutorService persistenceScheduledExecutorService, final @NotNull @PayloadPersistence ListeningScheduledExecutorService payloadPersistenceExecutor, final @NotNull SingleWriterService singleWriterService) { this.clientSessionPersistence = clientSessionPersistence; this.clientSessionSubscriptionPersistence = clientSessionSubscriptionPersistence; this.incomingMessageFlowPersistence = incomingMessageFlowPersistence; this.retainedMessagePersistence = retainedMessagePersistence; this.clientQueuePersistence = clientQueuePersistence; this.persistenceExecutorService = persistenceExecutorService; this.persistenceScheduledExecutorService = persistenceScheduledExecutorService; this.payloadPersistenceExecutor = payloadPersistenceExecutor; this.singleWriterService = singleWriterService; this.payloadPersistence = payloadPersistence; }
Example #2
Source File: MainGraph.java From armeria with Apache License 2.0 | 6 votes |
@Produces static ListenableFuture<List<Long>> fetchFromFakeDb(ServiceRequestContext context, ListeningScheduledExecutorService blockingExecutor) { // The context is mounted in a thread-local, meaning it is available to all logic such as tracing. checkState(ServiceRequestContext.current() == context); checkState(context.eventLoop().inEventLoop()); // This logic mimics using a blocking method, which would usually be something like a MySQL database // query using JDBC. // Always run blocking logic on the blocking task executor. By using // ServiceRequestContext.blockingTaskExecutor (indirectly via the ListeningScheduledExecutorService // wrapper we defined in MainModule), you also ensure the context is mounted inside the logic (e.g., // your DB call will be traced!). return blockingExecutor.submit(() -> { // The context is mounted in a thread-local, meaning it is available to all logic such as tracing. checkState(ServiceRequestContext.current() == context); checkState(!context.eventLoop().inEventLoop()); Uninterruptibles.sleepUninterruptibly(Duration.ofMillis(50)); return ImmutableList.of(23L, -23L); }); }
Example #3
Source File: PublishPayloadPersistenceImpl.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Inject PublishPayloadPersistenceImpl(final @NotNull PublishPayloadLocalPersistence localPersistence, final @NotNull @PayloadPersistence ListeningScheduledExecutorService scheduledExecutorService) { this.localPersistence = localPersistence; this.scheduledExecutorService = scheduledExecutorService; hashFunction = LongHashFunction.xx(); payloadCache = CacheBuilder.newBuilder() .expireAfterAccess(InternalConfigurations.PAYLOAD_CACHE_DURATION.get(), TimeUnit.MILLISECONDS) .maximumSize(InternalConfigurations.PAYLOAD_CACHE_SIZE.get()) .concurrencyLevel(InternalConfigurations.PAYLOAD_CACHE_CONCURRENCY_LEVEL.get()) .removalListener(new PayloadCacheRemovalListener(hashFunction, lookupTable)) .build(); removeSchedule = InternalConfigurations.PAYLOAD_PERSISTENCE_CLEANUP_SCHEDULE.get(); bucketLock = new BucketLock(InternalConfigurations.PAYLOAD_PERSISTENCE_BUCKET_COUNT.get()); }
Example #4
Source File: PersistenceMigrationModule.java From hivemq-community-edition with Apache License 2.0 | 6 votes |
@Override protected void configure() { bind(ShutdownHooks.class).asEagerSingleton(); bind(PersistenceStartup.class).asEagerSingleton(); bind(PersistenceStartupShutdownHookInstaller.class).asEagerSingleton(); if (persistenceConfigurationService.getMode() == PersistenceConfigurationService.PersistenceMode.FILE) { install(new PersistenceMigrationFileModule()); } else { install(new LocalPersistenceMemoryModule(null)); } bind(PublishPayloadPersistence.class).to(PublishPayloadPersistenceImpl.class).in(Singleton.class); bind(MetricRegistry.class).toInstance(metricRegistry); bind(MetricsHolder.class).toProvider(MetricsHolderProvider.class).asEagerSingleton(); bind(ListeningScheduledExecutorService.class).annotatedWith(PayloadPersistence.class) .toProvider(PayloadPersistenceScheduledExecutorProvider.class) .in(LazySingleton.class); bind(MessageDroppedService.class).toProvider(MessageDroppedServiceProvider.class).in(Singleton.class); }
Example #5
Source File: ApacheThriftMethodInvoker.java From drift with Apache License 2.0 | 6 votes |
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"); }
Example #6
Source File: PurgeSchedulingService.java From centraldogma with Apache License 2.0 | 6 votes |
public synchronized void start(Runnable task) { if (isStarted()) { return; } requireNonNull(task, "task"); final ListeningScheduledExecutorService scheduler = MoreExecutors.listeningDecorator(purgeWorker); this.scheduler = scheduler; @SuppressWarnings("UnstableApiUsage") final ListenableScheduledFuture<?> future = scheduler.scheduleWithFixedDelay( task, TICK.getSeconds(), TICK.getSeconds(), TimeUnit.SECONDS); Futures.addCallback(future, new FutureCallback<Object>() { @Override public void onSuccess(@Nullable Object result) {} @Override public void onFailure(Throwable cause) { logger.error("Storage purge scheduler stopped due to an unexpected exception:", cause); } }, purgeWorker); }
Example #7
Source File: StubInstance.java From bazel-buildfarm with Apache License 2.0 | 6 votes |
public StubInstance( String name, String identifier, DigestUtil digestUtil, ManagedChannel channel, long deadlineAfter, TimeUnit deadlineAfterUnits, Retrier retrier, @Nullable ListeningScheduledExecutorService retryService) { this.name = name; this.identifier = identifier; this.digestUtil = digestUtil; this.channel = channel; this.deadlineAfter = deadlineAfter; this.deadlineAfterUnits = deadlineAfterUnits; this.retrier = retrier; this.retryService = retryService; }
Example #8
Source File: DumpFileCleaner.java From bistoury with GNU General Public License v3.0 | 6 votes |
public void start() { if (!init.compareAndSet(false, true)) { return; } initDumpDir("jstack"); initDumpDir("qjdump"); initDumpDir("bistoury-class-dump"); final File file = new File(BASE_DUMP_DIR); ListeningScheduledExecutorService listeningDecorator = MoreExecutors.listeningDecorator(Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory("clean-dump-file"))); listeningDecorator.scheduleWithFixedDelay(new Runnable() { @Override public void run() { clean(file); } }, 0, 1, TimeUnit.HOURS); }
Example #9
Source File: CloudSqlInstance.java From cloud-sql-jdbc-socket-factory with Apache License 2.0 | 5 votes |
/** * Initializes a new Cloud SQL instance based on the given connection name. * * @param connectionName instance connection name in the format "PROJECT_ID:REGION_ID:INSTANCE_ID" * @param apiClient Cloud SQL Admin API client for interacting with the Cloud SQL instance * @param executor executor used to schedule asynchronous tasks * @param keyPair public/private key pair used to authenticate connections */ CloudSqlInstance( String connectionName, SQLAdmin apiClient, ListeningScheduledExecutorService executor, ListenableFuture<KeyPair> keyPair) { this.connectionName = connectionName; Matcher matcher = CONNECTION_NAME.matcher(connectionName); checkArgument( matcher.matches(), "[%s] Cloud SQL connection name is invalid, expected string in the form of" + " \"<PROJECT_ID>:<REGION_ID>:<INSTANCE_ID>\"."); this.projectId = matcher.group(1); this.regionId = matcher.group(3); this.instanceId = matcher.group(4); this.apiClient = apiClient; this.executor = executor; this.keyPair = keyPair; // Kick off initial async jobs synchronized (instanceDataGuard) { this.currentInstanceData = performRefresh(); this.nextInstanceData = Futures.immediateFuture(currentInstanceData); } }
Example #10
Source File: CloudSqlInstance.java From cloud-sql-jdbc-socket-factory with Apache License 2.0 | 5 votes |
private static <T> ListenableFuture<T> whenAllSucceed( Callable<T> task, ListeningScheduledExecutorService executor, ListenableFuture<?>... futures) { SettableFuture<T> taskFuture = SettableFuture.create(); // Create a countDown for all Futures to complete. AtomicInteger countDown = new AtomicInteger(futures.length); // Trigger the task when all futures are complete. FutureCallback<Object> runWhenInputAreComplete = new FutureCallback<Object>() { @Override public void onSuccess(@NullableDecl Object o) { if (countDown.decrementAndGet() == 0) { taskFuture.setFuture(executor.submit(task)); } } @Override public void onFailure(Throwable throwable) { if (!taskFuture.setException(throwable)) { String msg = "Got more than one input failure. Logging failures after the first"; logger.log(Level.SEVERE, msg, throwable); } } }; for (ListenableFuture<?> future : futures) { Futures.addCallback(future, runWhenInputAreComplete, executor); } return taskFuture; }
Example #11
Source File: RemoteRetrier.java From bazel with Apache License 2.0 | 5 votes |
@VisibleForTesting public RemoteRetrier( Supplier<Backoff> backoff, Predicate<? super Exception> shouldRetry, ListeningScheduledExecutorService retryScheduler, CircuitBreaker circuitBreaker, Sleeper sleeper) { super(backoff, shouldRetry, retryScheduler, circuitBreaker, sleeper); }
Example #12
Source File: TestUtils.java From bazel with Apache License 2.0 | 5 votes |
public static RemoteRetrier newRemoteRetrier( Supplier<Backoff> backoff, Predicate<? super Exception> shouldRetry, ListeningScheduledExecutorService retryScheduler) { ZeroDelayListeningScheduledExecutorService zeroDelayRetryScheduler = new ZeroDelayListeningScheduledExecutorService(retryScheduler); return new RemoteRetrier( backoff, shouldRetry, zeroDelayRetryScheduler, Retrier.ALLOW_ALL_CALLS, (millis) -> { /* don't wait in tests */ }); }
Example #13
Source File: CoreSocketFactory.java From cloud-sql-jdbc-socket-factory with Apache License 2.0 | 5 votes |
@VisibleForTesting // Returns a listenable, scheduled executor that exits upon shutdown. static ListeningScheduledExecutorService getDefaultExecutor() { // TODO(kvg): Figure out correct way to determine number of threads ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(2); executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false); return MoreExecutors.listeningDecorator( MoreExecutors.getExitingScheduledExecutorService(executor)); }
Example #14
Source File: CoreSocketFactory.java From cloud-sql-jdbc-socket-factory with Apache License 2.0 | 5 votes |
@VisibleForTesting CoreSocketFactory( ListenableFuture<KeyPair> localKeyPair, SQLAdmin adminApi, int serverProxyPort, ListeningScheduledExecutorService executor) { this.adminApi = adminApi; this.serverProxyPort = serverProxyPort; this.executor = executor; this.localKeyPair = localKeyPair; }
Example #15
Source File: PendingWillMessages.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
@Inject public PendingWillMessages(@NotNull final InternalPublishService publishService, @Persistence final ListeningScheduledExecutorService executorService, @NotNull final ClientSessionPersistence clientSessionPersistence, @NotNull final ClientSessionLocalPersistence clientSessionLocalPersistence) { this.publishService = publishService; this.executorService = executorService; this.clientSessionPersistence = clientSessionPersistence; this.clientSessionLocalPersistence = clientSessionLocalPersistence; executorService.scheduleAtFixedRate(new CheckWillsTask(), WILL_DELAY_CHECK_SCHEDULE, WILL_DELAY_CHECK_SCHEDULE, TimeUnit.SECONDS); }
Example #16
Source File: Retrier.java From bazel with Apache License 2.0 | 5 votes |
@VisibleForTesting Retrier( Supplier<Backoff> backoffSupplier, Predicate<? super Exception> shouldRetry, ListeningScheduledExecutorService retryService, CircuitBreaker circuitBreaker, Sleeper sleeper) { this.backoffSupplier = backoffSupplier; this.shouldRetry = shouldRetry; this.retryService = retryService; this.circuitBreaker = circuitBreaker; this.sleeper = sleeper; }
Example #17
Source File: JumpToCodeSelectionListener.java From otroslogviewer with Apache License 2.0 | 5 votes |
@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(); } } }
Example #18
Source File: PayloadPersistenceScheduledExecutorProvider.java From hivemq-community-edition with Apache License 2.0 | 5 votes |
@NotNull @Override @LazySingleton @PayloadPersistence public ListeningScheduledExecutorService get() { if (executorService == null) { final ThreadFactory threadFactory = ThreadFactoryUtil.create("payload-persistence-cleanup-%d"); final int coreSize = InternalConfigurations.PAYLOAD_PERSISTENCE_CLEANUP_THREADS.get(); final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(coreSize, threadFactory); executorService = MoreExecutors.listeningDecorator(scheduledExecutorService); } return executorService; }
Example #19
Source File: Retrier.java From bazel with Apache License 2.0 | 5 votes |
public Retrier( Supplier<Backoff> backoffSupplier, Predicate<? super Exception> shouldRetry, ListeningScheduledExecutorService retryScheduler, CircuitBreaker circuitBreaker) { this( backoffSupplier, shouldRetry, retryScheduler, circuitBreaker, TimeUnit.MILLISECONDS::sleep); }
Example #20
Source File: Retrier.java From bazel-buildfarm with Apache License 2.0 | 5 votes |
public Retrier( Supplier<Backoff> backoffSupplier, Predicate<Status> isRetriable, ListeningScheduledExecutorService retryScheduler) { this.backoffSupplier = backoffSupplier; this.isRetriable = isRetriable; this.retryScheduler = retryScheduler; }
Example #21
Source File: MDCPropagatingScheduledExecutorService.java From incubator-gobblin with Apache License 2.0 | 5 votes |
public MDCPropagatingScheduledExecutorService(ScheduledExecutorService executorService) { if (executorService instanceof ListeningScheduledExecutorService) { this.executorService = (ListeningScheduledExecutorService)executorService; } else { this.executorService = MoreExecutors.listeningDecorator(executorService); } }
Example #22
Source File: HeliosClient.java From helios with Apache License 2.0 | 5 votes |
private static ListeningScheduledExecutorService defaultExecutorService() { final int clientCount = clientCounter.incrementAndGet(); final ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat("helios-client-" + clientCount + "-thread-%d") .build(); final ScheduledThreadPoolExecutor stpe = new ScheduledThreadPoolExecutor(4, threadFactory); final ScheduledExecutorService exitingExecutor = MoreExecutors.getExitingScheduledExecutorService(stpe, 0, SECONDS); return MoreExecutors.listeningDecorator(exitingExecutor); }
Example #23
Source File: RetryingRequestDispatcher.java From helios with Apache License 2.0 | 5 votes |
private RetryingRequestDispatcher(final RequestDispatcher delegate, final ListeningScheduledExecutorService executorService, final Clock clock, final long retryTimeoutMillis, final long delayMillis) { this.delegate = delegate; this.executorService = executorService; this.clock = clock; this.retryTimeoutMillis = retryTimeoutMillis; this.delayMillis = delayMillis; }
Example #24
Source File: RemoteActionContextProvider.java From bazel with Apache License 2.0 | 5 votes |
private RemoteActionContextProvider( CommandEnvironment env, RemoteCache cache, @Nullable GrpcRemoteExecutor executor, @Nullable ListeningScheduledExecutorService retryScheduler, DigestUtil digestUtil, @Nullable Path logDir) { this.env = Preconditions.checkNotNull(env, "env"); this.cache = Preconditions.checkNotNull(cache, "cache"); this.executor = executor; this.retryScheduler = retryScheduler; this.digestUtil = digestUtil; this.logDir = logDir; }
Example #25
Source File: RemoteActionContextProvider.java From bazel with Apache License 2.0 | 5 votes |
public static RemoteActionContextProvider createForRemoteCaching( CommandEnvironment env, RemoteCache cache, ListeningScheduledExecutorService retryScheduler, DigestUtil digestUtil) { return new RemoteActionContextProvider( env, cache, /*executor=*/ null, retryScheduler, digestUtil, /*logDir=*/ null); }
Example #26
Source File: RemoteActionContextProvider.java From bazel with Apache License 2.0 | 5 votes |
public static RemoteActionContextProvider createForRemoteExecution( CommandEnvironment env, RemoteExecutionCache cache, GrpcRemoteExecutor executor, ListeningScheduledExecutorService retryScheduler, DigestUtil digestUtil, Path logDir) { return new RemoteActionContextProvider( env, cache, executor, retryScheduler, digestUtil, logDir); }
Example #27
Source File: RemoteSpawnRunner.java From bazel with Apache License 2.0 | 5 votes |
RemoteSpawnRunner( Path execRoot, RemoteOptions remoteOptions, ExecutionOptions executionOptions, Predicate<Label> verboseFailures, @Nullable Reporter cmdlineReporter, String buildRequestId, String commandId, RemoteExecutionCache remoteCache, GrpcRemoteExecutor remoteExecutor, ListeningScheduledExecutorService retryService, DigestUtil digestUtil, Path logDir, ImmutableSet<ActionInput> filesToDownload) { this.execRoot = execRoot; this.remoteOptions = remoteOptions; this.executionOptions = executionOptions; this.remoteCache = Preconditions.checkNotNull(remoteCache, "remoteCache"); this.remoteExecutor = Preconditions.checkNotNull(remoteExecutor, "remoteExecutor"); this.verboseFailures = verboseFailures; this.cmdlineReporter = cmdlineReporter; this.buildRequestId = buildRequestId; this.commandId = commandId; this.retrier = createExecuteRetrier(remoteOptions, retryService); this.digestUtil = digestUtil; this.logDir = logDir; this.filesToDownload = Preconditions.checkNotNull(filesToDownload, "filesToDownload"); }
Example #28
Source File: RemoteSpawnRunner.java From bazel with Apache License 2.0 | 5 votes |
private static RemoteRetrier createExecuteRetrier( RemoteOptions options, ListeningScheduledExecutorService retryService) { return new RemoteRetrier( options.remoteMaxRetryAttempts > 0 ? () -> new Retrier.ZeroBackoff(options.remoteMaxRetryAttempts) : () -> Retrier.RETRIES_DISABLED, RemoteSpawnRunner::retriableExecErrors, retryService, Retrier.ALLOW_ALL_CALLS); }
Example #29
Source File: RemoteRetrier.java From bazel with Apache License 2.0 | 5 votes |
public RemoteRetrier( RemoteOptions options, Predicate<? super Exception> shouldRetry, ListeningScheduledExecutorService retryScheduler, CircuitBreaker circuitBreaker) { this( options.remoteMaxRetryAttempts > 0 ? () -> new ExponentialBackoff(options) : () -> RETRIES_DISABLED, shouldRetry, retryScheduler, circuitBreaker); }
Example #30
Source File: RemoteRetrier.java From bazel with Apache License 2.0 | 5 votes |
public RemoteRetrier( Supplier<Backoff> backoff, Predicate<? super Exception> shouldRetry, ListeningScheduledExecutorService retryScheduler, CircuitBreaker circuitBreaker) { super(backoff, shouldRetry, retryScheduler, circuitBreaker); }