Java 类io.dropwizard.servlets.tasks.Task 实例源码

项目: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);
}
项目:graceland-core    文件:AbstractPlugin.java   
private void buildBinders() {
    if (!bindersBuilt) {
        jerseyBinder = Multibinder.newSetBinder(binder(), Object.class, Graceland.class);
        managedBinder = Multibinder.newSetBinder(binder(), Managed.class, Graceland.class);
        managedClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.ManagedClass, Graceland.class);
        healthCheckBinder = Multibinder.newSetBinder(binder(), HealthCheck.class, Graceland.class);
        healthCheckClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.HealthCheckClass, Graceland.class);
        taskBinder = Multibinder.newSetBinder(binder(), Task.class, Graceland.class);
        taskClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.TaskClass, Graceland.class);
        bundleBinder = Multibinder.newSetBinder(binder(), Bundle.class, Graceland.class);
        bundleClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.BundleClass, Graceland.class);
        commandBinder = Multibinder.newSetBinder(binder(), Command.class, Graceland.class);
        commandClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.CommandClass, Graceland.class);
        initializerBinder = Multibinder.newSetBinder(binder(), Initializer.class, Graceland.class);
        initializerClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.InitializerClass, Graceland.class);
        configuratorBinder = Multibinder.newSetBinder(binder(), Configurator.class, Graceland.class);
        configuratorClassBinder = Multibinder.newSetBinder(binder(), TypeLiterals.ConfiguratorClass, Graceland.class);

        bindersBuilt = true;
    }
}
项目:graceland-core    文件:AbstractPluginTest.java   
@Test
public void task_binds_work() {
    final Task task = mock(Task.class);
    final Class<TestTask> taskClass = TestTask.class;

    Injector injector = Guice.createInjector(new AbstractPlugin() {
        @Override
        protected void configure() {
            bindTask(task);
            bindTask(taskClass);
        }
    });

    Set<Task> taskSet = injector.getInstance(Keys.Tasks);
    Set<Class<? extends Task>> taskClassSet = injector.getInstance(Keys.TaskClasses);

    assertThat(taskSet, hasSize(1));
    assertThat(taskSet, hasItem(task));
    assertThat(taskClassSet, hasSize(1));
    assertThat(taskClassSet, hasItem(TestTask.class));
}
项目:graceland-core    文件:PlatformTest.java   
@Test
public void run_adds_tasks() throws Exception {
    final Task task = mock(Task.class);
    final Class<TestTask> taskClass = TestTask.class;

    Application application = buildApplication(
            new AbstractPlugin() {
                @Override
                protected void configure() {
                    bindTask(task);
                    bindTask(taskClass);
                }
            }
    );

    new Platform(application).run(configuration, environment);

    verify(adminEnvironment).addTask(eq(task));
    verify(adminEnvironment).addTask(isA(TestTask.class));
}
项目:camunda-bpm-dropwizard    文件:ActivateJobExecutor.java   
public static Task task() {
  return new Task(NAME) {
    @Override
    public void execute(final ImmutableMultimap<String, String> unused, final PrintWriter printWriter) throws Exception {
        printWriter.println(new ActivateJobExecutor().start());
    }
  };
}
项目:robe    文件:TaskScanner.java   
@Override
public void scanAndAdd(Environment environment, Injector injector, Reflections reflections) {
    Set<Class<? extends Task>> taskClasses = reflections.getSubTypesOf(Task.class);
    for (Class<? extends Task> task : taskClasses) {
        environment.admin().addTask(injector.getInstance(task));
        LOGGER.info("Added task: " + task);
    }
}
项目:dropwizard-springbundle    文件:SpringBundle.java   
/**
 * Register Task classes into Dropwizard context.
 *
 * @param environment
 */
private void registerTasks(Environment environment) {
    final Map<String, Task> beansOfType = applicationContext.getBeansOfType(Task.class);
    for (String beanName : beansOfType.keySet()) {
        Task task = beansOfType.get(beanName);
        environment.admin().addTask(task);
        logger.info("Registering task: " + task.getClass().getName());
    }
}
项目:graceland-core    文件:Platform.java   
/**
 * Ran when the Dropwizard service starts up. This method is responsible for setting up the
 * {@link io.dropwizard.setup.Environment} using the bindings from the loaded
 * {@link io.graceland.plugin.Plugin}s.
 *
 * @param configuration Provided by Dropwizard.
 * @param environment   Provided by Dropwizard.
 * @throws Exception Thrown by Dropwizard.
 */
@Override
public void run(PlatformConfiguration configuration, Environment environment) throws Exception {
    dropwizardModule.setup(configuration, environment);

    for (Configurator configurator : wrapper.getConfigurators()) {
        configurator.configure(configuration, environment);
        LOGGER.debug("Registered Configurator: {}", configurator.getClass().getCanonicalName());
    }

    for (Object jerseyComponent : wrapper.getJerseyComponents()) {
        environment.jersey().register(jerseyComponent);
        LOGGER.debug("Registered Jersey Component: {}", jerseyComponent.getClass().getCanonicalName());
    }

    for (Managed managed : wrapper.getManaged()) {
        environment.lifecycle().manage(managed);
        LOGGER.debug("Registered Managed Object: {}", managed.getClass().getCanonicalName());
    }

    for (HealthCheck healthCheck : wrapper.getHealthChecks()) {
        environment.healthChecks().register(healthCheck.toString(), healthCheck);
        LOGGER.debug("Registered Health Check: {}", healthCheck.getClass().getCanonicalName());
    }

    for (Task task : wrapper.getTasks()) {
        environment.admin().addTask(task);
        LOGGER.debug("Registered Task: {}", task.getClass().getCanonicalName());
    }

    for (FilterSpec filterSpec : wrapper.getFilterSpecs()) {
        registerFilterSpec(environment, filterSpec);

        LOGGER.debug("Registered Filter {}: {}",
                filterSpec.getName(),
                filterSpec.getFilter().getClass().getCanonicalName());
    }
}
项目:stroom-stats    文件:App.java   
private <T extends Task> void registerTask(final Environment environment, Class<T> type) {
    LOGGER.info("Registering task with class {}", type.getName());
    T task = injector.getInstance(type);
    environment.admin().addTask(task);
}
项目:outland    文件:GuiceApplication.java   
private void registerTasks(Environment environment, Injector injector) {
  reflections.getSubTypesOf(Task.class).forEach(c -> {
    environment.admin().addTask(injector.getInstance(c));
  });
}
项目:emodb    文件:DropwizardTaskRegistry.java   
@Override
public void addTask(Task task) {
    _environment.admin().addTask(task);
}
项目:emodb    文件:IgnoreAllTaskRegistry.java   
@Override
public void addTask(Task task) {
    // ignore
}
项目:dropwizard-guicey    文件:TaskInstaller.java   
@Override
public boolean matches(final Class<?> type) {
    return FeatureUtils.is(type, Task.class);
}
项目:dropwizard-guicey    文件:TaskInstaller.java   
@Override
public void install(final Environment environment, final Task instance) {
    environment.admin().addTask(instance);
}
项目:graceland-core    文件:AbstractPlugin.java   
protected void bindTask(Task task) {
    Preconditions.checkNotNull(task, "Task cannot be null.");
    buildBinders();
    taskBinder.addBinding().toInstance(task);
}
项目:graceland-core    文件:AbstractPlugin.java   
protected void bindTask(Class<? extends Task> taskClass) {
    Preconditions.checkNotNull(taskClass, "Task Class cannot be null.");
    buildBinders();
    taskClassBinder.addBinding().toInstance(taskClass);
}
项目:graceland-core    文件:InjectorWrapper.java   
public ImmutableSet<Task> getTasks() {
    return getAndBuildInstances(Keys.Tasks, Keys.TaskClasses);
}
项目:emodb    文件:TaskRegistry.java   
void addTask(Task task);