Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package io.dropwizard.setup;
 
import static com.google.common.base.MoreObjects.firstNonNull;
import static com.google.common.base.Preconditions.checkNotNull;

The administrative environment of a Dropwizard application.
public class AdminEnvironment extends ServletEnvironment {
    private static final Logger LOGGER = LoggerFactory.getLogger(AdminEnvironment.class);
    private final HealthCheckRegistry healthChecks;
    private final TaskServlet tasks;

    
Creates a new AdminEnvironment.

Parameters:
handler a servlet context handler
healthChecks a health check registry
                            HealthCheckRegistry healthChecksMetricRegistry metricRegistry) {
        super(handler);
        this. = healthChecks;
        this..register("deadlocks"new ThreadDeadlockHealthCheck());
        this. = new TaskServlet(metricRegistry);
        .add(new GarbageCollectionTask());
        .add(new LogConfigurationTask());
        addServlet("tasks").addMapping("/tasks/*");
            @Override
            public void lifeCycleStarting(LifeCycle event) {
                logTasks();
                logHealthChecks();
            }
        });
    }

    
Adds the given task to the set of tasks exposed via the admin interface.

Parameters:
task a task
    public void addTask(Task task) {
        .add(checkNotNull(task));
    }
    private void logTasks() {
        final StringBuilder stringBuilder = new StringBuilder(1024).append(String.format("%n%n"));
        for (Task task : .getTasks()) {
            final String taskClassName = firstNonNull(task.getClass().getCanonicalName(), task.getClass().getName());
            stringBuilder.append(String.format("    %-7s /tasks/%s (%s)%n",
                                               "POST",
                                               task.getName(),
                                               taskClassName));
        }
        .info("tasks = {}"stringBuilder.toString());
    }
    private void logHealthChecks() {
        if (.getNames().size() <= 1) {
            .warn(String.format(
                    "%n" +
                            "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" +
                            "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" +
                            "!    THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW      !%n" +
                            "!     IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE      !%n" +
                            "!    LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR    !%n" +
                            "!         APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT.       !%n" +
                            "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!%n" +
                            "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
            ));
        }
        .debug("health checks = {}".getNames());
    }
New to GrepCode? Check out our FAQ X