List of usage examples for java.time Duration ofSeconds
public static Duration ofSeconds(long seconds)
From source file:com.github.robozonky.app.runtime.LivenessCheck.java
public static void setup(final MainControl mainThreadControl) { final Refreshable<String> liveness = new LivenessCheck(mainThreadControl); Tasks.SUPPORTING.scheduler().submit(liveness, Duration.ofSeconds(5)); liveness.run(); // for testing purposes, making sure the refresh was started }
From source file:top.zhacker.ms.reactor.webflux.controllers.EchoWebSocketHandler.java
@Override public Mono<Void> handle(WebSocketSession session) { // Use retain() for Reactor Netty return session .send(session.receive().doOnNext(WebSocketMessage::retain).delayElements(Duration.ofSeconds(2))); }
From source file:com.example.config.ApplicationBuilder.java
public static void start(ConfigurableApplicationContext context) { if (!hasListeners(context)) { ((DefaultListableBeanFactory) context.getBeanFactory()).registerDisposableBean(SHUTDOWN_LISTENER, new ShutdownApplicationListener()); new BeanCountingApplicationListener().log(context); logger.info(STARTUP);/*w w w . j av a2s . c o m*/ } HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build(); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); HttpServer httpServer = HttpServer.create().host("localhost") .port(context.getEnvironment().getProperty("server.port", Integer.class, 8080)).handle(adapter); httpServer.bindUntilJavaShutdown(Duration.ofSeconds(60), disposable -> disposable.dispose()); }
From source file:playground.SseController.java
@RequestMapping("/sse-raw") Flux<SseEvent> sse() {/*w w w. j ava 2s. co m*/ return Flux.interval(Duration.ofSeconds(1)).map(l -> { SseEvent event = new SseEvent(); event.setId(Long.toString(l)); event.setData("foo\nbar"); event.setComment("bar\nbaz"); return event; }); }
From source file:de.bytefish.fcmjava.client.http.apache.utils.RetryHeaderUtils.java
private static boolean tryGetFromLong(String retryDelayAsString, OutParameter<Duration> result) { // Try to convert the String to a Long: OutParameter<Long> longResult = new OutParameter<>(); if (!tryConvertToLong(retryDelayAsString, longResult)) { return false; }/*from w w w .j a va2 s .c om*/ // If we can convert it to Long, then convert to a Duration in seconds: Duration retryDelayAsDuration = Duration.ofSeconds(longResult.get()); // Set in the Out Parameter: result.set(retryDelayAsDuration); return true; }
From source file:de.bytefish.fcmjava.client.interceptors.response.utils.RetryHeaderUtils.java
private static boolean tryGetFromLong(String retryDelayAsString, OutParameter<Duration> result) { // Try to convert the String to a Long: OutParameter<Long> longResult = new OutParameter<Long>(); if (!tryConvertToLong(retryDelayAsString, longResult)) { return false; }//from w w w . j a va2 s . com // If we can convert it to Long, then convert to a Duration in seconds: Duration retryDelayAsDuration = Duration.ofSeconds(longResult.get()); // Set in the Out Parameter: result.set(retryDelayAsDuration); return true; }
From source file:top.zhacker.ms.reactor.webflux.controllers.SseController.java
@GetMapping("/sse/string") Flux<String> string() { return Flux.interval(Duration.ofSeconds(1)).map(l -> "foo " + l); }
From source file:com.microsoft.azure.servicebus.samples.autoforward.AutoForward.java
public void run(String connectionString) throws Exception { IMessageSender topicSender;/*from w ww. ja v a 2 s . c om*/ IMessageSender queueSender; IMessageReceiver targetQueueReceiver; System.out.printf("\nSending messages\n"); topicSender = ClientFactory.createMessageSenderFromConnectionStringBuilder( new ConnectionStringBuilder(connectionString, "AutoForwardSourceTopic")); topicSender.send(createMessage("M1")); queueSender = ClientFactory.createMessageSenderFromConnectionStringBuilder( new ConnectionStringBuilder(connectionString, "AutoForwardTargetQueue")); queueSender.send(createMessage("M2")); System.out.printf("\nReceiving messages\n"); targetQueueReceiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder( new ConnectionStringBuilder(connectionString, "AutoForwardTargetQueue"), ReceiveMode.PEEKLOCK); for (int i = 0; i < 2; i++) { IMessage message = targetQueueReceiver.receive(Duration.ofSeconds(10)); if (message != null) { this.printReceivedMessage(message); targetQueueReceiver.complete(message.getLockToken()); } else { throw new Exception("Expected message not receive\n"); } } targetQueueReceiver.close(); }
From source file:top.zhacker.ms.reactor.webflux.controllers.SseController.java
@GetMapping("/sse/person") Flux<Person> person() {/* ww w .jav a2s . c o m*/ return Flux.interval(Duration.ofSeconds(1)).map(l -> new Person(Long.toString(l), "foo", "bar")); }
From source file:io.pivotal.strepsirrhini.chaosloris.CloudFoundryClientHealthIndicator.java
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { requestGetInfo(this.cloudFoundryClient) .doOnSuccess(response -> builder.up().withDetail("apiVersion", response.getApiVersion())) .block(Duration.ofSeconds(10)); }