@Override public void run(Environment environment) { ServiceLocatorUtilities.bind(serviceLocator, new EnvBinder(application, environment)); LifecycleEnvironment lifecycle = environment.lifecycle(); AdminEnvironment admin = environment.admin(); listServices(HealthCheck.class).forEach(healthCheck -> { String name = healthCheck.getClass().getSimpleName(); environment.healthChecks().register(name, healthCheck); }); listServices(Managed.class).forEach(lifecycle::manage); listServices(LifeCycle.class).forEach(lifecycle::manage); listServices(LifeCycle.Listener.class).forEach(lifecycle::addLifeCycleListener); listServices(ServerLifecycleListener.class).forEach(lifecycle::addServerLifecycleListener); listServices(Task.class).forEach(admin::addTask); environment.jersey().register(HK2LifecycleListener.class); //Set service locator as parent for Jersey's service locator environment.getApplicationContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator); environment.getAdminContext().setAttribute(ServletProperties.SERVICE_LOCATOR, serviceLocator); serviceLocator.inject(application); }
@Test public void initializeAndRun() { JAXWSBundle jaxwsBundle = new JAXWSBundle("/soap", jaxwsEnvironment); try { jaxwsBundle.run(null, null); } catch (Exception e) { assertThat(e, is(instanceOf(IllegalArgumentException.class))); } jaxwsBundle.initialize(bootstrap); verify(jaxwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class)); jaxwsBundle.run(null, environment); verify(servletEnvironment).addServlet(startsWith("CXF Servlet"), any(Servlet.class)); verify(lifecycleEnvironment).addServerLifecycleListener(any(ServerLifecycleListener.class)); verify(servlet).addMapping("/soap/*"); verify(jaxwsEnvironment, never()).setPublishedEndpointUrlPrefix(anyString()); }
@Test public void initializeAndRunWithPublishedEndpointUrlPrefix() { JAXWSBundle jaxwsBundle = new JAXWSBundle("/soap", jaxwsEnvironment) { @Override protected String getPublishedEndpointUrlPrefix(Object configuration) { return "http://some/prefix"; } }; try { jaxwsBundle.run(null, null); } catch (Exception e) { assertThat(e, is(instanceOf(IllegalArgumentException.class))); } jaxwsBundle.initialize(bootstrap); verify(jaxwsEnvironment).setInstrumentedInvokerBuilder(any(InstrumentedInvokerFactory.class)); jaxwsBundle.run(null, environment); verify(servletEnvironment).addServlet(startsWith("CXF Servlet"), any(Servlet.class)); verify(lifecycleEnvironment).addServerLifecycleListener(any(ServerLifecycleListener.class)); verify(servlet).addMapping("/soap/*"); verify(jaxwsEnvironment).setPublishedEndpointUrlPrefix("http://some/prefix"); }
@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); } }); }
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(); } } }); } }
@Override public void run(TestConfiguration testConfiguration, Environment environment) throws Exception { environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { SundialJobScheduler.addJob(JOB_NAME, TestJob.class); } }); }
public static ServerLifecycleListener serverLifecycleListener() { return new ServerLifecycleListener() { @Override public void serverStarted(final Server unused) { new ActivateJobExecutor().run(); } }; }
@Override public void run(Config configuration, Environment environment) throws Exception { CamundaHealthChecks.processIsDeployed(environment, PROCESS_DEFINITION_KEY); final StartProcessTask startProcessTask = new StartProcessTask(); environment.admin().addTask(startProcessTask); environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(final Server server) { startProcessTask.startProcess(); } }); }
private void startIfRequired() { if (jettyServer != null) { return; } try { application = newApplication(); final Bootstrap<C> bootstrap = new Bootstrap<C>(application) { @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); } }; application.initialize(bootstrap); final ServerCommand<C> command = new ServerCommand<>(application); final Namespace namespace = new Namespace(ImmutableMap.<String, Object>of("file", configPath)); command.run(bootstrap, namespace); } catch (Exception e) { throw new RuntimeException(e); } }
@Override public void run(BaragonAgentConfiguration configuration, Environment environment) throws Exception { environment.lifecycle().addServerLifecycleListener(new ServerProvider()); environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() { @Override public void serverStarted(Server server) { guiceBundle.getInjector().getInstance(LifecycleHelper.class).checkStateNodeVersion(); } }); }