@Override public void run(C configuration, Environment environment) throws Exception { environment.lifecycle().addServerLifecycleListener(server -> jettyServer = server); DropwizardTestSupport.this.configuration = configuration; DropwizardTestSupport.this.environment = environment; super.run(configuration, environment); for (ServiceListener<C> listener : listeners) { try { listener.onRun(configuration, environment, DropwizardTestSupport.this); } catch (Exception ex) { throw new RuntimeException("Error running app rule start listener", ex); } } } };
private void evaluateServiceStartedListeners() throws Exception { final List<ServerStartedListener> listeners = _injector.getInstance( Key.get(new TypeLiteral<List<ServerStartedListener>>() {})); if (!listeners.isEmpty()) { _environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { for (ServerStartedListener listener : listeners) { listener.serverStarted(); } } }); } }
/** * Register {@link ServerLifecycleListener}s in Dropwizard {@link Environment} from Spring application context. * * @param environment the Dropwizard environment * @param context the Spring application context */ private void registerServerLifecycleListeners(Environment environment, ConfigurableApplicationContext context) { Map<String, ServerLifecycleListener> beansOfType = context.getBeansOfType(ServerLifecycleListener.class); for (String beanName : beansOfType.keySet()) { // Add serverLifecycleListener to Dropwizard environment if (!beanName.equals(ENVIRONMENT_BEAN_NAME)) { ServerLifecycleListener serverLifecycleListener = beansOfType.get(beanName); environment.lifecycle().addServerLifecycleListener(serverLifecycleListener); LOG.info("Registering serverLifecycleListener: " + serverLifecycleListener.getClass().getName()); } } }
private void registerAndNotifyOtherServers(Environment environment) { environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { String serverURL = server.getURI().toString(); haServerNotificationManager.setHomeNodeURL(serverURL); try { transactionManager.beginTransaction(TransactionIsolation.SERIALIZABLE); HostConfigStorable hostConfigStorable = storageManager.get(new HostConfigStorable(serverURL).getStorableKey()); if (hostConfigStorable == null) { storageManager.add(new HostConfigStorable(storageManager.nextId(HostConfigStorable.NAME_SPACE), serverURL, System.currentTimeMillis())); } haServerNotificationManager.refreshServerInfo(storageManager.<HostConfigStorable>list(HostConfigStorable.NAME_SPACE)); transactionManager.commitTransaction(); } catch (Exception e) { transactionManager.rollbackTransaction(); throw e; } haServerNotificationManager.notifyDebut(); refreshHAServerManagedTask = new RefreshHAServerManagedTask(storageManager,transactionManager, haServerNotificationManager); environment.lifecycle().manage(refreshHAServerManagedTask); refreshHAServerManagedTask.start(); } }); }
private void registerAndNotifyOtherServers(Environment environment) { environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { String serverURL = server.getURI().toString(); haServerNotificationManager.setHomeNodeURL(serverURL); try { transactionManager.beginTransaction(TransactionIsolation.SERIALIZABLE); HostConfigStorable hostConfigStorable = storageManager.get(new HostConfigStorable(serverURL).getStorableKey()); if (hostConfigStorable == null) { storageManager.add(new HostConfigStorable(storageManager.nextId(HostConfigStorable.NAME_SPACE), serverURL, System.currentTimeMillis())); } haServerNotificationManager.refreshServerInfo(storageManager.<HostConfigStorable>list(HostConfigStorable.NAME_SPACE)); transactionManager.commitTransaction(); } catch (Exception e) { transactionManager.rollbackTransaction(); throw e; } haServerNotificationManager.notifyDebut(); refreshHAServerManagedTask = new RefreshHAServerManagedTask(storageManager,transactionManager, haServerNotificationManager); environment.lifecycle().manage(refreshHAServerManagedTask); refreshHAServerManagedTask.start(); } }); }
@Override public void run(RegistryConfiguration registryConfiguration, Environment environment) throws Exception { super.run(registryConfiguration, environment); environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { localServer = server; LOG.info("Received callback as server is started :[{}]", server); } }); }
@Override public void run(RegistryConfiguration registryConfiguration, Environment environment) throws Exception { super.run(registryConfiguration, environment); environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { localServer = server; LOG.info("Received callback as server is started :[{}]", server); } }); }
@Override public void run(C configuration, Environment environment) throws Exception { environment.lifecycle().addServerLifecycleListener(server -> jettyServer = server); DropwizardTestSupport.this.configuration = configuration; DropwizardTestSupport.this.environment = environment; super.run(configuration, environment); for (ServiceListener<C> listener : listeners) { try { listener.onRun(configuration, environment, DropwizardTestSupport.this); } catch (Exception ex) { throw new RuntimeException("Error running app rule start listener", ex); } } } };
private void registerHA(HAConfiguration haConfiguration, Environment environment) throws Exception { if(haConfiguration != null) { environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) {
private void registerHA(HAConfiguration haConfiguration, Environment environment) throws Exception { if(haConfiguration != null) { environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) {
lifecycleEnvironment.addServerLifecycleListener( new ServerLifecycleListener() { @Override
@Override public void run(C configuration, Environment environment) throws Exception { environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { jettyServer = server; } }); AbstractAppTest.this.configuration = configuration; AbstractAppTest.this.environment = environment; super.run(configuration, environment); } };
protected void setupEnvironment(ConsulFactory consulConfig, Environment environment) { final Consul consul = consulConfig.build(); final String serviceId = consulConfig.getServiceId().orElse(UUID.randomUUID().toString()); final ConsulAdvertiser advertiser = new ConsulAdvertiser(environment, consulConfig, consul, serviceId); final Optional<Duration> retryInterval = consulConfig.getRetryInterval(); final Optional<ScheduledExecutorService> scheduler = retryInterval.map(i -> Executors.newScheduledThreadPool(1)); // Register a Jetty listener to get the listening host and port environment .lifecycle() .addServerLifecycleListener( new ConsulServiceListener(advertiser, retryInterval, scheduler)); // Register a ping healthcheck to the Consul agent environment.healthChecks().register("consul", new ConsulHealthCheck(consul)); // Register a shutdown manager to deregister the service environment.lifecycle().manage(new ConsulAdvertiserManager(advertiser, scheduler)); // Add an administrative task to toggle maintenance mode environment.admin().addTask(new MaintenanceTask(consul, serviceId)); }
/** * Implements com.yammer.dropwizard.Bundle#run() */ @Override public void run(C configuration, Environment environment) { checkArgument(environment != null, "Environment is null"); environment.servlets().addServlet("CXF Servlet " + jaxwsEnvironment.getDefaultPath(), jaxwsEnvironment.buildServlet()).addMapping(servletPath); environment.lifecycle().addServerLifecycleListener( server -> jaxwsEnvironment.logEndpoints()); String publishedEndpointUrlPrefix = getPublishedEndpointUrlPrefix(configuration); if(publishedEndpointUrlPrefix != null) { jaxwsEnvironment.setPublishedEndpointUrlPrefix(publishedEndpointUrlPrefix); } }
environment.lifecycle().addServerLifecycleListener(server -> applyMongoMigration(configuration));
/** * Builds a {@link KafkaConsumer} instance from the given {@link ExecutorService} and name, * for the given {@link Environment}. * <p/> * The name is used to identify the returned {@link KafkaConsumer} instance, for example, as * the name of its {@link com.codahale.metrics.health.HealthCheck}s, etc. * * @param environment the {@link Environment} to build {@link KafkaConsumer} instances for. * @param executor the {@link ExecutorService} to process messages with. * @param name the name of the {@link KafkaConsumer}. * * @return a managed and configured {@link KafkaConsumer}. */ public KafkaConsumer build(final Environment environment, final ScheduledExecutorService executor, final String name) { final SynchronousConsumer<K, V> consumer = build(executor); // manage the consumer environment.lifecycle().manage(consumer); environment.lifecycle().addServerLifecycleListener(consumer); // add health checks environment.healthChecks().register(name, new KafkaConsumerHealthCheck(consumer)); return consumer; }
environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) {
environment.jersey().register(new TransactionBinder()); environment.lifecycle().addServerLifecycleListener(this);
environment.lifecycle().addServerLifecycleListener(new BaseUriDeriver(configuration));