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

CompletableFuture<Void> sendMessagesAsync(QueueClient sendClient) {
    List<HashMap<String, String>> data = GSON.fromJson("[" + "{'name' = 'Einstein', 'firstName' = 'Albert'},"
            + "{'name' = 'Heisenberg', 'firstName' = 'Werner'}," + "{'name' = 'Curie', 'firstName' = 'Marie'},"
            + "{'name' = 'Hawking', 'firstName' = 'Steven'}," + "{'name' = 'Newton', 'firstName' = 'Isaac'},"
            + "{'name' = 'Bohr', 'firstName' = 'Niels'}," + "{'name' = 'Faraday', 'firstName' = 'Michael'},"
            + "{'name' = 'Galilei', 'firstName' = 'Galileo'},"
            + "{'name' = 'Kepler', 'firstName' = 'Johannes'},"
            + "{'name' = 'Kopernikus', 'firstName' = 'Nikolaus'}" + "]",
            new TypeToken<List<HashMap<String, String>>>() {
            }.getType());//from  w w w . j  av  a2  s .  c o m

    List<CompletableFuture> tasks = new ArrayList<>();
    for (int i = 0; i < data.size(); i++) {
        final String messageId = Integer.toString(i);
        Message message = new Message(GSON.toJson(data.get(i), Map.class).getBytes(UTF_8));
        message.setContentType("application/json");
        message.setLabel("Scientist");
        message.setMessageId(messageId);
        message.setTimeToLive(Duration.ofMinutes(2));
        System.out.printf("\nMessage sending: Id = %s", message.getMessageId());
        tasks.add(sendClient.sendAsync(message).thenRunAsync(() -> {
            System.out.printf("\n\tMessage acknowledged: Id = %s", message.getMessageId());
        }));
    }
    return CompletableFuture.allOf(tasks.toArray(new CompletableFuture<?>[tasks.size()]));
}

From source file:de.lgblaumeiser.ptm.analysis.analyzer.HourComputer.java

private Duration calculateOvertime(final Duration worktime, final LocalDate day) {
    Duration minutes = worktime;//from w ww .ja va 2 s .  c om
    if (isWeekDay(day)) {
        minutes = minutes.minus(Duration.ofMinutes(480)); // Overtime is time after 8 hours
    }
    return minutes;
}

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

CompletableFuture<Void> sendMessagesAsync(IMessageSender sendClient, int maxMessages) {
    List<HashMap<String, String>> data = GSON.fromJson("[" + "{'name' = 'Einstein', 'firstName' = 'Albert'},"
            + "{'name' = 'Heisenberg', 'firstName' = 'Werner'}," + "{'name' = 'Curie', 'firstName' = 'Marie'},"
            + "{'name' = 'Hawking', 'firstName' = 'Steven'}," + "{'name' = 'Newton', 'firstName' = 'Isaac'},"
            + "{'name' = 'Bohr', 'firstName' = 'Niels'}," + "{'name' = 'Faraday', 'firstName' = 'Michael'},"
            + "{'name' = 'Galilei', 'firstName' = 'Galileo'},"
            + "{'name' = 'Kepler', 'firstName' = 'Johannes'},"
            + "{'name' = 'Kopernikus', 'firstName' = 'Nikolaus'}" + "]",
            new TypeToken<List<HashMap<String, String>>>() {
            }.getType());/*from www .j  a v a  2s.  c  o  m*/

    List<CompletableFuture> tasks = new ArrayList<>();
    for (int i = 0; i < Math.min(data.size(), maxMessages); i++) {
        final String messageId = Integer.toString(i);
        Message message = new Message(GSON.toJson(data.get(i), Map.class).getBytes(UTF_8));
        message.setContentType("application/json");
        message.setLabel(i % 2 == 0 ? "Scientist" : "Physicist");
        message.setMessageId(messageId);
        message.setTimeToLive(Duration.ofMinutes(2));
        System.out.printf("Message sending: Id = %s\n", message.getMessageId());
        tasks.add(sendClient.sendAsync(message).thenRunAsync(() -> {
            System.out.printf("\tMessage acknowledged: Id = %s\n", message.getMessageId());
        }));
    }
    return CompletableFuture.allOf(tasks.toArray(new CompletableFuture<?>[tasks.size()]));
}

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

CompletableFuture<Void> sendMessagesAsync(TopicClient sendClient) {
    List<HashMap<String, String>> data = GSON.fromJson("[" + "{'name' = 'Einstein', 'firstName' = 'Albert'},"
            + "{'name' = 'Heisenberg', 'firstName' = 'Werner'}," + "{'name' = 'Curie', 'firstName' = 'Marie'},"
            + "{'name' = 'Hawking', 'firstName' = 'Steven'}," + "{'name' = 'Newton', 'firstName' = 'Isaac'},"
            + "{'name' = 'Bohr', 'firstName' = 'Niels'}," + "{'name' = 'Faraday', 'firstName' = 'Michael'},"
            + "{'name' = 'Galilei', 'firstName' = 'Galileo'},"
            + "{'name' = 'Kepler', 'firstName' = 'Johannes'},"
            + "{'name' = 'Kopernikus', 'firstName' = 'Nikolaus'}" + "]",
            new TypeToken<List<HashMap<String, String>>>() {
            }.getType());/* ww w. jav  a  2s  .  co m*/

    List<CompletableFuture> tasks = new ArrayList<>();
    for (int i = 0; i < data.size(); i++) {
        final String messageId = Integer.toString(i);
        Message message = new Message(GSON.toJson(data.get(i), Map.class).getBytes(UTF_8));
        message.setContentType("application/json");
        message.setLabel("Scientist");
        message.setMessageId(messageId);
        message.setTimeToLive(Duration.ofMinutes(2));
        System.out.printf("Message sending: Id = %s\n", message.getMessageId());
        tasks.add(sendClient.sendAsync(message).thenRunAsync(() -> {
            System.out.printf("\tMessage acknowledged: Id = %s\n", message.getMessageId());
        }));
    }
    return CompletableFuture.allOf(tasks.toArray(new CompletableFuture<?>[tasks.size()]));
}

From source file:io.pravega.segmentstore.server.host.stat.AutoScaleProcessorTest.java

@Test(timeout = 10000)
public void scaleTest() {
    CompletableFuture<Void> result = new CompletableFuture<>();
    CompletableFuture<Void> result2 = new CompletableFuture<>();
    CompletableFuture<Void> result3 = new CompletableFuture<>();
    EventStreamWriter<AutoScaleEvent> writer = createWriter(event -> {
        if (event.getScope().equals(SCOPE) && event.getStream().equals(STREAM1)
                && event.getDirection() == AutoScaleEvent.UP) {
            result.complete(null);//from w w  w  . j a  va 2s  .co  m
        }

        if (event.getScope().equals(SCOPE) && event.getStream().equals(STREAM2)
                && event.getDirection() == AutoScaleEvent.DOWN) {
            result2.complete(null);
        }

        if (event.getScope().equals(SCOPE) && event.getStream().equals(STREAM3)
                && event.getDirection() == AutoScaleEvent.DOWN) {
            result3.complete(null);
        }
    });

    AutoScaleProcessor monitor = new AutoScaleProcessor(writer,
            AutoScalerConfig.builder().with(AutoScalerConfig.MUTE_IN_SECONDS, 0)
                    .with(AutoScalerConfig.COOLDOWN_IN_SECONDS, 0)
                    .with(AutoScalerConfig.CACHE_CLEANUP_IN_SECONDS, 1)
                    .with(AutoScalerConfig.CACHE_EXPIRY_IN_SECONDS, 1).build(),
            executor, maintenanceExecutor);

    String streamSegmentName1 = Segment.getScopedName(SCOPE, STREAM1, 0);
    String streamSegmentName2 = Segment.getScopedName(SCOPE, STREAM2, 0);
    String streamSegmentName3 = Segment.getScopedName(SCOPE, STREAM3, 0);
    monitor.notifyCreated(streamSegmentName1, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, 10);
    monitor.notifyCreated(streamSegmentName2, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, 10);
    monitor.notifyCreated(streamSegmentName3, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, 10);

    long twentyminutesback = System.currentTimeMillis() - Duration.ofMinutes(20).toMillis();
    monitor.put(streamSegmentName1, new ImmutablePair<>(twentyminutesback, twentyminutesback));
    monitor.put(streamSegmentName3, new ImmutablePair<>(twentyminutesback, twentyminutesback));

    monitor.report(streamSegmentName1, 10, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, twentyminutesback,
            1001, 500, 200, 200);

    monitor.report(streamSegmentName3, 10, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, twentyminutesback, 0.0,
            0.0, 0.0, 0.0);

    monitor.notifySealed(streamSegmentName1);
    assertTrue(FutureHelpers.await(result));
    assertTrue(FutureHelpers.await(result));
    assertTrue(FutureHelpers.await(result3));
}

From source file:io.pravega.service.server.host.stat.AutoScaleProcessorTest.java

@Test(timeout = 10000)
public void scaleTest() {
    CompletableFuture<Void> result = new CompletableFuture<>();
    CompletableFuture<Void> result2 = new CompletableFuture<>();
    CompletableFuture<Void> result3 = new CompletableFuture<>();
    EventStreamWriter<ScaleEvent> writer = createWriter(event -> {
        if (event.getScope().equals(SCOPE) && event.getStream().equals(STREAM1)
                && event.getDirection() == ScaleEvent.UP) {
            result.complete(null);/*from   ww  w.  j  a v  a2s .c  o  m*/
        }

        if (event.getScope().equals(SCOPE) && event.getStream().equals(STREAM2)
                && event.getDirection() == ScaleEvent.DOWN) {
            result2.complete(null);
        }

        if (event.getScope().equals(SCOPE) && event.getStream().equals(STREAM3)
                && event.getDirection() == ScaleEvent.DOWN) {
            result3.complete(null);
        }
    });

    AutoScaleProcessor monitor = new AutoScaleProcessor(writer,
            AutoScalerConfig.builder().with(AutoScalerConfig.MUTE_IN_SECONDS, 0)
                    .with(AutoScalerConfig.COOLDOWN_IN_SECONDS, 0)
                    .with(AutoScalerConfig.CACHE_CLEANUP_IN_SECONDS, 1)
                    .with(AutoScalerConfig.CACHE_EXPIRY_IN_SECONDS, 1).build(),
            executor, maintenanceExecutor);

    String streamSegmentName1 = Segment.getScopedName(SCOPE, STREAM1, 0);
    String streamSegmentName2 = Segment.getScopedName(SCOPE, STREAM2, 0);
    String streamSegmentName3 = Segment.getScopedName(SCOPE, STREAM3, 0);
    monitor.notifyCreated(streamSegmentName1, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, 10);
    monitor.notifyCreated(streamSegmentName2, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, 10);
    monitor.notifyCreated(streamSegmentName3, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, 10);

    long twentyminutesback = System.currentTimeMillis() - Duration.ofMinutes(20).toMillis();
    monitor.put(streamSegmentName1, new ImmutablePair<>(twentyminutesback, twentyminutesback));
    monitor.put(streamSegmentName3, new ImmutablePair<>(twentyminutesback, twentyminutesback));

    monitor.report(streamSegmentName1, 10, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, twentyminutesback,
            1001, 500, 200, 200);

    monitor.report(streamSegmentName3, 10, WireCommands.CreateSegment.IN_EVENTS_PER_SEC, twentyminutesback, 0.0,
            0.0, 0.0, 0.0);

    monitor.notifySealed(streamSegmentName1);
    assertTrue(FutureHelpers.await(result));
    assertTrue(FutureHelpers.await(result));
    assertTrue(FutureHelpers.await(result3));
}

From source file:be.bittich.quote.service.impl.TokenServiceImpl.java

@Override
public Boolean verifyDate(SecurityToken token) {
    Long expiredTime = Long.parseLong(env.getProperty("token.life"));
    Instant now = now();/*  w  ww.  j  ava  2  s. c  om*/
    Instant expiration = Instant.ofEpochMilli(token.getKeyCreationTime()).plus(Duration.ofMinutes(expiredTime));
    boolean before = now.isBefore(expiration);

    return before;

}

From source file:com.microsoft.azure.servicebus.samples.managingentity.ManagingEntity.java

private void updateQueue(QueueDescription queueDescription) throws InterruptedException, ExecutionException {
    System.out.println("Before updated - MaxDeliveryCount:" + queueDescription.getMaxDeliveryCount()
            + "; LockDuration:" + queueDescription.getLockDuration().toString());

    // Updating the properties of the queue.
    queueDescription.setMaxDeliveryCount(15);
    queueDescription.setLockDuration(Duration.ofMinutes(5));

    // Performing the actual update
    QueueDescription updatQueueDescription = this.managementClient.updateQueueAsync(queueDescription).get();

    System.out.println("After updated - MaxDeliveryCount:" + updatQueueDescription.getMaxDeliveryCount()
            + "; LockDuration:" + updatQueueDescription.getLockDuration().toString());
}

From source file:com.microsoft.azure.servicebus.samples.partitionedqueues.PartitionedQueues.java

void registerMessageHandler(QueueClient 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\tMessage received: \n\t\t\t\t\t\tMessageId = %s, \n\t\t\t\t\t\tSequenceNumber = %08X, \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  w w  w .ja  v  a 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.microsoft.azure.servicebus.samples.scheduledmessages.ScheduledMessages.java

void initializeReceiver(QueueClient 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\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") : "");
            }// w  w  w .  j a v a2  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);

}