Example usage for java.time Duration ofSeconds

List of usage examples for java.time Duration ofSeconds

Introduction

In this page you can find the example usage for java.time Duration ofSeconds.

Prototype

public static Duration ofSeconds(long seconds) 

Source Link

Document

Obtains a Duration representing a number of seconds.

Usage

From source file:top.zhacker.ms.reactor.webflux.controllers.SseController.java

@GetMapping("/sse/event")
Flux<ServerSentEvent<String>> event() {
    return Flux.interval(Duration.ofSeconds(1))
            .map(l -> ServerSentEvent.builder("foo\nbar").comment("bar\nbaz").id(Long.toString(l)).build());
}

From source file:com.orange.cloud.servicebroker.filter.securitygroups.config.CloudfoundryClientConfig.java

@Bean
DefaultConnectionContext connectionContext(CloudFoundryClientSettings cloudFoundryClientSettings) {

    DefaultConnectionContext.Builder connectionContext = DefaultConnectionContext.builder()
            .apiHost(cloudFoundryClientSettings.getHost()).sslHandshakeTimeout(Duration.ofSeconds(30))
            .skipSslValidation(cloudFoundryClientSettings.getSkipSslValidation());

    if (StringUtils.hasText(cloudFoundryClientSettings.getProxyHost())) {
        ProxyConfiguration.Builder proxyConfiguration = ProxyConfiguration.builder()
                .host(cloudFoundryClientSettings.getProxyHost())
                .port(cloudFoundryClientSettings.getProxyPort());

        if (StringUtils.hasText(cloudFoundryClientSettings.getProxyUsername())) {
            proxyConfiguration.password(cloudFoundryClientSettings.getProxyPassword())
                    .username(cloudFoundryClientSettings.getProxyUsername());
        }/*from   w  w  w . ja v a  2 s  .c o m*/

        connectionContext.proxyConfiguration(proxyConfiguration.build());
    }
    return connectionContext.build();
}

From source file:reactor.ipc.netty.http.client.PostAndGetTests.java

private void setupServer() throws InterruptedException {
    httpServer = HttpServer.create(0).newRouter(routes -> {
        routes.get("/get/{name}", getHandler()).post("/post", postHandler());
    }).block(Duration.ofSeconds(30));
}

From source file:org.kordamp.javatrove.example05.controller.AppController.java

public void load() {
    Flux<Repository> flux = github.repositories(model.getOrganization());
    if (model.getLimit() > 0) {
        flux = flux.take(model.getLimit());
    }/*from w  ww  . jav  a2s .c  om*/

    model.setCancellation(flux.timeout(Duration.ofSeconds(10L))
            .doOnSubscribe(subscription -> model.setState(RUNNING)).doOnTerminate(() -> model.setState(READY))
            .doOnError(throwable -> eventBus.publishAsync(new ThrowableEvent(throwable)))
            .subscribeOn(Schedulers.parallel()).subscribe(model.getRepositories()::add));
}

From source file:com.twitter.heron.common.config.SystemConfigTest.java

@Test
public void testReadConfig() throws IOException {
    InputStream inputStream = getClass().getResourceAsStream(RESOURCE_LOC);
    if (inputStream == null) {
        throw new RuntimeException("Sample output file not found");
    }/*from w  w w.  ja  v  a 2 s . com*/
    File file = File.createTempFile("system_temp", "yaml");
    file.deleteOnExit();
    OutputStream outputStream = new FileOutputStream(file);
    IOUtils.copy(inputStream, outputStream);
    outputStream.close();
    SystemConfig systemConfig = SystemConfig.newBuilder(true).putAll(file.getAbsolutePath(), true).build();
    Assert.assertEquals("log-files", systemConfig.getHeronLoggingDirectory());
    Assert.assertEquals(ByteAmount.fromMegabytes(100), systemConfig.getHeronLoggingMaximumSize());
    Assert.assertEquals(5, systemConfig.getHeronLoggingMaximumFiles());
    Assert.assertEquals(Duration.ofSeconds(60), systemConfig.getHeronMetricsExportInterval());
}

From source file:org.springframework.cloud.stream.ExponentialMovingAverageProcessor.java

@StreamListener
@Output(Processor.OUTPUT)/*from  www  . ja  v  a 2  s  .  c  o  m*/
public Flux<GroupedMovingAverage> computeEWMA(@Input(Processor.INPUT) Flux<String> emitter) {
    return emitter.map(s -> {
        JsonNode payload = null;
        try {
            payload = mapper.readTree(s);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return payload;
    }).window(Duration.ofSeconds(properties.getWindow()))
            .flatMap(w -> w.groupBy(jsonNode -> jsonNode.get(properties.getGroupKey()).asText())
                    .flatMap(group -> group.reduce(new ExponentialMovingAverage(), (ewma, node) -> {
                        ewma.compute(node.get(properties.getFieldName()).asDouble());
                        return ewma;
                    }).map(ewma1 -> {
                        return new GroupedMovingAverage(group.key(), ewma1.getCurrentValue());
                    })));
}

From source file:org.springframework.boot.webservices.client.HttpWebServiceMessageSenderBuilderTests.java

@Test
public void buildWithReadAndConnectTimeout() {
    ClientHttpRequestMessageSender messageSender = build(
            new HttpWebServiceMessageSenderBuilder().requestFactory(SimpleClientHttpRequestFactory::new)
                    .setConnectTimeout(Duration.ofSeconds(5)).setReadTimeout(Duration.ofSeconds(2)));
    SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) messageSender
            .getRequestFactory();//from   www. j a va2s.  c  o m
    assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 5000);
    assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 2000);
}

From source file:com.microsoft.azure.servicebus.samples.duplicatedetection.DuplicateDetection.java

void receive(String connectionString) throws Exception {
    IMessageReceiver receiver = ClientFactory.createMessageReceiverFromConnectionStringBuilder(
            new ConnectionStringBuilder(connectionString, "DupdetectQueue"), ReceiveMode.PEEKLOCK);

    // receive messages from queue
    String receivedMessageId = "";

    System.out.printf("\n\tWaiting up to 5 seconds for messages from %s ...\n", receiver.getEntityPath());
    while (true) {
        IMessage receivedMessage = receiver.receive(Duration.ofSeconds(5));

        if (receivedMessage == null) {
            break;
        }/*w  ww. j  a  v a2s  .  co  m*/
        System.out.printf("\t<= Received a message with messageId %s\n", receivedMessage.getMessageId());
        receiver.complete(receivedMessage.getLockToken());
        if (receivedMessageId.contentEquals(receivedMessage.getMessageId())) {
            throw new Exception("Received a duplicate message!");
        }
        receivedMessageId = receivedMessage.getMessageId();
    }
    System.out.printf("\tDone receiving messages from %s\n", receiver.getEntityPath());

    receiver.close();
}

From source file:se.curity.examples.oauth.jwt.JwkManager.java

public JwkManager(URI jwksUri, long minKidReloadTimeInSeconds, HttpClient httpClient) {
    this._jwksUri = jwksUri;
    _jsonWebKeyByKID = new TimeBasedCache<>(Duration.ofSeconds(minKidReloadTimeInSeconds), this::reload);
    _httpClient = httpClient;/*from  www.  ja v  a 2  s  .c  o m*/

    // invalidate the cache periodically to avoid stale state
    _executor.scheduleAtFixedRate(this::ensureCacheIsFresh, 5, 15, TimeUnit.MINUTES);
}

From source file:de.codecentric.boot.admin.server.web.client.InstanceWebClientTest.java

@BeforeClass
public static void setUp() {
    StepVerifier.setDefaultTimeout(Duration.ofSeconds(5));
}