当前位置: 首页>>代码示例>>Java>>正文


Java Environment.addTask方法代码示例

本文整理汇总了Java中com.yammer.dropwizard.config.Environment.addTask方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.addTask方法的具体用法?Java Environment.addTask怎么用?Java Environment.addTask使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.yammer.dropwizard.config.Environment的用法示例。


在下文中一共展示了Environment.addTask方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.yammer.dropwizard.config.Environment; //导入方法依赖的package包/类
@Override
public void run(LocateApiConfiguration configuration, Environment environment) throws Exception {

    /**
     * Mongo set up
     */
    MongoClient mongoClient = configureMongoClient(environment, configuration.getMongoConfiguration());

    DB locateDb = setUpDb(configuration.getMongoConfiguration().getLocateDatabase(), configuration.getMongoConfiguration(), mongoClient);
    DB credentialsDb = setUpDb(configuration.getMongoConfiguration().getCredentialsDatabase(), configuration.getMongoConfiguration(), mongoClient);

    /**
     * Dao layer
     */
    final AuthorizationTokenDao authorizationTokenDao = configureAuthorizationTokenDao(credentialsDb);
    final UsageDao usageDao = configureRateMeterDao(credentialsDb);
    final AddressDao addressDao = configureAddressDao(locateDb);
    final PostcodeToAuthorityDao postcodeToAuthorityDao = configurePostcodeToAuthorityDao(locateDb);

    /**
     * Enable cors support
     */
    environment.addFilter(CrossOriginFilter.class, "*")
            .setInitParam("allowedOrigins", configuration.getAllowedOrigins())
            .setInitParam("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin,Authorization")
            .setInitParam("allowedMethods", "OPTIONS,GET");

    /**
     * Resources
     */
    environment.addResource(new AddressResource(addressDao, configuration));
    environment.addResource(new PostcodeToAuthorityResource(postcodeToAuthorityDao));

    /**
     * Healthchecks
     */
    environment.addHealthCheck(new MongoHealthCheck(mongoClient));

    /**
     * Exception mapper
     */
    environment.addProvider(new LocateExceptionMapper());

    /**
     * Authentication
     */
    environment.addProvider(new BearerTokenAuthProvider(configuration, usageDao, new BearerTokenAuthenticator(authorizationTokenDao)));

    /**
     * Better exception mappings
     */
    removeDefaultExceptionMappers(environment);

    /**
     * Date serialisation
     */
    environment.getObjectMapperFactory().setDateFormat(internalDateFormatter);

    /**
     * Tasks
     */
    environment.addTask(new MongoIndexTask(authorizationTokenDao, usageDao));

}
 
开发者ID:alphagov,项目名称:locate-api,代码行数:65,代码来源:LocateApiService.java

示例2: run

import com.yammer.dropwizard.config.Environment; //导入方法依赖的package包/类
@Override
public void run(Environment environment) {

    environment.addTask(new ExampleNagiosCheckTask());
}
 
开发者ID:Berico-Technologies,项目名称:Nagios-Dropwizard,代码行数:6,代码来源:ExampleNagiosBundle.java

示例3: run

import com.yammer.dropwizard.config.Environment; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * @throws IOException when instance in configuration can not be opened and closed.
 */
@Override
public final void run(final KijiRESTConfiguration configuration, final Environment environment)
    throws IOException {
  final KijiURI clusterURI = KijiURI.newBuilder(configuration.getClusterURI()).build();
  final ManagedKijiClient managedKijiClient = new ManagedKijiClient(configuration);
  environment.manage(managedKijiClient);

  // Setup the health checker for the KijiClient
  environment.addHealthCheck(new KijiClientHealthCheck(managedKijiClient));

  // Remove all built-in Dropwizard ExceptionHandler.
  // Always depend on custom ones.
  // Inspired by Jeremy Whitlock's suggestion on thoughtspark.org.
  Set<Object> jerseyResources = environment.getJerseyResourceConfig().getSingletons();
  Iterator<Object> jerseyResourcesIterator = jerseyResources.iterator();
  while (jerseyResourcesIterator.hasNext()) {
    Object jerseyResource = jerseyResourcesIterator.next();
    if (jerseyResource instanceof ExceptionMapper
        && jerseyResource.getClass().getName().startsWith("com.yammer.dropwizard.jersey")) {
      jerseyResourcesIterator.remove();
    }
  }

  // Load admin task to manually refresh instances.
  environment.addTask(new RefreshInstancesTask(managedKijiClient));
  // Load admin task to manually close instances and tables.
  environment.addTask(new CloseTask(managedKijiClient));
  // Load admin task to manually shutdown the system.
  environment.addTask(new ShutdownTask(managedKijiClient, configuration));

  // Adds custom serializers.
  registerSerializers(environment.getObjectMapperFactory());

  // Adds exception mappers to print better exception messages to the client than what
  // Dropwizard does by default.
  environment.addProvider(new GeneralExceptionMapper());

  // Load resources.
  for (KijiRestPlugin plugin : Lookups.get(KijiRestPlugin.class)) {
    LOG.info("Loading plugin {}", plugin.getClass());
    plugin.install(managedKijiClient, configuration, environment);
  }

  // Allow global CORS filter. CORS off by default.
  if (configuration.getCORS()) {
    environment.addFilter(
        CrossOriginFilter.class,
        configuration.getHttpConfiguration().getRootPath());
    LOG.info("Global cross-origin resource sharing is allowed.");
  }
}
 
开发者ID:kijiproject,项目名称:kiji-rest,代码行数:57,代码来源:KijiRESTService.java

示例4: run

import com.yammer.dropwizard.config.Environment; //导入方法依赖的package包/类
@Override
public void run(TestConfiguration configuration, Environment environment) throws Exception {

    for (NagiosCheckTask checkTask : configuration.getCheckTasks()){

        environment.addTask(checkTask);
    }

    for (HealthCheck healthCheck : configuration.getWrappedCheckTasks()){

        environment.addHealthCheck(healthCheck);
    }

    environment.addResource(FakeResource.class);
}
 
开发者ID:Berico-Technologies,项目名称:Nagios-Dropwizard,代码行数:16,代码来源:TestService.java


注:本文中的com.yammer.dropwizard.config.Environment.addTask方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。