List of usage examples for java.time Duration ofMillis
public static Duration ofMillis(long millis)
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.ofMillis(10); System.out.println(duration); }
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.ofDays(33); //seconds or nanos Duration duration1 = Duration.ofHours(33); //seconds or nanos Duration duration2 = Duration.ofMillis(33); //seconds or nanos Duration duration3 = Duration.ofMinutes(33); //seconds or nanos Duration duration4 = Duration.ofNanos(33); //seconds or nanos Duration duration5 = Duration.ofSeconds(33); //seconds or nanos Duration duration6 = Duration.between(LocalDate.of(2012, 11, 11), LocalDate.of(2013, 1, 1)); System.out.println(duration6.getSeconds()); System.out.println(duration.getNano()); System.out.println(duration.getSeconds()); }
From source file:org.springframework.cloud.stream.FluxTest.java
@Before public void setup() { emitter = Flux.interval(Duration.ofMillis(100)).map(tick -> { return Quote.random(); }).map(quote -> {//w w w .j a v a 2 s. com String payload = null; try { payload = mapper.writeValueAsString(quote); } catch (JsonProcessingException e) { e.printStackTrace(); } return payload; }); }
From source file:com.netflix.spinnaker.igor.config.LockManagerConfig.java
@Bean LockService lockService(final LockManager lockManager) { Duration lockMaxDuration = null; if (lockManagerConfigProperties.getMaximumLockDurationMillis() != null) { lockMaxDuration = Duration.ofMillis(lockManagerConfigProperties.getMaximumLockDurationMillis()); }/*from w w w . j ava 2 s .com*/ return new LockService(lockManager, lockMaxDuration); }
From source file:ch.cyberduck.core.dropbox.DropboxExceptionMappingService.java
@Override public BackgroundException map(final DbxException failure) { final StringBuilder buffer = new StringBuilder(); this.parse(buffer, failure.getMessage()); if (failure instanceof InvalidAccessTokenException) { return new LoginFailureException(buffer.toString(), failure); }/*w w w . jav a 2 s. c om*/ if (failure instanceof RetryException) { final Duration delay = Duration.ofMillis(((RetryException) failure).getBackoffMillis()); return new RetriableAccessDeniedException(buffer.toString(), delay); } if (failure instanceof ServerException) { return new ConnectionRefusedException(buffer.toString(), failure); } if (failure instanceof GetMetadataErrorException) { final GetMetadataError error = ((GetMetadataErrorException) failure).errorValue; final LookupError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); case NOT_FOUND: case NOT_FILE: case NOT_FOLDER: return new NotfoundException(buffer.toString(), failure); case RESTRICTED_CONTENT: return new AccessDeniedException(buffer.toString(), failure); } } if (failure instanceof DeleteErrorException) { final DeleteError error = ((DeleteErrorException) failure).errorValue; final LookupError lookup = error.getPathLookupValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); case NOT_FOUND: case NOT_FILE: case NOT_FOLDER: return new NotfoundException(buffer.toString(), failure); case RESTRICTED_CONTENT: return new AccessDeniedException(buffer.toString(), failure); } } if (failure instanceof ListFolderErrorException) { final ListFolderError error = ((ListFolderErrorException) failure).errorValue; final LookupError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case INVALID_PATH_ROOT: return new NotfoundException(buffer.toString(), failure); case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); case NOT_FOUND: case NOT_FILE: case NOT_FOLDER: return new NotfoundException(buffer.toString(), failure); case RESTRICTED_CONTENT: return new AccessDeniedException(buffer.toString(), failure); } } if (failure instanceof CreateFolderErrorException) { final CreateFolderError error = ((CreateFolderErrorException) failure).errorValue; final WriteError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); case DISALLOWED_NAME: case NO_WRITE_PERMISSION: case CONFLICT: return new AccessDeniedException(buffer.toString(), failure); case INSUFFICIENT_SPACE: return new QuotaException(buffer.toString(), failure); } } if (failure instanceof SearchErrorException) { final SearchError error = ((SearchErrorException) failure).errorValue; final LookupError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case INVALID_PATH_ROOT: case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); case NOT_FOUND: case NOT_FILE: case NOT_FOLDER: return new NotfoundException(buffer.toString(), failure); case RESTRICTED_CONTENT: return new AccessDeniedException(buffer.toString(), failure); } } if (failure instanceof DownloadErrorException) { final DownloadError error = ((DownloadErrorException) failure).errorValue; final LookupError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); case NOT_FOUND: case NOT_FILE: case NOT_FOLDER: return new NotfoundException(buffer.toString(), failure); case RESTRICTED_CONTENT: return new AccessDeniedException(buffer.toString(), failure); } } if (failure instanceof UploadErrorException) { final UploadError error = ((UploadErrorException) failure).errorValue; final UploadWriteFailed lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.getReason().tag()) { case CONFLICT: case NO_WRITE_PERMISSION: case DISALLOWED_NAME: return new AccessDeniedException(buffer.toString(), failure); case INSUFFICIENT_SPACE: return new QuotaException(buffer.toString(), failure); case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); } } if (failure instanceof UploadSessionFinishErrorException) { final UploadSessionFinishError error = ((UploadSessionFinishErrorException) failure).errorValue; final WriteError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); case DISALLOWED_NAME: case NO_WRITE_PERMISSION: case CONFLICT: return new AccessDeniedException(buffer.toString(), failure); case INSUFFICIENT_SPACE: return new QuotaException(buffer.toString(), failure); } } if (failure instanceof GetTemporaryLinkErrorException) { final GetTemporaryLinkError error = ((GetTemporaryLinkErrorException) failure).errorValue; final LookupError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case NOT_FOUND: case NOT_FILE: case NOT_FOLDER: return new NotfoundException(buffer.toString(), failure); case RESTRICTED_CONTENT: return new AccessDeniedException(buffer.toString(), failure); case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); } } if (failure instanceof ListFolderContinueErrorException) { final ListFolderContinueError error = ((ListFolderContinueErrorException) failure).errorValue; final LookupError lookup = error.getPathValue(); this.parse(buffer, lookup.toString()); switch (lookup.tag()) { case NOT_FOUND: case NOT_FILE: case NOT_FOLDER: return new NotfoundException(buffer.toString(), failure); case RESTRICTED_CONTENT: return new AccessDeniedException(buffer.toString(), failure); case MALFORMED_PATH: case OTHER: return new InteroperabilityException(buffer.toString(), failure); } } return new InteroperabilityException(buffer.toString(), failure); }
From source file:org.springframework.cloud.stream.FluxTest.java
@Test public void testGroupBy() throws Exception { final Map<String, Map<String, Double>> averages = new HashMap<>(); Cancellation cancellation = emitter.map(s -> { Quote payload = null;/*from w w w . j a v a 2 s.c o m*/ try { payload = mapper.readValue(s, Quote.class); } catch (IOException e) { e.printStackTrace(); } return payload; }).groupBy(Quote::getSymbol).flatMap(grp -> { return grp.buffer(Duration.ofMillis(1000)); }).subscribe(maps -> { double totalBid = 0.0; double totalAsk = 0.0; for (Quote quote : maps) { totalAsk += quote.getAsk(); totalBid += quote.getBid(); } Map<String, Double> entry = new HashMap<String, Double>(); entry.put("ask", totalAsk / maps.size()); entry.put("bid", totalAsk / maps.size()); averages.put(maps.get(0).getSymbol() + "_" + System.currentTimeMillis(), entry); }); Thread.sleep(3000L); cancellation.dispose(); System.out.println(averages); }
From source file:com.opentable.jaxrs.JaxRsClientFactoryImpl.java
private void configureHttpEngine(String clientName, ResteasyClientBuilder clientBuilder, JaxRsClientConfig config) {//from w w w . j ava 2s.co m final HttpClientBuilder builder = HttpClientBuilder.create(); if (config.isEtcdHacksEnabled()) { builder.setRedirectStrategy(new ExtraLaxRedirectStrategy()) .addInterceptorFirst(new SwallowHeaderInterceptor(HttpHeaders.CONTENT_LENGTH)); } final MonitoredPoolingHttpClientConnectionManager connectionManager = new MonitoredPoolingHttpClientConnectionManager( clientName); connectionManager.setCheckoutWarnTime(Duration.ofMillis(config.connectionPoolWarnTime().getMillis())); connectionManager.setMaxTotal(config.connectionPoolSize()); connectionManager.setDefaultMaxPerRoute(config.httpClientDefaultMaxPerRoute()); final HttpClient client = builder .setDefaultSocketConfig( SocketConfig.custom().setSoTimeout((int) config.socketTimeout().getMillis()).build()) .setDefaultRequestConfig(customRequestConfig(config, RequestConfig.custom())) .setConnectionManager(connectionManager).build(); final ApacheHttpClient4Engine engine = new HackedApacheHttpClient4Engine(config, client); clientBuilder.httpEngine(engine); }
From source file:org.springframework.cloud.stream.binder.pubsub.BatchingPubSubMessageHandler.java
@Override public void start() { if (this.concurrency == null) { // We are assuming Brian Goetz (http://www.ibm.com/developerworks/java/library/j-jtp0730/index.html) cores * 1 + (1 + wait/service) and that http wait is taking 2x more than service this.concurrency = Runtime.getRuntime().availableProcessors() * 3; }/*www . j ava 2s . c om*/ this.processorCancellation = processor.groupBy(PubSubMessage::getTopic) .flatMap(group -> group.map(pubSubMessage -> { return pubSubMessage.getMessage(); }).buffer(producerProperties.getExtension().getBatchSize(), Duration.ofMillis(producerProperties.getExtension().getWindowSize())).map(messages -> { return new GroupedMessage(group.key(), messages); })) .parallel(concurrency).runOn(Schedulers.elastic()).doOnNext(groupedMessage -> { logger.info("Dispatching messages"); resourceManager.publishMessages(groupedMessage); }).sequential().publishOn(Schedulers.elastic()).subscribe(); running = true; }
From source file:org.ng200.openolympus.DurationJacksonModule.java
public DurationJacksonModule() { addSerializer(new JsonSerializer<Duration>() { @Override// w ww . ja va2 s . c om public void serialize(Duration duration, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { gen.writeNumber(duration.toMillis()); } @Override public Class<Duration> handledType() { return Duration.class; } }); addDeserializer(Duration.class, new JsonDeserializer<Duration>() { @Override public Duration deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { long l = jp.getValueAsLong(); return Duration.ofMillis(l); } @Override public Class<Duration> handledType() { return Duration.class; } }); }
From source file:org.springframework.cloud.stream.FluxTest.java
@Test public void testGroupByReduce() throws Exception { emitter.map(s -> {/*from w w w .j a v a 2 s .com*/ Quote payload = null; try { payload = mapper.readValue(s, Quote.class); } catch (IOException e) { e.printStackTrace(); } return payload; }).window(Duration.ofMillis(1000)).flatMap(w -> w.groupBy(Quote::getSymbol) .flatMap(group -> group.reduce(new ExponentialMovingAverage(), (ewma, quote) -> { ewma.compute(quote.getBid()); return ewma; }).map(ewma1 -> { return new GroupedMovingAverage(group.key(), ewma1.getCurrentValue()); }))).subscribe(System.out::println) ; Thread.sleep(3000L); }