Refine search
/** @since 15.0 */ @Override public final void awaitRunning() { delegate.awaitRunning(); }
@Override public void doStop() { if (generatorService == null || !generatorService.isRunning()) { log.error("Cannot stop generator transport, it isn't running."); return; } log.debug("Stopping generator transport service {}", generatorService); generatorService.stopAsync().awaitTerminated(); generatorService = null; }
/** @since 13.0 */ @Override public final void addListener(Listener listener, Executor executor) { delegate.addListener(listener, executor); }
private void stopQuietly(final Service service) { if (service == null) { return; } try { service.stopAsync().awaitTerminated(); } catch (Exception ignore) { // ignored } }
/** * Initiates service {@linkplain Service#startAsync startup} on all the services being managed. It * is only valid to call this method if all of the services are {@linkplain State#NEW new}. * * @return this * @throws IllegalStateException if any of the Services are not {@link State#NEW new} when the * method is called. */ @CanIgnoreReturnValue public ServiceManager startAsync() { for (Service service : services) { State state = service.state(); checkState(state == NEW, "Service %s is %s, cannot start it.", service, state); } for (Service service : services) { try { state.tryStartTiming(service); service.startAsync(); } catch (IllegalStateException e) { // This can happen if the service has already been started or stopped (e.g. by another // service or listener). Our contract says it is safe to call this method if // all services were NEW when it was called, and this has already been verified above, so we // don't propagate the exception. logger.log(Level.WARNING, "Unable to start Service " + service, e); } } return this; }
public void testDefaultService() throws InterruptedException { WaitOnRunService service = new WaitOnRunService(); service.startAsync().awaitRunning(); enterRun.await(); service.stopAsync().awaitTerminated(); }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service stopAsync() { delegate.stopAsync(); return this; }
@Override public synchronized void failed(State from, Throwable failure) { assertEquals(from, Iterables.getLast(stateHistory)); stateHistory.add(State.FAILED); assertEquals(State.FAILED, service.state()); assertEquals(failure, service.failureCause()); if (from == State.STARTING) { try { service.awaitRunning(); fail(); } catch (IllegalStateException e) { assertThat(e).hasCauseThat().isEqualTo(failure); } } try { service.awaitTerminated(); fail(); } catch (IllegalStateException e) { assertThat(e).hasCauseThat().isEqualTo(failure); } completionLatch.countDown(); } }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service startAsync() { delegate.startAsync(); return this; }
public void testTimeout() { // Create a service whose executor will never run its commands Service service = new AbstractExecutionThreadService() { @Override protected void run() throws Exception {} @Override protected ScheduledExecutorService executor() { return TestingExecutors.noOpScheduledExecutor(); } @Override protected String serviceName() { return "Foo"; } }; try { service.startAsync().awaitRunning(1, TimeUnit.MILLISECONDS); fail("Expected timeout"); } catch (TimeoutException e) { assertThat(e) .hasMessageThat() .isEqualTo("Timed out waiting for Foo [STARTING] to reach the RUNNING state."); } }
public void testCustomScheduler_deadlock() throws InterruptedException, BrokenBarrierException { final CyclicBarrier inGetNextSchedule = new CyclicBarrier(2); // This will flakily deadlock, so run it multiple times to increase the flake likelihood for (int i = 0; i < 1000; i++) { Service service = new AbstractScheduledService() { @Override protected void runOneIteration() {} @Override protected Scheduler scheduler() { return new CustomScheduler() { @Override protected Schedule getNextSchedule() throws Exception { if (state() != State.STARTING) { inGetNextSchedule.await(); Thread.yield(); throw new RuntimeException("boom"); } return new Schedule(0, TimeUnit.NANOSECONDS); } }; } }; service.startAsync().awaitRunning(); inGetNextSchedule.await(); service.stopAsync(); } }
@Override public synchronized void running() { assertEquals(State.STARTING, Iterables.getOnlyElement(stateHistory)); stateHistory.add(State.RUNNING); service.awaitRunning(); assertNotSame(State.STARTING, service.state()); }
/** @since 15.0 */ @Override public final void awaitTerminated(long timeout, TimeUnit unit) throws TimeoutException { delegate.awaitTerminated(timeout, unit); }
WeakReference<ServiceManagerState> stateReference = new WeakReference<>(state); for (Service service : copy) { service.addListener(new ServiceListener(service, stateReference), directExecutor()); checkArgument(service.state() == NEW, "Can only manage NEW services, %s", service);
private void stopQuietly(Service service) { try { service.stopAndWait(); } catch (Exception e) { LOG.debug("Error stopping the preview runner.", e); } }
/** @since 14.0 */ @Override public final Throwable failureCause() { return delegate.failureCause(); }
@Override public final boolean isRunning() { return delegate.isRunning(); }
@Deprecated @Override public final State startAndWait() { return delegate.startAndWait(); }
@Override public void failure(Service service) { super.failure(service); LOG.error(String.format("Service %s has failed.", service.getClass().getSimpleName()), service.failureCause()); try { service.stopAsync(); ServiceBasedAppLauncher.this.stop(); } catch (ApplicationException ae) { LOG.error("Could not shutdown services gracefully. This may cause the application to hang."); } } });
@Override protected void doStop() throws Exception { if (service.state() != Service.State.TERMINATED && service.state() != Service.State.FAILED) { LOG.debug("stopping controller service for program {}.", getProgramRunId()); service.stopAndWait(); LOG.debug("stopped controller service for program {}, waiting for it to finish running listener hooks.", getProgramRunId()); serviceStoppedLatch.await(30, TimeUnit.SECONDS); LOG.debug("controller service for program {} finished running listener hooks.", getProgramRunId()); } }