本文整理汇总了Java中io.dropwizard.servlets.tasks.Task类的典型用法代码示例。如果您正苦于以下问题:Java Task类的具体用法?Java Task怎么用?Java Task使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Task类属于io.dropwizard.servlets.tasks包,在下文中一共展示了Task类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@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);
}
示例2: task_binds_work
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@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));
}
示例3: run_adds_tasks
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@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));
}
示例4: task
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
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());
}
};
}
示例5: scanAndAdd
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@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);
}
}
示例6: registerTasks
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
/**
* 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());
}
}
示例7: buildBinders
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
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;
}
}
示例8: run
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
/**
* 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());
}
}
示例9: registerTask
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
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);
}
示例10: registerTasks
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
private void registerTasks(Environment environment, Injector injector) {
reflections.getSubTypesOf(Task.class).forEach(c -> {
environment.admin().addTask(injector.getInstance(c));
});
}
示例11: addTask
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@Override
public void addTask(Task task) {
_environment.admin().addTask(task);
}
示例12: addTask
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@Override
public void addTask(Task task) {
// ignore
}
示例13: matches
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@Override
public boolean matches(final Class<?> type) {
return FeatureUtils.is(type, Task.class);
}
示例14: install
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
@Override
public void install(final Environment environment, final Task instance) {
environment.admin().addTask(instance);
}
示例15: bindTask
import io.dropwizard.servlets.tasks.Task; //导入依赖的package包/类
protected void bindTask(Task task) {
Preconditions.checkNotNull(task, "Task cannot be null.");
buildBinders();
taskBinder.addBinding().toInstance(task);
}