@Override public void doLaunch(final MessageInput input) throws MisfireException { generatorService = new AbstractExecutionThreadService() { @Override protected void run() throws Exception { while (isRunning()) { if (isThrottled()) { blockUntilUnthrottled(); } final RawMessage rawMessage = GeneratorTransport.this.produceRawMessage(input); if (rawMessage != null) { input.processRawMessage(rawMessage); } } } }; generatorService.startAsync(); }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service startAsync() { delegate.startAsync(); return this; }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service startAsync() { delegate.startAsync(); return this; }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service startAsync() { delegate.startAsync(); return this; }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service startAsync() { delegate.startAsync(); return this; }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service startAsync() { delegate.startAsync(); return this; }
/** @since 15.0 */ @CanIgnoreReturnValue @Override public final Service startAsync() { delegate.startAsync(); return this; }
@Override protected void doStart() { b.startAsync(); super.doStart(); } };
/** * 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; }
@Override protected void startUp() throws Exception { LOGGER.info("Starting the " + StreamingJobConfigurationManager.class.getSimpleName()); // submit command to fetch job specs this.fetchJobSpecExecutor.execute(new Runnable() { @Override public void run() { try { while(true) { fetchJobSpecs(); } } catch (InterruptedException e) { LOGGER.info("Fetch thread interrupted... will exit"); } catch (ExecutionException e) { LOGGER.error("Failed to fetch job specs", e); throw new RuntimeException("Failed to fetch specs", e); } } }); // if the instance consumer is a service then need to start it to consume job specs // IMPORTANT: StreamingKafkaSpecConsumer needs to be launched after a fetching thread is created. // This is because StreamingKafkaSpecConsumer will invoke addListener(new JobSpecListener()) during startup, // which will push job specs into a blocking queue _jobSpecQueue. A fetching thread will help to consume the // blocking queue to prevent a hanging issue. if (this.specConsumer instanceof Service) { ((Service) this.specConsumer).startAsync().awaitRunning(); } }
/** * Start any services required by the application launcher then start the application launcher */ private void startAppLauncherAndServices() { // other services such as the job configuration manager have a dependency on the job catalog, so it has be be // started first if (this.jobCatalog instanceof Service) { ((Service) this.jobCatalog).startAsync().awaitRunning(); } this.applicationLauncher.start(); }
/** * 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 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(); } }
/** * 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 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 testTimeout() throws Exception { // Create a service whose executor will never run its commands Service service = new TestService() { @Override protected Executor executor() { return new Executor() { @Override public void execute(Runnable command) {} }; } @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 testTimeout() { // Create a service whose executor will never run its commands Service service = new AbstractScheduledService() { @Override protected Scheduler scheduler() { return Scheduler.newFixedDelaySchedule(0, 1, TimeUnit.NANOSECONDS); } @Override protected ScheduledExecutorService executor() { return TestingExecutors.noOpScheduledExecutor(); } @Override protected void runOneIteration() throws Exception {} @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."); } }
stampedeService.startAsync(); stampedeService.awaitTerminated();
/** * @since 15.0 */ @Override public final Service startAsync() { delegate.startAsync(); return this; }
private static void doStartService(final Class<? extends Service> serviceClass) { try { final Service service = GuiceHelper.getGuiceInjector().getInstance(serviceClass); if (!service.isRunning()) service.startAsync(); else LOGGER.debug("service was already started, perhaps because it is an eager singleton?"); } catch (ConfigurationException e) { LOGGER.warn("Service may NOT be a Guice service, check configuration", e); } }