Example usage for java.time Duration ofMinutes

List of usage examples for java.time Duration ofMinutes

Introduction

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

Prototype

public static Duration ofMinutes(long minutes) 

Source Link

Document

Obtains a Duration representing a number of standard minutes.

Usage

From source file:com.microsoft.azure.servicebus.samples.queuesgettingstarted.QueuesGettingStarted.java

void registerReceiver(QueueClient queueClient, ExecutorService executorService) throws Exception {

    // register the RegisterMessageHandler callback with executor service
    queueClient.registerMessageHandler(new IMessageHandler() {
        // callback invoked when the message handler loop has obtained a message
        public CompletableFuture<Void> onMessageAsync(IMessage message) {
            // receives message is passed to callback
            if (message.getLabel() != null && message.getContentType() != null
                    && message.getLabel().contentEquals("Scientist")
                    && message.getContentType().contentEquals("application/json")) {

                byte[] body = message.getBody();
                Map scientist = GSON.fromJson(new String(body, UTF_8), Map.class);

                System.out.printf(
                        "\n\t\t\t\tMessage received: \n\t\t\t\t\t\tMessageId = %s, \n\t\t\t\t\t\tSequenceNumber = %s, \n\t\t\t\t\t\tEnqueuedTimeUtc = %s,"
                                + "\n\t\t\t\t\t\tExpiresAtUtc = %s, \n\t\t\t\t\t\tContentType = \"%s\",  \n\t\t\t\t\t\tContent: [ firstName = %s, name = %s ]\n",
                        message.getMessageId(), message.getSequenceNumber(), message.getEnqueuedTimeUtc(),
                        message.getExpiresAtUtc(), message.getContentType(),
                        scientist != null ? scientist.get("firstName") : "",
                        scientist != null ? scientist.get("name") : "");
            }//from  ww w.  j  a  v  a 2 s  .  com
            return CompletableFuture.completedFuture(null);
        }

        // callback invoked when the message handler has an exception to report
        public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
            System.out.printf(exceptionPhase + "-" + throwable.getMessage());
        }
    },
            // 1 concurrent call, messages are auto-completed, auto-renew duration
            new MessageHandlerOptions(1, true, Duration.ofMinutes(1)), executorService);

}

From source file:com.google.maps.DistanceMatrixApiTest.java

@Test
public void testNewRequestWithAllPossibleParams() throws Exception {
    try (LocalTestServerContext sc = new LocalTestServerContext("{\"status\" : \"OK\"}")) {
        String[] origins = new String[] { "Perth, Australia", "Sydney, Australia", "Melbourne, Australia",
                "Adelaide, Australia", "Brisbane, Australia", "Darwin, Australia", "Hobart, Australia",
                "Canberra, Australia" };
        String[] destinations = new String[] { "Uluru, Australia", "Kakadu, Australia",
                "Blue Mountains, Australia", "Bungle Bungles, Australia", "The Pinnacles, Australia" };

        DistanceMatrixApi.newRequest(sc.context).origins(origins).destinations(destinations)
                .mode(TravelMode.DRIVING).language("en-AU").avoid(RouteRestriction.TOLLS).units(Unit.IMPERIAL)
                .departureTime(Instant.now().plus(Duration.ofMinutes(2))) // this is ignored when an API key is used
                .await();//from   w  w  w  .  ja va 2  s  .c o  m

        sc.assertParamValue(StringUtils.join(origins, "|"), "origins");
        sc.assertParamValue(StringUtils.join(destinations, "|"), "destinations");
        sc.assertParamValue(TravelMode.DRIVING.toUrlValue(), "mode");
        sc.assertParamValue("en-AU", "language");
        sc.assertParamValue(RouteRestriction.TOLLS.toUrlValue(), "avoid");
        sc.assertParamValue(Unit.IMPERIAL.toUrlValue(), "units");
    }
}

From source file:com.microsoft.azure.servicebus.samples.topicsgettingstarted.TopicsGettingStarted.java

void registerMessageHandlerOnClient(SubscriptionClient receiveClient, ExecutorService executorService)
        throws Exception {

    // register the RegisterMessageHandler callback
    receiveClient.registerMessageHandler(new IMessageHandler() {
        // callback invoked when the message handler loop has obtained a message
        public CompletableFuture<Void> onMessageAsync(IMessage message) {
            // receives message is passed to callback
            if (message.getLabel() != null && message.getContentType() != null
                    && message.getLabel().contentEquals("Scientist")
                    && message.getContentType().contentEquals("application/json")) {

                byte[] body = message.getBody();
                Map scientist = GSON.fromJson(new String(body, UTF_8), Map.class);

                System.out.printf(
                        "\n\t\t\t\t%s Message received: \n\t\t\t\t\t\tMessageId = %s, \n\t\t\t\t\t\tSequenceNumber = %s, \n\t\t\t\t\t\tEnqueuedTimeUtc = %s,"
                                + "\n\t\t\t\t\t\tExpiresAtUtc = %s, \n\t\t\t\t\t\tContentType = \"%s\",  \n\t\t\t\t\t\tContent: [ firstName = %s, name = %s ]\n",
                        receiveClient.getEntityPath(), message.getMessageId(), message.getSequenceNumber(),
                        message.getEnqueuedTimeUtc(), message.getExpiresAtUtc(), message.getContentType(),
                        scientist != null ? scientist.get("firstName") : "",
                        scientist != null ? scientist.get("name") : "");
            }//from w  ww. j a  va  2 s . c o  m
            return receiveClient.completeAsync(message.getLockToken());
        }

        // callback invoked when the message handler has an exception to report
        public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
            System.out.printf(exceptionPhase + "-" + throwable.getMessage());
        }
    },
            // 1 concurrent call, messages are auto-completed, auto-renew duration
            new MessageHandlerOptions(1, false, Duration.ofMinutes(1)), executorService);

}

From source file:com.orange.cloud.servicebroker.filter.core.filters.AbstractServiceBrokerFilterTest.java

@Test
public void push_service_broker_app() {
    final String applicationName = getApplicationName();
    final Map<String, String> environmentVariables = serviceBrokerAppEnvironmentVariables();
    givenSpace()//from   w  ww . j a  v a2  s  . c  om
            .then(pushThenStartServiceBrokerApp(this.cloudFoundryOperations, applicationName,
                    getApplicationPath(), domainTest, environmentVariables))
            .then(this.cloudFoundryOperations.applications()
                    .get(GetApplicationRequest.builder().name(applicationName).build()))
            .map(ApplicationDetail::getName).as(StepVerifier::create).expectNext(applicationName)
            .expectComplete().verify(Duration.ofMinutes(5));
}

From source file:com.orange.cloud.servicebroker.filter.core.filters.AbstractServiceBrokerFilterTest.java

@Test
public void create_service_broker() {

    final String applicationName = getApplicationName();
    final String brokerName = getBrokerName();
    final String applicationUrl = getAppUrl(applicationName, domainTest);
    final Map<String, String> environmentVariables = serviceBrokerAppEnvironmentVariables();

    givenSpace()/* www.  j a v a2s  .  c om*/
            .then(pushThenStartServiceBrokerApp(this.cloudFoundryOperations, applicationName,
                    getApplicationPath(), domainTest, environmentVariables))
            .then(createPrivateServiceBroker(this.cloudFoundryOperations, brokerName, brokerFilterUser,
                    brokerFilterPassword, applicationUrl))
            .thenMany(this.cloudFoundryOperations.serviceAdmin().list()).filter(hasServiceBroker(brokerName))
            .as(StepVerifier::create).expectNextCount(1).expectComplete().verify(Duration.ofMinutes(5));
}

From source file:gobblin.eventhub.writer.EventhubDataWriter.java

/**
 * A signature which contains the duration.
 * After the duration is expired, the signature becomes invalid
 *//*  w ww. jav  a  2s .  c o  m*/
public void refreshSignature() {
    if (postStartTimestamp == 0
            || (System.nanoTime() - postStartTimestamp) > Duration.ofMinutes(sigExpireInMinute).toNanos()) {
        // generate signature
        try {
            signature = SharedAccessSignatureTokenProvider.generateSharedAccessSignature(sasKeyName, sasKey,
                    namespaceName, Duration.ofMinutes(sigExpireInMinute));
            postStartTimestamp = System.nanoTime();
            LOG.info("Signature is refreshing: " + signature);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}

From source file:com.microsoft.azure.servicebus.samples.timetolive.TimeToLive.java

CompletableFuture pickUpAndFixDeadLetters(String connectionString, String queueName,
        IMessageSender resubmitSender, ExecutorService executorService) throws Exception {
    CompletableFuture running = new CompletableFuture();
    QueueClient receiver = new QueueClient(
            new ConnectionStringBuilder(connectionString, "BasicQueue/$deadletterqueue"), ReceiveMode.PEEKLOCK);

    running.whenComplete((r, t) -> {//from w ww.j  a va  2 s . c  om
        try {
            receiver.close();
        } catch (ServiceBusException e) {
            System.out.printf(e.getMessage());
        }
    });

    // register the RegisterMessageHandler callback
    receiver.registerMessageHandler(new IMessageHandler() {
        // callback invoked when the message handler loop has obtained a message
        public CompletableFuture<Void> onMessageAsync(IMessage message) {
            try {
                IMessage resubmitMessage = new Message(message.getBody());
                System.out.printf(
                        "\n\t\tFixing: \n\t\t\tMessageId = %s, \n\t\t\tSequenceNumber = %s, \n\t\t\tLabel = %s\n",
                        message.getMessageId(), message.getSequenceNumber(), message.getLabel());
                resubmitMessage.setMessageId(message.getMessageId());
                resubmitMessage.setLabel(message.getLabel());
                resubmitMessage.setContentType(message.getContentType());
                resubmitMessage.setTimeToLive(Duration.ofMinutes(2));

                resubmitSender.send(resubmitMessage);
                return receiver.completeAsync(message.getLockToken());
            } catch (Exception e) {
                CompletableFuture failure = new CompletableFuture();
                failure.completeExceptionally(e);
                return failure;
            }
        }

        // callback invoked when the message handler has an exception to report
        public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
            System.out.printf(exceptionPhase + "-" + throwable.getMessage());
        }
    },
            // 1 concurrent call, messages are auto-completed, auto-renew duration
            new MessageHandlerOptions(1, false, Duration.ofMinutes(1)), executorService);

    return running;
}

From source file:com.microsoft.azure.servicebus.samples.deadletterqueue.DeadletterQueue.java

CompletableFuture receiveMessagesAsync(String connectionString, String queueName,
        ExecutorService executorService) throws Exception {

    CompletableFuture running = new CompletableFuture();
    QueueClient receiver = new QueueClient(new ConnectionStringBuilder(connectionString, "BasicQueue"),
            ReceiveMode.PEEKLOCK);/*from   ww  w  . j  a  va  2s .c  o  m*/

    running.whenComplete((r, t) -> {
        try {
            receiver.close();
        } catch (ServiceBusException e) {
            System.out.printf(e.getMessage());
        }
    });

    // register the RegisterMessageHandler callback
    receiver.registerMessageHandler(new IMessageHandler() {
        // callback invoked when the message handler loop has obtained a message
        public CompletableFuture<Void> onMessageAsync(IMessage message) {
            // receives message is passed to callback
            if (message.getLabel() != null && message.getContentType() != null
                    && message.getLabel().contentEquals("Scientist")
                    && message.getContentType().contentEquals("application/json")) {

                byte[] body = message.getBody();
                Map scientist = GSON.fromJson(new String(body, UTF_8), Map.class);

                System.out.printf(
                        "\n\t\t\t\tMessage received: \n\t\t\t\t\t\tMessageId = %s, \n\t\t\t\t\t\tSequenceNumber = %s, \n\t\t\t\t\t\tEnqueuedTimeUtc = %s,"
                                + "\n\t\t\t\t\t\tExpiresAtUtc = %s, \n\t\t\t\t\t\tContentType = \"%s\",  \n\t\t\t\t\t\tContent: [ firstName = %s, name = %s ]\n",
                        message.getMessageId(), message.getSequenceNumber(), message.getEnqueuedTimeUtc(),
                        message.getExpiresAtUtc(), message.getContentType(),
                        scientist != null ? scientist.get("firstName") : "",
                        scientist != null ? scientist.get("name") : "");
            } else {
                return receiver.deadLetterAsync(message.getLockToken());
            }
            return receiver.completeAsync(message.getLockToken());
        }

        // callback invoked when the message handler has an exception to report
        public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
            System.out.printf(exceptionPhase + "-" + throwable.getMessage());
        }
    },
            // 1 concurrent call, messages are auto-completed, auto-renew duration
            new MessageHandlerOptions(1, false, Duration.ofMinutes(1)), executorService);

    return running;
}

From source file:com.orange.cloud.servicebroker.filter.core.filters.AbstractServiceBrokerFilterTest.java

@Test
public void service_offering() {

    final String applicationName = getApplicationName();
    final String brokerName = getBrokerName();
    final String applicationUrl = getAppUrl(applicationName, domainTest);
    final Map<String, String> environmentVariables = serviceBrokerAppEnvironmentVariables();

    givenSpace()/*  w w w . j av a 2  s . c o m*/
            .then(pushThenStartServiceBrokerApp(this.cloudFoundryOperations, applicationName,
                    getApplicationPath(), domainTest, environmentVariables))
            .then(createPrivateServiceBroker(this.cloudFoundryOperations, brokerName, brokerFilterUser,
                    brokerFilterPassword, applicationUrl))
            .thenMany(this.cloudFoundryOperations.services()
                    .listServiceOfferings(ListServiceOfferingsRequest.builder()
                            .serviceName(getFilteredServiceBrokerOffering()).build()))
            .filter(hasService(getFilteredServiceBrokerOffering())).as(StepVerifier::create).expectNextCount(1)
            .expectComplete().verify(Duration.ofMinutes(5));
}

From source file:com.microsoft.azure.servicebus.samples.deadletterqueue.DeadletterQueue.java

CompletableFuture PickUpAndFixDeadletters(String connectionString, String queueName,
        IMessageSender resubmitSender, ExecutorService executorService) throws Exception {
    CompletableFuture running = new CompletableFuture();
    QueueClient receiver = new QueueClient(
            new ConnectionStringBuilder(connectionString, "BasicQueue/$deadletterqueue"), ReceiveMode.PEEKLOCK);

    running.whenComplete((r, t) -> {// www  .j  ava 2 s  .  co m
        try {
            receiver.close();
        } catch (ServiceBusException e) {
            System.out.printf(e.getMessage());
        }
    });

    // register the RegisterMessageHandler callback
    receiver.registerMessageHandler(new IMessageHandler() {
        // callback invoked when the message handler loop has obtained a message
        public CompletableFuture<Void> onMessageAsync(IMessage message) {
            try {
                IMessage resubmitMessage = new Message(message.getBody());
                if (message.getLabel() != null && message.getLabel().contentEquals("Physicist")) {
                    System.out.printf(
                            "\n\t\tFixing: \n\t\t\tMessageId = %s, \n\t\t\tSequenceNumber = %s, \n\t\t\tLabel = %s\n",
                            message.getMessageId(), message.getSequenceNumber(), message.getLabel());
                    resubmitMessage.setMessageId(message.getMessageId());
                    resubmitMessage.setLabel("Scientist");
                    resubmitMessage.setContentType(message.getContentType());
                    resubmitMessage.setTimeToLive(Duration.ofMinutes(2));
                    resubmitSender.send(resubmitMessage);
                }
                return receiver.completeAsync(message.getLockToken());
            } catch (Exception e) {
                CompletableFuture failure = new CompletableFuture();
                failure.completeExceptionally(e);
                return failure;
            }
        }

        // callback invoked when the message handler has an exception to report
        public void notifyException(Throwable throwable, ExceptionPhase exceptionPhase) {
            System.out.printf(exceptionPhase + "-" + throwable.getMessage());
        }
    },
            // 1 concurrent call, messages are auto-completed, auto-renew duration
            new MessageHandlerOptions(1, false, Duration.ofMinutes(1)), executorService);

    return running;
}