List of usage examples for com.google.common.util.concurrent AbstractIdleService AbstractIdleService
protected AbstractIdleService()
From source file:dk.dma.ais.reader.AisReaderGroup.java
public Service asService() { return new AbstractIdleService() { @Override//from w w w. jav a 2 s . co m protected void shutDown() throws Exception { lock.lock(); try { for (AisReader r : readers.values()) { LOG.info("Trying to stop reader " + r); r.stopReader(); } for (AisReader r : readers.values()) { try { LOG.info("Trying to join reader thread" + r); r.join(); } catch (InterruptedException e) { LOG.error("Interrupted while waiting for shutdown", e); } } } finally { lock.unlock(); } } @Override protected void startUp() throws Exception { lock.lock(); try { for (AisReader r : readers.values()) { r.start(); } } finally { lock.unlock(); } } }; }
From source file:co.cask.cdap.logging.framework.distributed.DistributedLogFramework.java
@Override protected Service createService(Set<Integer> partitions) { Map<String, LogPipelineSpecification<AppenderContext>> specs = new LogPipelineLoader(cConf) .load(contextProvider);/*from w w w .ja va 2 s. c o m*/ int pipelineCount = specs.size(); // Create one KafkaLogProcessorPipeline per spec final List<Service> pipelines = new ArrayList<>(); for (final LogPipelineSpecification<AppenderContext> pipelineSpec : specs.values()) { final CConfiguration cConf = pipelineSpec.getConf(); final AppenderContext context = pipelineSpec.getContext(); long bufferSize = getBufferSize(pipelineCount, cConf, partitions.size()); final String topic = cConf.get(Constants.Logging.KAFKA_TOPIC); final KafkaPipelineConfig config = new KafkaPipelineConfig(topic, partitions, bufferSize, cConf.getLong(Constants.Logging.PIPELINE_EVENT_DELAY_MS), cConf.getInt(Constants.Logging.PIPELINE_KAFKA_FETCH_SIZE), cConf.getLong(Constants.Logging.PIPELINE_CHECKPOINT_INTERVAL_MS)); RetryStrategy retryStrategy = RetryStrategies.fromConfiguration(cConf, "system.log.process."); pipelines.add(new RetryOnStartFailureService(new Supplier<Service>() { @Override public Service get() { return new KafkaLogProcessorPipeline( new LogProcessorPipelineContext(cConf, context.getName(), context), checkpointManagerFactory.create(topic, pipelineSpec.getCheckpointPrefix()), brokerService, config); } }, retryStrategy)); } // Returns a Service that start/stop all pipelines. return new AbstractIdleService() { @Override protected void startUp() throws Exception { // Starts all pipeline validateAllFutures(Iterables.transform(pipelines, new Function<Service, ListenableFuture<State>>() { @Override public ListenableFuture<State> apply(Service service) { return service.start(); } })); } @Override protected void shutDown() throws Exception { // Stops all pipeline validateAllFutures(Iterables.transform(pipelines, new Function<Service, ListenableFuture<State>>() { @Override public ListenableFuture<State> apply(Service service) { return service.stop(); } })); } }; }
From source file:org.apache.twill.yarn.YarnTwillRunnerService.java
/** * Creates an instance./*from w ww . java2s . c o m*/ * * @param config Configuration of the yarn cluster * @param zkConnect ZooKeeper connection string * @param locationFactory Factory to create {@link Location} instances that are readable and writable by this service */ public YarnTwillRunnerService(YarnConfiguration config, String zkConnect, LocationFactory locationFactory) { this.yarnConfig = config; this.locationFactory = locationFactory; this.zkClientService = getZKClientService(zkConnect); this.controllers = HashBasedTable.create(); this.serviceDelegate = new AbstractIdleService() { @Override protected void startUp() throws Exception { YarnTwillRunnerService.this.startUp(); } @Override protected void shutDown() throws Exception { YarnTwillRunnerService.this.shutDown(); } }; }