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


Java Configuration类代码示例

本文整理汇总了Java中io.dropwizard.Configuration的典型用法代码示例。如果您正苦于以下问题:Java Configuration类的具体用法?Java Configuration怎么用?Java Configuration使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: run

import io.dropwizard.Configuration; //导入依赖的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);
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:34,代码来源:WorkerServiceApplication.java

示例2: getTracer

import io.dropwizard.Configuration; //导入依赖的package包/类
private Tracer getTracer() {
  try {
    return new com.uber.jaeger.Configuration(
        getName(),
        new com.uber.jaeger.Configuration.SamplerConfiguration("const", 1),
        new com.uber.jaeger.Configuration.ReporterConfiguration(
            true,
            "tracing-jaeger-agent",
            6831,
            1000,   // flush interval in milliseconds
            10000)  /*max buffered Spans*/)
        .getTracer();
  } catch (Exception e) {
    e.printStackTrace();
    return NoopTracerFactory.create();
  }
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:18,代码来源:SearchServiceApplication.java

示例3: getTracer

import io.dropwizard.Configuration; //导入依赖的package包/类
private Tracer getTracer() {
  try {
    return new com.uber.jaeger.Configuration(
        getName(),
        new com.uber.jaeger.Configuration.SamplerConfiguration("const", 1), // 100%
        new com.uber.jaeger.Configuration.ReporterConfiguration(
            true,
            "tracing-jaeger-agent",
            6831,
            1000,   // flush interval in milliseconds
            10000)  /*max buffered Spans*/)
        .getTracer();
  } catch (Exception e) {
    e.printStackTrace();
    return NoopTracerFactory.create();
  }
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:18,代码来源:IndexerServiceApplication.java

示例4: run

import io.dropwizard.Configuration; //导入依赖的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");
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:20,代码来源:HelloWorldMonolithApp.java

示例5: run

import io.dropwizard.Configuration; //导入依赖的package包/类
public void run(Configuration configuration, Environment environment) {
  final CollectorRegistry collectorRegistry = new CollectorRegistry();
  collectorRegistry.register(new DropwizardExports(environment.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 String jdbcUrl = "jdbc:tracing:postgresql://tweets-db/postgres";
  final String jdbcUsername = "postgres";
  final String jdbcPassword = "example";
  final TweetsRepository tweetsRepository = new JooqPostgresTweetsRepository(jdbcUrl, jdbcUsername, jdbcPassword);
  final TweetsService tweetsService = new TweetsService(tweetsRepository);
  final TweetsResource tweetsResource = new TweetsResource(tweetsService);

  environment.jersey().register(tweetsResource);

  final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
  environment.jersey().register(tracing);

  environment.admin()
      .addServlet("metrics", new MetricsServlet(collectorRegistry))
      .addMapping("/metrics");
}
 
开发者ID:jeqo,项目名称:talk-observing-distributed-systems,代码行数:31,代码来源:TweetsServiceApplication.java

示例6: run

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override
public void run(final Configuration configuration,
                final Environment environment) {

    environment.jersey().register(new RateLimitingFactoryProvider.Binder(requestRateLimiterFactory));
    environment.jersey().register(new RateLimited429EnforcerFeature());

    environment.lifecycle().manage(new Managed() {
        @Override
        public void start() {
        }

        @Override
        public void stop() throws Exception {
            requestRateLimiterFactory.close();
        }
    });
}
 
开发者ID:mokies,项目名称:ratelimitj,代码行数:19,代码来源:RateLimitBundle.java

示例7: registersACustomNameOfHealthCheckAndDBPoolMetrics

import io.dropwizard.Configuration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void registersACustomNameOfHealthCheckAndDBPoolMetrics() throws Exception {
    final HibernateBundle<Configuration> customBundle = new HibernateBundle<Configuration>(entities, factory) {
        @Override
        public DataSourceFactory getDataSourceFactory(Configuration configuration) {
            return dbConfig;
        }

        @Override
        protected String name() {
            return "custom-hibernate";
        }
    };
    when(factory.build(eq(customBundle),
            any(Environment.class),
            any(DataSourceFactory.class),
            anyList(),
            eq("custom-hibernate"))).thenReturn(sessionFactory);

    customBundle.run(configuration, environment);

    final ArgumentCaptor<SessionFactoryHealthCheck> captor =
            ArgumentCaptor.forClass(SessionFactoryHealthCheck.class);
    verify(healthChecks).register(eq("custom-hibernate"), captor.capture());
}
 
开发者ID:mtakaki,项目名称:CredentialStorageService-dw-hibernate,代码行数:27,代码来源:HibernateBundleTest.java

示例8: run

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override
public void run(final T config, final Environment environment) throws Exception {
	Module bootstrapModule = new AbstractModule() {
		@Override
		protected void configure() {
			install(new DropwizardModule());
			if (mainModule != null)
				install(mainModule);

			bind(Configuration.class).toInstance(config);
			bind(configClass).toInstance(config);
			bind(Environment.class).toInstance(environment);
		}
	};

	environment.servlets() //
			.addFilter("guice-request-scope", new GuiceFilter()) //
			.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");

	Guice.createInjector(bootstrapModule).getInstance(applicationClass).run();
}
 
开发者ID:foxylion,项目名称:dropwizard-guice,代码行数:22,代码来源:GuiceBootstrap.java

示例9: configure

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override protected void configure() {
  // Initialize the BouncyCastle security provider for cryptography support.
  BouncyCastle.require();

  bind(Clock.class).toInstance(Clock.systemUTC());

  install(new CookieModule(config.getCookieKey()));
  install(new CryptoModule(config.getDerivationProviderClass(), config.getContentKeyStore()));

  bind(CookieConfig.class).annotatedWith(SessionCookie.class)
      .toInstance(config.getSessionCookieConfig());
  bind(CookieConfig.class).annotatedWith(Xsrf.class)
      .toInstance(config.getXsrfCookieConfig());

  // TODO(justin): Consider https://github.com/HubSpot/dropwizard-guice.
  bind(Environment.class).toInstance(environment);
  bind(Configuration.class).toInstance(config);
  bind(KeywhizConfig.class).toInstance(config);
}
 
开发者ID:square,项目名称:keywhiz,代码行数:20,代码来源:ServiceModule.java

示例10: initialize

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override
public void initialize(Bootstrap<?> bootstrap)
{
    final InjectableValues injectableValues = new InjectableValues()
    {
        @Override
        public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance)
        {
            return null;
        }
    };
    final ConfigurationFactoryFactory<? extends Configuration> configurationFactoryFactory = bootstrap.getConfigurationFactoryFactory();
    ConfigurationFactoryFactory factoryFactory = new ConfigurationFactoryFactory()
    {
        @Override
        public ConfigurationFactory create(Class klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
        {
            objectMapper.setInjectableValues(injectableValues);
            //noinspection unchecked
            return configurationFactoryFactory.create(klass, validator, objectMapper, propertyPrefix);
        }
    };
    //noinspection unchecked
    bootstrap.setConfigurationFactoryFactory(factoryFactory);
}
 
开发者ID:soabase,项目名称:soabase,代码行数:26,代码来源:GuiceBundle.java

示例11: build

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override
public DynamicAttributes build(Configuration configuration, Environment environment, List<String> scopes)
{
    SqlSession sqlSession = SoaBundle.getFeatures(environment).getNamedRequired(SqlSession.class, sessionName);

    final SqlDynamicAttributes dynamicAttributes = new SqlDynamicAttributes(sqlSession, scopes);
    ScheduledExecutorService service = environment.lifecycle().scheduledExecutorService("SqlDynamicAttributes-%d", true).build();
    Runnable command = new Runnable()
    {
        @Override
        public void run()
        {
            dynamicAttributes.update();
        }
    };
    service.scheduleAtFixedRate(command, refreshPeriodSeconds, refreshPeriodSeconds, TimeUnit.SECONDS);
    return dynamicAttributes;
}
 
开发者ID:soabase,项目名称:soabase,代码行数:19,代码来源:SqlDynamicAttributesFactory.java

示例12: build

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override
public DynamicAttributes build(Configuration configuration, Environment environment, List<String> scopes)
{
    DBI jdbi = SoaBundle.getFeatures(environment).getNamedRequired(DBI.class, name);

    final JdbiDynamicAttributes dynamicAttributes = new JdbiDynamicAttributes(jdbi, scopes);
    ScheduledExecutorService service = environment.lifecycle().scheduledExecutorService("JdbiDynamicAttributes-%d", true).build();
    Runnable command = new Runnable()
    {
        @Override
        public void run()
        {
            dynamicAttributes.update();
        }
    };
    service.scheduleAtFixedRate(command, refreshPeriodSeconds, refreshPeriodSeconds, TimeUnit.SECONDS);
    return dynamicAttributes;
}
 
开发者ID:soabase,项目名称:soabase,代码行数:19,代码来源:JdbiDynamicAttributesFactory.java

示例13: run

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override
public void run(Configuration configuration, Environment environment) throws Exception
{
    SoaConfiguration soaConfiguration = ComposedConfigurationAccessor.access(configuration, environment, SoaConfiguration.class);

    updateInstanceName(soaConfiguration);
    List<String> scopes = Lists.newArrayList();
    scopes.add(soaConfiguration.getInstanceName());
    scopes.add(soaConfiguration.getServiceName());
    scopes.addAll(soaConfiguration.getScopes());
    environment.getApplicationContext().setAttribute(DynamicAttributesBundle.Scopes.class.getName(), new Scopes(scopes));

    // attributes must be allocated first - Discovery et al might need them
    DynamicAttributes attributes = StandardAttributesContainer.wrapAttributes(SoaBundle.checkManaged(environment, soaConfiguration.getAttributesFactory().build(configuration, environment, scopes)), SoaBundle.hasAdminKey);
    environment.getApplicationContext().setAttribute(DynamicAttributes.class.getName(), attributes);
}
 
开发者ID:soabase,项目名称:soabase,代码行数:17,代码来源:DynamicAttributesBundle.java

示例14: internalRun

import io.dropwizard.Configuration; //导入依赖的package包/类
@Override
protected void internalRun(Configuration configuration, Environment environment)
{
    Metric metric = new Gauge<Integer>()
    {
        final Random random = new Random();

        @Override
        public Integer getValue()
        {
            return random.nextInt(100);
        }
    };
    environment.metrics().register("goodbye-random", metric);

    environment.jersey().register(GoodbyeResource.class);
    JerseyEnvironment adminJerseyEnvironment = SoaBundle.getFeatures(environment).getNamedRequired(JerseyEnvironment.class, SoaFeatures.ADMIN_NAME);
    adminJerseyEnvironment.register(GoodbyeAdminResource.class);
}
 
开发者ID:soabase,项目名称:soabase,代码行数:20,代码来源:GoodbyeApp.java

示例15: testFindEntityClassesFromDirectory

import io.dropwizard.Configuration; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testFindEntityClassesFromDirectory() {
    String packageWithEntities = "com.scottescue.dropwizard.entitymanager.entity.fake.entities.pckg";
    ScanningEntityManagerBundle bundle = new ScanningEntityManagerBundle(packageWithEntities) {
        @Override
        public void run(Object o, Environment environment) throws Exception {
        }

        @Override
        public PooledDataSourceFactory getDataSourceFactory(Configuration configuration) {
            return null;
        }
    };

    assertThat(bundle.getEntities()).containsOnly(
            FakeEntity1.class,
            DeepFakeEntity.class,
            DeeperFakeEntity.class);
}
 
开发者ID:scottescue,项目名称:dropwizard-entitymanager,代码行数:21,代码来源:ScanningEntityManagerBundleTest.java


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