本文整理匯總了Java中io.dropwizard.util.Duration類的典型用法代碼示例。如果您正苦於以下問題:Java Duration類的具體用法?Java Duration怎麽用?Java Duration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Duration類屬於io.dropwizard.util包,在下文中一共展示了Duration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNewSecureClient
import io.dropwizard.util.Duration; //導入依賴的package包/類
protected Client getNewSecureClient(String keyStoreResourcePath) throws Exception {
TlsConfiguration tlsConfiguration = new TlsConfiguration();
tlsConfiguration.setKeyStorePath(new File(resourceFilePath(keyStoreResourcePath)));
tlsConfiguration.setKeyStorePassword("notsecret");
tlsConfiguration.setTrustStorePath(new File(resourceFilePath("tls/test-truststore.jks")));
tlsConfiguration.setTrustStorePassword("notsecret");
tlsConfiguration.setVerifyHostname(false);
tlsConfiguration.setSupportedCiphers(Lists.newArrayList("TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"));
tlsConfiguration.setSupportedProtocols(Lists.newArrayList("TLSv1.2"));
JerseyClientConfiguration configuration = new JerseyClientConfiguration();
configuration.setTlsConfiguration(tlsConfiguration);
configuration.setTimeout(Duration.seconds(30));
configuration.setConnectionTimeout(Duration.seconds(30));
configuration.setConnectionRequestTimeout(Duration.seconds(30));
return new JerseyClientBuilder(USER_INFO_APP_RULE.getEnvironment())
.using(configuration)
.build(UUID.randomUUID().toString());
}
示例2: TestPolicyConfiguration
import io.dropwizard.util.Duration; //導入依賴的package包/類
private TestPolicyConfiguration(
JerseyClientConfiguration httpClient,
ServiceInfoConfiguration serviceInfo,
ClientTrustStoreConfiguration clientTrustStoreConfiguration,
Duration timeoutPeriod,
Duration matchingServiceResponseWaitPeriod,
Duration assertionLifetime) {
this.eventSinkUri = URI.create("http://event-sink");
this.samlEngineUri = URI.create("http://saml-engine");
this.samlSoapProxyUri = URI.create("http://saml-soap-proxy");
this.httpClient = httpClient;
this.serviceInfo = serviceInfo;
this.clientTrustStoreConfiguration = clientTrustStoreConfiguration;
this.timeoutPeriod = timeoutPeriod;
this.matchingServiceResponseWaitPeriod = matchingServiceResponseWaitPeriod;
this.assertionLifetime = assertionLifetime;
this.configUri = URI.create("http://config");
}
示例3: testSerialization
import io.dropwizard.util.Duration; //導入依賴的package包/類
@Test
public void testSerialization() throws IOException {
final String json =
"{" +
"\"type\": \"tcp\"," +
"\"host\": \"i am a host\"," +
"\"port\": \"12345\"," +
"\"timeout\": \"5 minutes\"" +
"}";
final ObjectMapper mapper = Jackson.newObjectMapper();
mapper.registerModule(new ParameterNamesModule(JsonCreator.Mode.PROPERTIES));
final Environment env = mock(Environment.class);
when(env.getObjectMapper()).thenReturn(mapper);
final InfluxDbTcpWriter.Factory factory = mapper.readValue(json, InfluxDbTcpWriter.Factory.class);
assertEquals("expected TCP host", "i am a host", factory.host());
assertEquals("expected TCP port", 12345, factory.port());
assertEquals("expected TCP timeout", Duration.minutes(5), factory.timeout());
}
示例4: getDefaultJerseyClientConfiguration
import io.dropwizard.util.Duration; //導入依賴的package包/類
public static JerseyClientConfiguration getDefaultJerseyClientConfiguration(boolean verifyHostname, boolean trustSelfSignedCertificates) {
JerseyClientConfiguration jerseyClientConfiguration = new JerseyClientConfiguration();
jerseyClientConfiguration.setTimeout(Duration.seconds(60));
jerseyClientConfiguration.setTimeToLive(Duration.minutes(10));
jerseyClientConfiguration.setCookiesEnabled(false);
jerseyClientConfiguration.setConnectionTimeout(Duration.seconds(4));
jerseyClientConfiguration.setRetries(3);
jerseyClientConfiguration.setKeepAlive(Duration.seconds(60));
jerseyClientConfiguration.setChunkedEncodingEnabled(false);
jerseyClientConfiguration.setValidateAfterInactivityPeriod(Duration.seconds(5));
TlsConfiguration tlsConfiguration = new TlsConfiguration();
tlsConfiguration.setProtocol("TLSv1.2");
tlsConfiguration.setVerifyHostname(verifyHostname);
tlsConfiguration.setTrustSelfSignedCertificates(trustSelfSignedCertificates);
jerseyClientConfiguration.setTlsConfiguration(tlsConfiguration);
jerseyClientConfiguration.setGzipEnabledForRequests(false);
return jerseyClientConfiguration;
}
開發者ID:alphagov,項目名稱:verify-matching-service-adapter,代碼行數:19,代碼來源:MatchingServiceAdapterConfiguration.java
示例5: build
import io.dropwizard.util.Duration; //導入依賴的package包/類
public Jdbi build(Environment environment,
PooledDataSourceFactory configuration,
String name) {
ManagedDataSource dataSource = configuration.build(environment.metrics(), name);
String validationQuery = configuration.getValidationQuery();
Jdbi jdbi = Jdbi.create(dataSource);
jdbi.setTimingCollector(new InstrumentedTimingCollector(environment.metrics(), nameStrategy));
jdbi.installPlugins();
environment.lifecycle().manage(dataSource);
environment.healthChecks().register(name, new JdbiHealthCheck(
environment.getHealthCheckExecutorService(),
configuration.getValidationQueryTimeout().orElseGet(() -> Duration.seconds(5)),
jdbi, validationQuery));
return jdbi;
}
示例6: defaultCleanupExecutor
import io.dropwizard.util.Duration; //導入依賴的package包/類
private static ExecutorService defaultCleanupExecutor(String metricsGroup, LifeCycleRegistry lifeCycle, MetricRegistry metricRegistry) {
final Meter meter = metricRegistry.meter(MetricRegistry.name(metricsGroup, "AstyanaxEventReaderDAO", "discarded_slab_cleanup"));
String nameFormat = "Events Slab Reader Cleanup-" + metricsGroup.substring(metricsGroup.lastIndexOf('.') + 1) + "-%d";
ExecutorService executor = new ThreadPoolExecutor(
NUM_CLEANUP_THREADS, NUM_CLEANUP_THREADS,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(MAX_CLEANUP_QUEUE_LENGTH),
new ThreadFactoryBuilder().setNameFormat(nameFormat).build(),
new ThreadPoolExecutor.DiscardPolicy() {
@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
meter.mark();
}
});
lifeCycle.manage(new ExecutorServiceManager(executor, Duration.seconds(5), nameFormat));
return executor;
}
示例7: execute
import io.dropwizard.util.Duration; //導入依賴的package包/類
@Override
public void execute(ImmutableMultimap<String, String> parameters, PrintWriter out) throws Exception {
boolean oldEnabled = _dedupEnabled.get();
boolean newEnabled = oldEnabled;
for (String value : parameters.get("dedup")) {
newEnabled = Boolean.parseBoolean(value);
_dedupEnabled.set(newEnabled);
}
out.printf("dedup-enabled: %s%n", newEnabled);
Collection<String> migrations = parameters.get("migrate");
if (!migrations.isEmpty()) {
if (newEnabled) {
out.println("Ignoring migrations since Databus dedup is still enabled.");
} else {
if (oldEnabled) {
out.println("Sleeping 15 seconds to allow in-flight requests to complete.");
out.flush();
Thread.sleep(Duration.seconds(15).toMilliseconds());
}
migrate(migrations, out);
}
}
}
示例8: DefaultRateLimitedLogFactory
import io.dropwizard.util.Duration; //導入依賴的package包/類
@VisibleForTesting
DefaultRateLimitedLogFactory(ScheduledExecutorService executor, Duration interval) {
_executor = checkNotNull(executor, "executor");
_interval = checkNotNull(interval, "interval");
// After the last access we (1) hold the error up to 30 seconds before reporting it, then (2) wait to see if
// any more instances of the error occur, after the (3) third 30-second interval of no more access we can be
// confident that we can safely stop tracking the error and expire it from the cache. Hence "interval * 3".
_cache = CacheBuilder.newBuilder()
.expireAfterAccess(interval.getQuantity() * 3, interval.getUnit())
.build(CacheLoader.from(Functions.<Message>identity()));
_executor.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
_cache.cleanUp();
}
}, 1, 1, TimeUnit.MINUTES);
}
示例9: testSingleError
import io.dropwizard.util.Duration; //導入依賴的package包/類
@Test
public void testSingleError() {
Logger log = mock(Logger.class);
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
RateLimitedLog rateLimitedLog =
new DefaultRateLimitedLogFactory(executor, Duration.days(1))
.from(log);
verify(executor).scheduleWithFixedDelay(Matchers.<Runnable>any(), eq(1L), eq(1L), eq(TimeUnit.MINUTES));
Throwable t = new Throwable();
rateLimitedLog.error(t, "Test error: {}", "first!");
verify(log).error("Test error: first!", t);
verify(executor).schedule(Matchers.<Runnable>any(), eq(1L), eq(TimeUnit.DAYS));
verifyNoMoreInteractions(log, executor);
}
示例10: overridePoolingOptions
import io.dropwizard.util.Duration; //導入依賴的package包/類
private static void overridePoolingOptions(CassandraFactory cassandraFactory) {
PoolingOptionsFactory newPoolingOptionsFactory = new PoolingOptionsFactory() {
@Override
public PoolingOptions build() {
if (null == getPoolTimeout()) {
setPoolTimeout(Duration.minutes(2));
}
return super.build().setMaxQueueSize(40960);
}
};
cassandraFactory.getPoolingOptions().ifPresent((originalPoolingOptions) -> {
newPoolingOptionsFactory.setHeartbeatInterval(originalPoolingOptions.getHeartbeatInterval());
newPoolingOptionsFactory.setIdleTimeout(originalPoolingOptions.getIdleTimeout());
newPoolingOptionsFactory.setLocal(originalPoolingOptions.getLocal());
newPoolingOptionsFactory.setRemote(originalPoolingOptions.getRemote());
newPoolingOptionsFactory.setPoolTimeout(originalPoolingOptions.getPoolTimeout());
});
cassandraFactory.setPoolingOptions(java.util.Optional.of(newPoolingOptionsFactory));
}
示例11: run
import io.dropwizard.util.Duration; //導入依賴的package包/類
@Override
public void run(AppConfiguration configuration, Environment environment) throws Exception {
configuration.getZipkinClient().setTimeout(Duration.seconds(50));
configuration.getZipkinClient().setConnectionRequestTimeout(Duration.seconds(50));
Brave brave = configuration.getZipkinFactory().build(environment).get();
final Client client = new ZipkinClientBuilder(environment, brave)
.build(configuration.getZipkinClient());
new MySQLStatementInterceptorManagementBean(brave.clientTracer());
/**
* Database
*/
createDatabase();
DatabaseUtils.executeDatabaseScript("init.sql");
UserDAO userDAO = new UserDAO();
// Register resources
environment.jersey().register(new HelloHandler());
environment.jersey().register(new SyncHandler(client));
environment.jersey().register(new AsyncHandler(client, brave));
environment.jersey().register(new UsersHandler(userDAO, client, brave));
}
示例12: testHttp2
import io.dropwizard.util.Duration; //導入依賴的package包/類
@Test
public void testHttp2() {
final JettyClientConfiguration conf = load("http2-client.yml");
assertThat(conf.getIdleTimeout()).isEqualTo(Duration.minutes(5));
assertThat(conf.getConnectionTimeout()).isEqualTo(Duration.seconds(1));
assertThat(conf.getConnectionFactoryBuilder())
.isInstanceOf(Http2ClientTransportFactory.class);
final Http2ClientTransportFactory http2 = (Http2ClientTransportFactory)
conf.getConnectionFactoryBuilder();
assertThat(http2.getKeyStorePath()).isEqualTo("client.jks");
assertThat(http2.getKeyStorePassword()).isEqualTo("http2_client");
assertThat(http2.getKeyStoreType()).isEqualTo("JKS");
assertThat(http2.getTrustStorePath()).isEqualTo("servers.jks");
assertThat(http2.getTrustStorePassword()).isEqualTo("http2_server");
assertThat(http2.getTrustStoreType()).isEqualTo("JKS");
assertThat(http2.getSupportedProtocols()).containsOnly("TLSv1.2");
assertThat(http2.getSupportedCipherSuites()).containsOnly("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256");
}
示例13: testHttps
import io.dropwizard.util.Duration; //導入依賴的package包/類
@Test
public void testHttps() {
final JettyClientConfiguration conf = load("https-client.yml");
assertThat(conf.getIdleTimeout()).isEqualTo(Duration.minutes(5));
assertThat(conf.getConnectionTimeout()).isEqualTo(Duration.seconds(1));
assertThat(conf.getConnectionFactoryBuilder())
.isInstanceOf(HttpsClientTransportFactory.class);
final HttpsClientTransportFactory https = (HttpsClientTransportFactory)
conf.getConnectionFactoryBuilder();
assertThat(https.getKeyStorePath()).isEqualTo("client.jks");
assertThat(https.getKeyStorePassword()).isEqualTo("http2_client");
assertThat(https.getKeyStoreType()).isEqualTo("JKS");
assertThat(https.getTrustStorePath()).isEqualTo("servers.jks");
assertThat(https.getTrustStorePassword()).isEqualTo("http2_server");
assertThat(https.getTrustStoreType()).isEqualTo("JKS");
assertThat(https.getSupportedProtocols()).containsOnly("TLSv1.2");
assertThat(https.getSupportedCipherSuites()).containsOnly("TLS_ECDHE.*");
}
示例14: run
import io.dropwizard.util.Duration; //導入依賴的package包/類
@Override
public final void run(T configuration, Environment environment) throws Exception {
final PooledDataSourceFactory dbConfig = getDataSourceFactory(configuration);
this.entityManagerFactory = entityManagerFactoryFactory.build(this, environment, dbConfig, entities, name());
this.entityManagerContext = new EntityManagerContext(entityManagerFactory);
this.sharedEntityManager = sharedEntityManagerFactory.build(entityManagerContext);
registerUnitOfWorkListerIfAbsent(environment).registerEntityManagerFactory(name(), entityManagerFactory);
environment.healthChecks().register(name(),
new EntityManagerFactoryHealthCheck(
environment.getHealthCheckExecutorService(),
dbConfig.getValidationQueryTimeout().orElse(Duration.seconds(5)),
entityManagerFactory,
dbConfig.getValidationQuery()));
}
示例15: build
import io.dropwizard.util.Duration; //導入依賴的package包/類
public AnalysisServiceClient build(Environment environment) {
final HttpClientConfiguration httpConfig = new HttpClientConfiguration();
httpConfig.setTimeout(Duration.milliseconds(getTimeout()));
final HttpClient httpClient = new HttpClientBuilder(environment).using(httpConfig)
.build("analysis-http-client");
AnalysisServiceClient client = new AnalysisServiceClientAdapter(getHost(), getPort(),
getPortFailover(), getPath(), httpClient);
environment.lifecycle().manage(new Managed() {
@Override
public void start() {
}
@Override
public void stop() {
}
});
return client;
}