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:Main.java

public static void main(String[] args) {
    Duration duration = Duration.ofMinutes(10);
    System.out.println(duration);
}

From source file:Main.java

public static void main(String[] args) {

    Duration d1 = Duration.ofDays(2);
    System.out.println(d1);/*from w w w.  j  a v  a2s.c  o  m*/

    Duration d2 = Duration.ofMinutes(2);
    System.out.println(d2);

}

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:com.microsoft.azure.servicebus.samples.duplicatedetection.DuplicateDetection.java

void send(String connectionString) throws Exception {
    IMessageSender sender = ClientFactory.createMessageSenderFromConnectionStringBuilder(
            new ConnectionStringBuilder(connectionString, "DupdetectQueue"));

    String messageId = UUID.randomUUID().toString();
    // Send messages to queue
    System.out.printf("\tSending messages to %s ...\n", sender.getEntityPath());
    IMessage message = new Message();
    message.setMessageId(messageId);// w  ww.j a v a 2 s. c  o m
    message.setTimeToLive(Duration.ofMinutes(1));
    sender.send(message);
    System.out.printf("\t=> Sent a message with messageId %s\n", message.getMessageId());

    IMessage message2 = new Message();
    message2.setMessageId(messageId);
    message2.setTimeToLive(Duration.ofMinutes(1));
    sender.send(message2);
    System.out.printf("\t=> Sent a duplicate message with messageId %s\n", message.getMessageId());
    sender.close();
}

From source file:org.cloudfoundry.dependency.check.CheckAction.java

@Override
public void run(String... args) {
    run().doOnNext(response -> this.logger.debug("Response: {}", response))
            .doOnNext(OutputUtils.write(this.objectMapper)).block(Duration.ofMinutes(5));
}

From source file:org.darkware.wpman.data.WPUpdatableComponent.java

/**
 * Create a new base instance of an updatable component.
 *
 * @param componentType The type of component in the concrete implementation
 *//*ww  w.j av  a 2 s .  c o  m*/
public WPUpdatableComponent(final WPUpdatableType componentType) {
    super();

    this.componentType = componentType;
    this.config = new LazyLoaded<C>(Duration.ofMinutes(2)) {
        @Override
        protected C loadValue() throws Exception {
            return WPUpdatableComponent.this.getConfig();
        }
    };
}

From source file:com.microsoft.azure.servicebus.samples.prefetch.Prefetch.java

long sendAndReceiveMessages(IMessageSender sender, IMessageReceiver receiver, int messageCount)
        throws Exception {
    // Now we can start sending messages.
    Random rnd = new Random();
    byte[] mockPayload = new byte[100]; // 100 random-byte payload

    rnd.nextBytes(mockPayload);/*w  ww .  j av  a2  s.  c  o  m*/

    System.out.printf("\nSending %d messages to the queue\n", messageCount);
    ArrayList<CompletableFuture<Void>> sendOps = new ArrayList<>();
    for (int i = 0; i < messageCount; i++) {
        IMessage message = new Message(mockPayload);
        message.setTimeToLive(Duration.ofMinutes(5));
        sendOps.add(sender.sendAsync(message));
    }
    CompletableFuture.allOf(sendOps.toArray(new CompletableFuture<?>[sendOps.size()])).join();

    System.out.printf("Send completed\n");

    // Receive the messages
    System.out.printf("Receiving messages...\n");

    // Start stopwatch
    Stopwatch stopWatch = Stopwatch.createStarted();

    IMessage receivedMessage = receiver.receive(Duration.ofSeconds(5));
    while (receivedMessage != null) {
        // here's where you'd do any work

        // complete (round trips)
        receiver.complete(receivedMessage.getLockToken());

        if (--messageCount <= 0)
            break;

        // now get the next message
        receivedMessage = receiver.receive(Duration.ofSeconds(5));
    }
    // Stop the stopwatch
    stopWatch.stop();

    System.out.printf("Receive completed\n");

    long timeTaken = stopWatch.elapsed(TimeUnit.MILLISECONDS);
    System.out.printf("Time to receive and complete all messages = %d milliseconds\n", timeTaken);

    return timeTaken;
}

From source file:com.microsoft.azure.servicebus.samples.scheduledmessages.ScheduledMessages.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());/*  w  w w .  j  a  v a  2  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));
        message.setScheduledEnqueueTimeUtc(Clock.systemUTC().instant().plusSeconds(120));
        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.partitionedqueues.PartitionedQueues.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());// w  w w.  j  ava2 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));
        message.setPartitionKey(data.get(i).get("name").substring(0, 1));

        tasks.add(sendClient.sendAsync(message).thenRunAsync(() -> {
            System.out.printf("Message sent: Id = %s\n", message.getMessageId());
        }));
    }
    return CompletableFuture.allOf(tasks.toArray(new CompletableFuture<?>[tasks.size()]));
}

From source file:com.microsoft.azure.servicebus.samples.messagebrowse.MessageBrowse.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  a v a  2  s .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));

        tasks.add(sendClient.sendAsync(message).thenRunAsync(() -> {
            System.out.printf("Message sent: Id = %s\n", message.getMessageId());
        }));
    }
    return CompletableFuture.allOf(tasks.toArray(new CompletableFuture<?>[tasks.size()]));
}