Exemplo n.º 1
0
  /**
   * Creates a new environment.
   *
   * @param configuration the service's {@link Configuration}
   * @param service the service
   */
  public Environment(Configuration configuration, AbstractService<?> service) {
    this.service = service;
    this.config =
        new DropwizardResourceConfig() {
          @Override
          public void validate() {
            super.validate();
            logResources();
            logProviders();
            logHealthChecks();
            logManagedObjects();
            logEndpoints();
          }
        };
    this.healthChecks = ImmutableSet.builder();
    this.servlets = ImmutableMap.builder();
    this.filters = ImmutableMultimap.builder();
    this.servletListeners = ImmutableSet.builder();
    this.tasks = ImmutableSet.builder();
    this.lifeCycle = new AggregateLifeCycle();

    final HttpServlet jerseyContainer = service.getJerseyContainer(config);
    if (jerseyContainer != null) {
      addServlet(jerseyContainer, configuration.getHttpConfiguration().getRootPath())
          .setInitOrder(Integer.MAX_VALUE);
    }
    addTask(new GarbageCollectionTask());
  }
Exemplo n.º 2
0
 private void logHealthChecks() {
   final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
   for (HealthCheck healthCheck : healthChecks.build()) {
     builder.add(healthCheck.getClass().getCanonicalName());
   }
   LOG.debug("health checks = {}", builder.build());
 }
Exemplo n.º 3
0
 private void logManagedObjects() {
   final ImmutableSet.Builder<String> builder = ImmutableSet.builder();
   for (Object bean : lifeCycle.getBeans()) {
     builder.add(bean.getClass().getCanonicalName());
   }
   LOG.debug("managed objects = {}", builder.build());
 }
Exemplo n.º 4
0
  private void logProviders() {
    final ImmutableSet.Builder<String> builder = ImmutableSet.builder();

    for (Class<?> klass : config.getClasses()) {
      if (klass.isAnnotationPresent(Provider.class)) {
        builder.add(klass.getCanonicalName());
      }
    }

    for (Object o : config.getSingletons()) {
      if (o.getClass().isAnnotationPresent(Provider.class)) {
        builder.add(o.getClass().getCanonicalName());
      }
    }

    LOG.debug("providers = {}", builder.build());
  }