List of usage examples for com.google.common.util.concurrent MoreExecutors getExitingScheduledExecutorService
@Beta @GwtIncompatible("TODO") public static ScheduledExecutorService getExitingScheduledExecutorService(ScheduledThreadPoolExecutor executor, long terminationTimeout, TimeUnit timeUnit)
From source file:se.svt.helios.serviceregistration.consul.ConsulServiceRegistrar.java
public ConsulServiceRegistrar(final ConsulClient consulClient, final String serviceCheckScript, final String serviceCheckInterval) { this.consulClient = consulClient; this.serviceCheckScript = serviceCheckScript; this.serviceCheckInterval = serviceCheckInterval; this.handles = Maps.newConcurrentMap(); this.endpoints = Sets.newConcurrentHashSet(); this.executor = MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("consul-registrar-%d").build()), 0, TimeUnit.SECONDS); // If the Consul agent is restarted, all services will forgotten. Therefore we sync the // state between services known by this plugin and services registered in Consul. Runnable registrationRunnable = new Runnable() { @Override//w ww .ja v a 2 s. c om public void run() { syncState(); } }; this.executor.scheduleAtFixedRate(registrationRunnable, CONSUL_UPDATE_INTERVAL, CONSUL_UPDATE_INTERVAL, TimeUnit.SECONDS); }
From source file:org.factcast.server.rest.resources.FactsObserverFactory.java
@Inject public FactsObserverFactory(@NonNull LinkFactory<FactsResource> factsResourceLinkFactory, @NonNull HyperSchemaCreator hyperSchemaCreator, @NonNull FactTransformer factTransformer, @Value("${rest.cleanup-conn.threads-nr:10}") int nrCleanUpThreads, @Value("${rest.cleanup-conn.interval-sec:10}") int waitSecondsForCleanUpCheck) { this(factsResourceLinkFactory, hyperSchemaCreator, factTransformer, MoreExecutors.getExitingScheduledExecutorService(new ScheduledThreadPoolExecutor(nrCleanUpThreads), 100, TimeUnit.MILLISECONDS), waitSecondsForCleanUpCheck); }
From source file:com.addthis.bundle.channel.BatchingDataChannelOutput.java
/** * Constructor initializes a empty messsage list and starts a purge thread which runs * every {@code maxTimeInMillis} and checks to see if the messages need to be purged * from the queue./* w w w . java 2 s. c o m*/ * * @param batchSize - the number of messages that the channel should queue before invoking sendBatch * @param maxTimeInMillis - the maximum time in milliseconds a message can sit on the queue before * being sent to the channel. */ public BatchingDataChannelOutput(int batchSize, long maxTimeInMillis) { messageList = new ArrayList<Bundle>(); this.maxTimeInMillis = maxTimeInMillis; this.batchSize = batchSize; bufferPurgeExecutor = MoreExecutors.getExitingScheduledExecutorService( new ScheduledThreadPoolExecutor(1, new ThreadFactoryBuilder().setNameFormat("BatchingDataChannelOutputThread-%d").build()), 5000, TimeUnit.MILLISECONDS); bufferPurgeExecutor.scheduleWithFixedDelay(new BatchSendRunner(), maxTimeInMillis, maxTimeInMillis, TimeUnit.MILLISECONDS); }
From source file:com.spotify.helios.agent.TaskMonitor.java
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); }
From source file:com.spotify.helios.serviceregistration.skydns.SkyDnsServiceRegistrar.java
/** * @param etcdClient client to talk to etcd with. * @param timeToLiveSeconds how long entries in the discovery service should live. * @param format the hostname format./*from w w w. ja va 2 s . co m*/ */ public SkyDnsServiceRegistrar(final MiniEtcdClient etcdClient, final int timeToLiveSeconds, final String format) { this.etcdClient = Preconditions.checkNotNull(etcdClient); this.timeToLiveSeconds = timeToLiveSeconds; this.handles = Maps.newConcurrentMap(); this.executor = MoreExecutors.getExitingScheduledExecutorService( (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(1, threadFactory), 0, SECONDS); // Dividing into thirds, since at least halves are necessary to ensure that the item doesn't // expire due to a slight delay, and went to thirds so that a single failure won't tank the // registration this.executor.scheduleAtFixedRate(registrationRunnable, timeToLiveSeconds / 3, timeToLiveSeconds / 3, SECONDS); this.srvFormat = format; }