本文整理汇总了Java中io.dropwizard.setup.Environment类的典型用法代码示例。如果您正苦于以下问题:Java Environment类的具体用法?Java Environment怎么用?Java Environment使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Environment类属于io.dropwizard.setup包,在下文中一共展示了Environment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.dropwizard.setup.Environment; //导入依赖的package包/类
public void run(Configuration configuration, Environment environment) throws Exception {
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
final PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
.withCollectorRegistry(collectorRegistry)
.withConstLabel("service", getName())
.build();
final Tracer tracer = getTracer();
final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
GlobalTracer.register(metricsTracer);
final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
environment.jersey().register(tracing);
final Properties producerConfigs = new Properties();
producerConfigs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "tweets-kafka:9092");
producerConfigs.put(ProducerConfig.ACKS_CONFIG, "all");
producerConfigs.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);
final KafkaProducer<Long, String> kafkaProducer =
new KafkaProducer<>(producerConfigs, new LongSerializer(), new StringSerializer());
final Producer<Long, String> tracingKafkaProducer =
new TracingKafkaProducer<>(kafkaProducer, metricsTracer);
final ObjectMapper objectMapper = environment.getObjectMapper();
final TweetEventRepository tweetRepository = new KafkaTweetEventRepository(tracingKafkaProducer, objectMapper);
final TweetsService tweetsService = new TweetsService(tweetRepository);
final TweetsResource tweetsResource = new TweetsResource(tweetsService);
environment.jersey().register(tweetsResource);
}
示例2: JDBIManager
import io.dropwizard.setup.Environment; //导入依赖的package包/类
/**
* @param shardService Your shard service.
* @param shardRegistry Your shard registry.
* @param dbiRegistry Your DBI registry.
* @param daoRegistry Your DAO registry.
* @param dropwizardDbiFactory Your dropwizard application's DBI Factory.
* @param dropwizardEnvironment Your dropwizard application's environment.
* @param dropwizardDSFactory Your dropwizard application's datasource factory.
* @param DBIInitializer We call your initializer immediately after dropwizardDbiFactory builds your
* DBI. @see jdbishard.jdbi.NoOpDBIInitializer.
* @param humanFriendlyShardNamer We register metrics for each shard connection given the human
* friendly name. @see jdbishard.sharding.IdOnlyShardNamer.
*/
@Inject
public JDBIManager(
ShardService<ShardIdT, KeyT> shardService,
ShardRegistry<ShardIdT, KeyT> shardRegistry,
DBIRegistry<ShardIdT> dbiRegistry,
DAORegistry<ShardIdT> daoRegistry,
DBIFactory dropwizardDbiFactory,
Environment dropwizardEnvironment,
DataSourceFactory dropwizardDSFactory,
DBIInitializer DBIInitializer,
HumanFriendlyShardNamer humanFriendlyShardNamer)
{
this.shardService = shardService;
this.shardRegistry = shardRegistry;
this.dbiRegistry = dbiRegistry;
this.daoRegistry = daoRegistry;
this.dropwizardDbiFactory = dropwizardDbiFactory;
this.dropwizardEnvironment = dropwizardEnvironment;
this.dropwizardDSFactory = dropwizardDSFactory;
this.DBIInitializer = DBIInitializer;
this.humanFriendlyShardNamer = humanFriendlyShardNamer;
}
示例3: run
import io.dropwizard.setup.Environment; //导入依赖的package包/类
@Override
public final void run(MatchingServiceAdapterConfiguration configuration, Environment environment) {
IdaSamlBootstrap.bootstrap();
environment.getObjectMapper().setDateFormat(new ISO8601DateFormat());
environment.jersey().register(LocalMetadataResource.class);
environment.jersey().register(MatchingServiceResource.class);
environment.jersey().register(UnknownUserAttributeQueryResource.class);
environment.jersey().register(SamlOverSoapExceptionMapper.class);
environment.jersey().register(ExceptionExceptionMapper.class);
MatchingServiceAdapterHealthCheck healthCheck = new MatchingServiceAdapterHealthCheck();
environment.healthChecks().register(healthCheck.getName(), healthCheck);
}
开发者ID:alphagov,项目名称:verify-matching-service-adapter,代码行数:17,代码来源:MatchingServiceAdapterApplication.java
示例4: extractRowsForSimpleServer
import io.dropwizard.setup.Environment; //导入依赖的package包/类
private static List<ApplicationUrlsGenerator> extractRowsForSimpleServer(Environment environment, ServerConnector connector) {
return ImmutableList.of(
new ApplicationUrlsGenerator(
APPLICATION_URL_TYPE,
isHttps(connector.getDefaultProtocol()),
connector.getLocalPort(),
environment.getApplicationContext().getContextPath()
),
new ApplicationUrlsGenerator(
ADMIN_URL_TYPE,
isHttps(connector.getDefaultProtocol()),
connector.getLocalPort(),
environment.getAdminContext().getContextPath()
),
new ApplicationUrlsGenerator(
HEALTHCHECK_URL_TYPE,
isHttps(connector.getDefaultProtocol()),
connector.getLocalPort(),
environment.getAdminContext().getContextPath()
)
);
}
示例5: build
import io.dropwizard.setup.Environment; //导入依赖的package包/类
/**
* Create an instance of MyBatis.
*
* @param environment The dropwizard environment
* @param configuration The data source factory/configuration
* @param dataSource The datasource you want to use.
* @param name The name of this mybatis factory used for metrics
* @return An instance of MyBatis.
*/
public final SqlSessionFactory build(Environment environment,
DataSourceFactory configuration,
ManagedDataSource dataSource,
String name) {
// Initialize validation query
final String validationQuery = configuration.getValidationQuery();
// Build mybatis session factory
TransactionFactory transactionFactory = new JdbcTransactionFactory();
org.apache.ibatis.mapping.Environment myBatisEnvironment =
new org.apache.ibatis.mapping.Environment(ENV_NAME, transactionFactory, dataSource);
Configuration mybatisConfiguration = new Configuration(myBatisEnvironment);
SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(mybatisConfiguration);
// Setup managed data source and health checks
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name, new MyBatisHealthCheck(sessionFactory, validationQuery));
return sessionFactory;
}
示例6: registerResources
import io.dropwizard.setup.Environment; //导入依赖的package包/类
private void registerResources(Environment environment) {
EventStore eventStore = new InMemoryEventStore();
EventBus eventBus = new AsyncEventBus(newSingleThreadExecutor());
// domain model
AccountService accountService = new AccountService(eventStore, eventBus);
environment.jersey().register(new AccountsResource(accountService));
environment.jersey().register(new AccountResource(accountService));
environment.jersey().register(new DepositsResource(accountService));
environment.jersey().register(new WithdrawalsResource(accountService));
ClientService clientService = new ClientService(eventStore);
environment.jersey().register(new ClientsResource(clientService));
environment.jersey().register(new ClientResource(clientService));
// read model
TransactionsRepository transactionsRepository = new InMemoryTransactionsRepository();
eventBus.register(new TransactionsListener(transactionsRepository));
environment.jersey().register(new AccountTransactionsResource(transactionsRepository));
AccountsRepository accountsRepository = new InMemoryAccountsRepository();
eventBus.register(new AccountsListener(accountsRepository));
environment.jersey().register(new ClientAccountsResource(accountsRepository));
}
示例7: build
import io.dropwizard.setup.Environment; //导入依赖的package包/类
@Override
public DBI build(Environment environment, PooledDataSourceFactory configuration, ManagedDataSource dataSource, String name) {
final DBI dbi = super.build(environment, configuration, dataSource, name);
dbi.registerArgumentFactory(new ValueArgumentFactory(configuration.getDriverClass()));
dbi.registerArgumentFactory(new OptionArgumentFactory(configuration.getDriverClass()));
dbi.registerContainerFactory(new OptionContainerFactory());
// The order of container factories is important, least specific to most specific
dbi.registerContainerFactory(new SeqContainerFactory());
dbi.registerContainerFactory(new IndexedSeqContainerFactory());
dbi.registerContainerFactory(new SetContainerFactory());
dbi.registerContainerFactory(new TreeContainerFactory());
dbi.registerContainerFactory(new ListContainerFactory());
dbi.registerContainerFactory(new ArrayContainerFactory());
dbi.registerContainerFactory(new QueueContainerFactory());
dbi.registerContainerFactory(new StreamContainerFactory());
dbi.registerContainerFactory(new VectorContainerFactory());
return dbi;
}
示例8: run
import io.dropwizard.setup.Environment; //导入依赖的package包/类
@Override
public void run(Configuration configuration, Environment environment) throws Exception {
// Preparing Translation Service
final TranslationService translationService = new TranslationService();
// Preparing Greeting Service and inject Translation
final GreetingResource greetingService = new GreetingResource(translationService);
// Register Greeting Service
environment.jersey().register(greetingService);
// Add Metrics Instrumentation to count requests
final CollectorRegistry collectorRegistry = new CollectorRegistry();
collectorRegistry.register(new DropwizardExports(environment.metrics()));
// Register Metrics Servlet
environment.admin()
.addServlet("metrics", new MetricsServlet(collectorRegistry))
.addMapping("/metrics");
}
示例9: DefaultSqlSessionFactoryProvider
import io.dropwizard.setup.Environment; //导入依赖的package包/类
/**
* Create a new provider instance
*
* @param dropwizardEnvironment The dropwizard environment object
* @param applicationName The application name
* @param dataSourceFactories The MultiEnvAware datasource list used to create session factories from
* @param typeHandlers The list of type handlers to configure with each session factory
* @param sqlMappers The list of sql mappers to configure with each session factory
*/
private DefaultSqlSessionFactoryProvider(Environment dropwizardEnvironment,
String applicationName,
MultiEnvAware<ConfigurableLazyDataSourceFactory> dataSourceFactories,
List<Class<?>> typeHandlers,
List<Class<?>> sqlMappers,
Map<Class<?>, Class<?>> typeClassToTypeHandlerClassMap,
Map<String, Class<?>> typeToAliasClassMap,
ObjectFactory objectFactory,
Map<String, Object> mybatisConfigurationSettingsMap) {
this.dropwizardEnvironment = dropwizardEnvironment;
this.applicationName = applicationName;
this.dataSourceFactories = dataSourceFactories;
this.typeHandlers = typeHandlers;
this.sqlMappers = sqlMappers;
this.typeClassToTypeHandlerClassMap = typeClassToTypeHandlerClassMap;
this.typeToAliasClassMap = typeToAliasClassMap;
this.objectFactory = objectFactory;
this.mybatisConfigurationSettings = mybatisConfigurationSettingsMap;
sessionFactories = dataSourceFactories.convert((env, dataSource) -> buildSessionFactory(dataSource, env));
}
示例10: run
import io.dropwizard.setup.Environment; //导入依赖的package包/类
@Override
public void run(TestAppConfig configuration, Environment environment) throws Exception {
final ShardRegistry<String, UUID> shardRegistry = new ShardRegistry<>();
final DAORegistry<String> daoRegistry = new DAORegistry<>();
final DBIFactory dbiFactory = new DBIFactory();
jdbiManager = new JDBIManager<>(
new StaticShardService(),
shardRegistry,
new DBIRegistry<>(),
daoRegistry,
dbiFactory,
environment,
configuration.getDataSourceFactory(),
new NoOpDBIInitializer(),
new IdOnlyShardNamer());
clientDAO = new ClientDAO(shardRegistry, daoRegistry);
daoRegistry.registerType(ClientShardDAO.class);
jdbiManager.updateObjects();
}
示例11: run
import io.dropwizard.setup.Environment; //导入依赖的package包/类
@Override
public void run(final CONFIG configuration,
final Environment environment) {
environment.jersey().register(auditedQueryResourceClass);
environment.jersey().register(auditedDocRefResourceClass);
environment.jersey().register(new AbstractBinder() {
@Override
protected void configure() {
bind(QueryEventLoggingService.class).to(EventLoggingService.class);
bind(queryServiceClass).to(QueryService.class);
bind(docRefServiceClass).to(new ParameterizedTypeImpl(DocRefService.class, docRefEntityClass));
bind(AuthorisationServiceImpl.class).to(AuthorisationService.class);
bind(configuration.getAuthorisationServiceConfig()).to(AuthorisationServiceConfig.class);
bind(configuration.getTokenConfig()).to(TokenConfig.class);
}
});
}
示例12: run
import io.dropwizard.setup.Environment; //导入依赖的package包/类
@Override
public void run(AppConfiguration appConfiguration, Environment environment) throws Exception {
logger.info("Registering jersey HTTP API");
final URL configurationsDirURL = Helpers.getResourceURL("configurations/");
final URI configurationsDirURI = configurationsDirURL.toURI();
final ConfigurationDAO configurationDAO = new SimpleFilesystemConfigurationDAO(configurationsDirURI);
final ConfigurationsResource configurationsResource = new ConfigurationsResource(configurationDAO);
environment.jersey().register(configurationsResource);
final URL documentsDirURL = Helpers.getResourceURL("documents/");
final URI documentsDirURI = documentsDirURL.toURI();
final DocumentDAO documentDAO = new SimpleFilesystemDocumentDAO(documentsDirURI);
final DocumentsResource documentsResource = new DocumentsResource(documentDAO);
environment.jersey().register(documentsResource);
final URL platesDirURL = Helpers.getResourceURL("plates/");
final URI platesDirURI = platesDirURL.toURI();
final PlateDAO plateDAO = new SimpleFilesystemPlateDAO(platesDirURI);
final PlatesResource platesResource = new PlatesResource(plateDAO);
environment.jersey().register(platesResource);
logger.info("HTTP API registered");
}
示例13: register
import io.dropwizard.setup.Environment; //导入依赖的package包/类
static void register(Environment environment, Injector injector) {
register(environment, "QueryResource",
() -> injector.getInstance(QueryResource.class));
register(environment, injector.getInstance(ServiceDiscoverer.class));
register(environment, injector.getInstance(ServiceDiscoveryRegistrar.class));
StatisticsFlatMappingService statisticsFlatMappingService = injector.getInstance(StatisticsFlatMappingService.class);
register(environment, statisticsFlatMappingService);
//
StatisticsAggregationService statisticsAggregationService = injector.getInstance(StatisticsAggregationService.class);
register(environment, statisticsAggregationService);
register(environment, LogLevelInspector.INSTANCE);
register(environment, injector.getInstance(StroomPropertyServiceHealthCheck.class));
register(environment, injector.getInstance(HBaseConnection.class));
}
示例14: run
import io.dropwizard.setup.Environment; //导入依赖的package包/类
@Override
public void run(RiaBotServiceConfiguration riaBotServiceConfiguration, Environment environment) throws Exception {
//Start the job scheduler
JobManager.getInstance().startScheduler();
/*
* Register resources with jersey.
*/
final RiaResource chatResource = new RiaResource();
/*
* Setup jersey environment.
*/
environment.jersey().setUrlPattern(EndpointUtils.ENDPOINT_ROOT + "/*");
environment.jersey().register(chatResource);
log.info("Done with all initializations for user service");
}
示例15: build
import io.dropwizard.setup.Environment; //导入依赖的package包/类
public DBClient build(Environment environment) {
String dbServer = System.getenv("DB");
if (dbServer != null) {
server = dbServer;
}
dbClient = dbFactory.create(server, port, dbName);
log.info("Connected to db");
environment.lifecycle().manage(new Managed() {
@Override
public void start() throws Exception {
dbClient.useDB(dbName);
}
@Override
public void stop() throws Exception {
dbClient.close();
}
});
return dbClient;
}