當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。