Java 类io.dropwizard.lifecycle.ServerLifecycleListener 实例源码

项目:dropwizard-hk2bundle    文件:HK2Bundle.java   
@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);
}
项目:dropwizard-jaxws    文件:JAXWSBundleTest.java   
@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());
}
项目:dropwizard-jaxws    文件:JAXWSBundleTest.java   
@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");
}
项目:registry    文件:LocalSchemaRegistryServer.java   
@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);
        }
    });
}
项目:emodb    文件:EmoService.java   
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();
                }
            }
        });
    }
}
项目:dropwizard-sundial    文件:SundialBundleITBase.java   
@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);
        }
    });
}
项目:camunda-bpm-dropwizard    文件:ActivateJobExecutor.java   
public static ServerLifecycleListener serverLifecycleListener() {
  return new ServerLifecycleListener() {
    @Override
    public void serverStarted(final Server unused) {
      new ActivateJobExecutor().run();
    }
  };
}
项目:camunda-bpm-dropwizard    文件:DropwizardInvoiceExampleApplication.java   
@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();
    }
  });

}
项目:camunda-bpm-dropwizard    文件:DropwizardTwitterExampleApplication.java   
@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();
    }
  });

}
项目:monasca-common    文件:AbstractAppTest.java   
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);
  }
}
项目:Baragon    文件:BaragonAgentService.java   
@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();
    }
  });
}