Java Code Examples for com.google.common.util.concurrent.MoreExecutors#getExitingScheduledExecutorService()
The following examples show how to use
com.google.common.util.concurrent.MoreExecutors#getExitingScheduledExecutorService() .
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: SchedulerModule.java From dynein with Apache License 2.0 | 6 votes |
@Provides @Singleton public HeartbeatManager provideHeartBeat(EventBus eventBus, Clock clock) { HeartbeatManager heartbeatManager = new HeartbeatManager( new ConcurrentHashMap<>(), MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool( 1, new ThreadFactoryBuilder().setNameFormat("heartbeat-manager-%d").build())), eventBus, clock, heartbeatConfiguration); eventBus.register(heartbeatManager); return heartbeatManager; }
Example 2
Source File: SchedulerModule.java From dynein with Apache License 2.0 | 6 votes |
@Provides @Singleton public WorkerManager provideWorkerManager( PartitionWorkerFactory factory, EventBus eventBus, Metrics metrics, PartitionPolicy policy) { List<PartitionWorker> partitionWorkers = new ArrayList<>(); for (int i = 0; i < workersConfiguration.getNumberOfWorkers(); i++) { partitionWorkers.add(factory.get(i)); } WorkerManager manager = new WorkerManager( partitionWorkers, factory, MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool( 1, new ThreadFactoryBuilder().setNameFormat("worker-manager-%d").build())), new ConcurrentHashMap<>(), policy, metrics); eventBus.register(manager); return manager; }
Example 3
Source File: ThrottledAsyncChecker.java From hadoop-ozone with Apache License 2.0 | 6 votes |
public ThrottledAsyncChecker(final Timer timer, final long minMsBetweenChecks, final long diskCheckTimeout, final ExecutorService executorService) { this.timer = timer; this.minMsBetweenChecks = minMsBetweenChecks; this.diskCheckTimeout = diskCheckTimeout; this.executorService = MoreExecutors.listeningDecorator(executorService); this.checksInProgress = new HashMap<>(); this.completedChecks = new WeakHashMap<>(); if (this.diskCheckTimeout > 0) { ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1); this.scheduledExecutorService = MoreExecutors .getExitingScheduledExecutorService(scheduledThreadPoolExecutor); } else { this.scheduledExecutorService = null; } }
Example 4
Source File: DnsSrvWatchers.java From dns-java with Apache License 2.0 | 6 votes |
public DnsSrvWatcher<T> build() { checkState(polling ^ dnsSrvWatcherFactory != null, "specify either polling or custom trigger"); DnsSrvWatcherFactory<T> watcherFactory; if (polling) { final ScheduledExecutorService executor = scheduledExecutorService != null ? scheduledExecutorService : MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor( 1, new ThreadFactoryBuilder().setNameFormat("dns-lookup-%d").build()), 0, SECONDS); watcherFactory = cnf -> new PollingDnsSrvWatcher<>(cnf, executor, pollingInterval, pollingIntervalUnit); } else { watcherFactory = requireNonNull(dnsSrvWatcherFactory, "dnsSrvWatcherFactory"); } final ChangeNotifierFactory<T> changeNotifierFactory = fqdn -> new ServiceResolvingChangeNotifier<>( resolver, fqdn, resultTransformer, errorHandler); return watcherFactory.create(changeNotifierFactory); }
Example 5
Source File: Agent.java From statsd-jvm-profiler with MIT License | 6 votes |
/** * Schedule profilers with a SchedulerExecutorService * * @param profilers Collection of profilers to schedule * @param arguments */ private static void scheduleProfilers(Collection<Profiler> profilers, Arguments arguments) { // We need to convert to an ExitingScheduledExecutorService so the JVM shuts down // when the main thread finishes ScheduledExecutorService scheduledExecutorService = MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(profilers.size(), new ProfilerThreadFactory())); Map<String, ScheduledFuture<?>> runningProfilers = new HashMap<>(profilers.size()); Map<String, Profiler> activeProfilers = new HashMap<>(profilers.size()); for (Profiler profiler : profilers) { activeProfilers.put(profiler.getClass().getSimpleName(), profiler); ProfilerWorkerThread worker = new ProfilerWorkerThread(profiler, errors); ScheduledFuture future = scheduledExecutorService.scheduleAtFixedRate(worker, EXECUTOR_DELAY, profiler.getPeriod(), profiler.getTimeUnit()); runningProfilers.put(profiler.getClass().getSimpleName(), future); } if (arguments.httpServerEnabled) { ProfilerServer.startServer(runningProfilers, activeProfilers, arguments.httpPort, isRunning, errors); } }
Example 6
Source File: MultiLangProcessorRuntime.java From streamline with Apache License 2.0 | 6 votes |
@Override public void initialize(Map<String, Object> config) { command = (String[]) config.get(COMMAND); processTimeoutMills = (int) config.get(PROCESS_TIMEOUT_MILLS); Map<String, Object> processorConfig = (Map<String, Object>) config.get(PROCESS_CONFIG); ShellContext shellContext = (ShellContext) config.get(SHELL_CONTEXT); List<String> outputStreams = (List<String>) config.get(OUTPUT_STREAMS); Map<String, String> envMap = (Map<String, String>) config.get(SHELL_ENVIRONMENT); String className = (String) config.get(MULTILANG_SERIALIZER); shellProcess = new ShellProcess(command); if(className != null) shellProcess.setSerializerClassName(className); shellProcess.setEnv(envMap); //subprocesses must send their pid first thing Long subpid = shellProcess.launch(processorConfig, shellContext, outputStreams); LOG.info("Launched subprocess with pid " + subpid); LOG.info("Start checking heartbeat..."); setHeartbeat(); heartBeatExecutorService = MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1)); heartBeatExecutorService.scheduleAtFixedRate(new HeartbeatTimerTask(this), 1, 1, TimeUnit.SECONDS); }
Example 7
Source File: ShellBolt.java From jstorm with Apache License 2.0 | 5 votes |
public void prepare(Map stormConf, TopologyContext context, final OutputCollector collector) { Object maxPending = stormConf.get(Config.TOPOLOGY_SHELLBOLT_MAX_PENDING); if (maxPending != null) { this._pendingWrites = new LinkedBlockingQueue(((Number) maxPending).intValue()); } _rand = new Random(); _collector = collector; _context = context; workerTimeoutMills = 1000 * RT.intCast(stormConf.get(Config.SUPERVISOR_WORKER_TIMEOUT_SECS)); _process = new ShellProcess(_command); // subprocesses must send their pid first thing Number subpid = _process.launch(stormConf, context); LOG.info("Launched subprocess with pid " + subpid); // reader _readerThread = new Thread(new BoltReaderRunnable()); _readerThread.start(); _writerThread = new Thread(new BoltWriterRunnable()); _writerThread.start(); heartBeatExecutorService = MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1)); heartBeatExecutorService.scheduleAtFixedRate(new BoltHeartbeatTimerTask(this), 1, 1, TimeUnit.SECONDS); LOG.info("Start checking heartbeat..."); setHeartbeat(); }
Example 8
Source File: TaskMonitor.java From helios with Apache License 2.0 | 5 votes |
public TaskMonitor(final JobId jobId, final FlapController flapController, final StatusUpdater statusUpdater) { this.jobId = jobId; this.flapController = flapController; this.statusUpdater = statusUpdater; final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1); // Let core threads time out to avoid unnecessarily keeping a flapping state check thread alive // for the majority of tasks that do not flap. executor.setKeepAliveTime(5, SECONDS); executor.allowCoreThreadTimeOut(true); this.scheduler = MoreExecutors.getExitingScheduledExecutorService(executor, 0, SECONDS); }
Example 9
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 10
Source File: ProfilerServerTest.java From statsd-jvm-profiler with MIT License | 5 votes |
@Before public void setup() throws IOException { MockProfiler1 profiler1 = new MockProfiler1(new HashSet<String>()); MockProfiler2 profiler2 = new MockProfiler2(new HashSet<String>()); activeProfilers = new HashMap<>(); activeProfilers.put("MockProfiler1", profiler1); activeProfilers.put("MockProfiler2", profiler2); port = 8080; isRunning = new AtomicReference<>(true); errors = new ArrayList<>(); errors.add("example error"); Map<String, ScheduledFuture<?>> runningProfilers = new HashMap<>(); ProfilerWorkerThread worker1 = new ProfilerWorkerThread(profiler1, errors); ProfilerWorkerThread worker2 = new ProfilerWorkerThread(profiler2, errors); ScheduledExecutorService scheduledExecutorService = MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(2, new ProfilerThreadFactory())); ScheduledFuture future1 = scheduledExecutorService.scheduleAtFixedRate(worker1, 0, profiler1.getPeriod(), profiler1.getTimeUnit()); ScheduledFuture future2 = scheduledExecutorService.scheduleAtFixedRate(worker2, 0, profiler2.getPeriod(), profiler2.getTimeUnit()); runningProfilers.put("MockProfiler1", future1); runningProfilers.put("MockProfiler2", future2); ProfilerServer.startServer(runningProfilers, activeProfilers, port, isRunning, errors); client = HttpClients.createDefault(); }
Example 11
Source File: AbstractSpringConfigContext.java From x-pipe with Apache License 2.0 | 5 votes |
@Bean(name = SCHEDULED_EXECUTOR) public ScheduledExecutorService getScheduledExecutorService() { int corePoolSize = OsUtils.getCpuCount(); if (corePoolSize > maxScheduledCorePoolSize) { corePoolSize = maxScheduledCorePoolSize; } return MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor(corePoolSize, XpipeThreadFactory.create(SCHEDULED_EXECUTOR)), THREAD_POOL_TIME_OUT, TimeUnit.SECONDS ); }
Example 12
Source File: EmailSentCounter.java From x-pipe with Apache License 2.0 | 5 votes |
@PostConstruct public void scheduledCheckSentEmails() { logger.info("[scheduledCheckSentEmails] [post construct] begin"); ScheduledExecutorService scheduled = MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor(1, XpipeThreadFactory.create(getClass().getSimpleName() + "-")), THREAD_POOL_TIME_OUT, TimeUnit.SECONDS ); start(scheduled); }
Example 13
Source File: ConsoleContextConfig.java From x-pipe with Apache License 2.0 | 5 votes |
@Bean(name = REDIS_COMMAND_EXECUTOR) public ScheduledExecutorService getRedisCommandExecutor() { int corePoolSize = OsUtils.getCpuCount(); if (corePoolSize > maxScheduledCorePoolSize) { corePoolSize = maxScheduledCorePoolSize; } return MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor(corePoolSize, XpipeThreadFactory.create(REDIS_COMMAND_EXECUTOR)), THREAD_POOL_TIME_OUT, TimeUnit.SECONDS ); }
Example 14
Source File: DefaultTunnelManager.java From x-pipe with Apache License 2.0 | 5 votes |
@PostConstruct public void cleaner() { ScheduledExecutorService scheduled = MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor(1, XpipeThreadFactory.create("DefaultTunnelManager")), THREAD_POOL_TIME_OUT, TimeUnit.SECONDS); future = scheduled.scheduleWithFixedDelay( new AbstractExceptionLogTask() { @Override protected void doRun() throws Exception { doClean(); } }, 10, 10, TimeUnit.MINUTES); }
Example 15
Source File: Production.java From x-pipe with Apache License 2.0 | 5 votes |
@Bean(name = GLOBAL_SCHEDULED) public ScheduledExecutorService getScheduled() { int corePoolSize = Math.min(OsUtils.getCpuCount(), 4); return MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor(corePoolSize, XpipeThreadFactory.create(GLOBAL_SCHEDULED)), 1, TimeUnit.SECONDS ); }
Example 16
Source File: DefaultProxyEndpointManager.java From x-pipe with Apache License 2.0 | 5 votes |
public DefaultProxyEndpointManager(IntSupplier checkInterval) { this.healthCheckInterval = checkInterval; this.scheduled = MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor(1, XpipeThreadFactory.create("ProxyEndpointManager")), THREAD_POOL_TIME_OUT, TimeUnit.SECONDS); this.healthChecker = new DefaultProxyEndpointHealthChecker(scheduled); start(); }
Example 17
Source File: SamplingScheduler.java From babar with Apache License 2.0 | 5 votes |
public void schedule(Set<? extends SamplingSchedulable> schedulables) { ScheduledExecutorService scheduledExecutorService = MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(schedulables.size(), new SchedulerThreadFactory()), 0, TimeUnit.MILLISECONDS); for (SamplingSchedulable samplingSchedulable : schedulables) { System.out.println("scheduling "+ samplingSchedulable.getClass()+ " with an interval of "+ samplingSchedulable.getInterval() + " ms"); try { scheduledExecutorService.scheduleAtFixedRate(samplingSchedulable, 0, samplingSchedulable.getInterval(), samplingSchedulable.getTimeUnit()); } catch (Exception e) { e.printStackTrace(); } } }
Example 18
Source File: PartitionWorker.java From dynein with Apache License 2.0 | 5 votes |
void startExecutor() { scanTimes = new ConcurrentHashMap<>(); executorService = MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool( workersConfiguration.getThreadPoolSize(), new ThreadFactoryBuilder() .setNameFormat("partition-worker-" + index + "-%s") .build())); log.info("New ExecutorService has been created."); }
Example 19
Source File: GobblinHelixMultiManager.java From incubator-gobblin with Apache License 2.0 | 4 votes |
@Override public HelixTaskResult handleMessage() throws InterruptedException { String messageSubType = this._message.getMsgSubType(); Preconditions.checkArgument( messageSubType.equalsIgnoreCase(HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString()), String.format("Unknown %s message subtype: %s", GobblinHelixConstants.SHUTDOWN_MESSAGE_TYPE, messageSubType)); HelixTaskResult result = new HelixTaskResult(); if (stopStatus.isStopInProgress()) { result.setSuccess(true); return result; } log.info("Handling message " + HelixMessageSubTypes.APPLICATION_MASTER_SHUTDOWN.toString()); ScheduledExecutorService shutdownMessageHandlingCompletionWatcher = MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1)); // Schedule the task for watching on the removal of the shutdown message, which indicates that // the message has been successfully processed and it's safe to disconnect the HelixManager. // This is a hacky way of watching for the completion of processing the shutdown message and // should be replaced by a fix to https://issues.apache.org/jira/browse/HELIX-611. shutdownMessageHandlingCompletionWatcher.scheduleAtFixedRate(new Runnable() { @Override public void run() { HelixManager helixManager = _notificationContext.getManager(); HelixDataAccessor helixDataAccessor = helixManager.getHelixDataAccessor(); HelixProperty helixProperty = helixDataAccessor .getProperty(_message.getKey(helixDataAccessor.keyBuilder(), helixManager.getInstanceName())); // The absence of the shutdown message indicates it has been removed if (helixProperty == null) { eventBus.post(new ClusterManagerShutdownRequest()); } } }, 0, 1, TimeUnit.SECONDS); result.setSuccess(true); return result; }
Example 20
Source File: ShellSpout.java From jstorm with Apache License 2.0 | 3 votes |
public void open(Map stormConf, TopologyContext context, SpoutOutputCollector collector) { _collector = collector; _context = context; workerTimeoutMills = 1000 * RT.intCast(stormConf.get(Config.SUPERVISOR_WORKER_TIMEOUT_SECS)); _process = new ShellProcess(_command); Number subPid = _process.launch(stormConf, context); LOG.info("Launched subprocess with pid " + subPid); heartBeatExecutorService = MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(1)); }