List of usage examples for com.google.common.util.concurrent Service isRunning
boolean isRunning();
From source file:com.continuuity.weave.internal.WeaveContainerMain.java
private static Service wrapService(final ZKClientService zkClientService, final Service containerService) { return new Service() { @Override/*from w ww . jav a 2s. c o m*/ public ListenableFuture<State> start() { return Futures.transform(Services.chainStart(zkClientService, containerService), new AsyncFunction<List<ListenableFuture<State>>, State>() { @Override public ListenableFuture<State> apply(List<ListenableFuture<State>> input) throws Exception { return input.get(1); } }); } @Override public State startAndWait() { return Futures.getUnchecked(start()); } @Override public boolean isRunning() { return containerService.isRunning(); } @Override public State state() { return containerService.state(); } @Override public ListenableFuture<State> stop() { return Futures.transform(Services.chainStop(containerService, zkClientService), new AsyncFunction<List<ListenableFuture<State>>, State>() { @Override public ListenableFuture<State> apply(List<ListenableFuture<State>> input) throws Exception { return input.get(0); } }); } @Override public State stopAndWait() { return Futures.getUnchecked(stop()); } @Override public void addListener(Listener listener, Executor executor) { containerService.addListener(listener, executor); } }; }
From source file:com.brighttag.agathon.service.impl.ServiceRegistry.java
@Override protected void shutDown() { List<Future<State>> stopFutures = Lists.newArrayList(); LOG.info("Stopping service registry"); // Stop the services in parallel for (Service service : services) { if (service.isRunning()) { Future<State> stopFuture = service.stop(); stopFutures.add(stopFuture); LOG.info("Stop service {}, future={}", serviceName(service), stopFuture); }//from w w w . j av a 2s . c om } // Wait for the services ... and swallow exceptions for (Future<State> stateFuture : stopFutures) { try { State state = stateFuture.get(); LOG.info("Service future {} result={}", stateFuture, state); } catch (Exception e) { // Ok to catch Exception here LOG.warn("Problem stopping service, but pushing on", e); } } LOG.info("Finished stopping service registry"); }
From source file:org.apache.twill.internal.CompositeService.java
private void stopAll() throws Exception { Throwable failureCause = null; // Stop services in reverse order. Iterator<Service> itor = services.descendingIterator(); while (itor.hasNext()) { Service service = itor.next(); try {/*from w w w . j av a2s.co m*/ if (service.isRunning() || service.state() == State.STARTING) { service.stopAndWait(); } } catch (UncheckedExecutionException e) { // Just catch as we want all services stopped if (failureCause == null) { failureCause = e.getCause(); } else { // Log for sub-sequence service shutdown error, as only the first failure cause will be thrown. LOG.warn("Failed to stop service {}", service, e); } } } if (failureCause != null) { Throwables.propagateIfPossible(failureCause, Exception.class); throw new RuntimeException(failureCause); } }
From source file:de.ks.launch.Launcher.java
public boolean isStarted() { for (Service service : getServices()) { if (!service.isRunning()) { return false; }/*from ww w . ja v a 2 s .c o m*/ } return true; }
From source file:io.janusproject.kernel.Kernel.java
/** Replies a kernel service that is alive. * * @param <S> - type of the type to reply. * @param type - type of the type to reply. * @return the service, or <code>null</code>. *//*from w w w. j a v a2 s .co m*/ public <S extends Service> S getService(Class<S> type) { for (Service serv : this.serviceManager.servicesByState().values()) { if (serv.isRunning() && type.isInstance(serv)) { return type.cast(serv); } } return null; }