Example usage for java.time Clock systemUTC

List of usage examples for java.time Clock systemUTC

Introduction

In this page you can find the example usage for java.time Clock systemUTC.

Prototype

public static Clock systemUTC() 

Source Link

Document

Obtains a clock that returns the current instant using the best available system clock, converting to date and time using the UTC time-zone.

Usage

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());/*from  www  .j  av  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:alfio.controller.api.support.PublicCategory.java

public ZonedDateTime getInception() {
    return getUtcInception().withZoneSameInstant(Clock.systemUTC().getZone());
}

From source file:org.haiku.haikudepotserver.pkg.PkgIconServiceImpl.java

@Override
public void removePkgIcon(ObjectContext context, Pkg pkg) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(null != pkg, "the package must be supplied");

    context.deleteObjects(deriveDataObjectsToDelete(pkg.getPkgIcons()));
    pkg.setModifyTimestamp();/* w ww .  j a v  a2  s . c  o m*/
    pkg.setIconModifyTimestamp(new java.sql.Timestamp(Clock.systemUTC().millis()));

    pkgService.findSubordinatePkgsForMainPkg(context, pkg.getName())
            .forEach(develPkg -> removePkgIcon(context, develPkg));

}

From source file:alfio.controller.api.support.PublicCategory.java

public ZonedDateTime getExpiration() {
    return getUtcExpiration().withZoneSameInstant(Clock.systemUTC().getZone());
}

From source file:com.netflix.spinnaker.orca.clouddriver.tasks.manifest.ManifestForceCacheRefreshTask.java

@Autowired
public ManifestForceCacheRefreshTask(Registry registry, CloudDriverCacheService cacheService,
        CloudDriverCacheStatusService cacheStatusService, ObjectMapper objectMapper) {
    this(registry, cacheService, cacheStatusService, objectMapper, Clock.systemUTC());
}

From source file:org.mylab.consulclient.ConsulClient.java

public ConsulKey getKeyDetailed(String key) throws IOException {
    logger.info("getKey called with a key value of: " + key + " at: " + Clock.systemUTC().instant().toString());
    String response = invokeConnector(key);
    logger.info("getKey returned response: " + response + " at: " + Clock.systemUTC().instant().toString());
    ObjectMapper mapper = new ObjectMapper();
    ConsulKey[] ckKeyArray = mapper.readValue(response, ConsulKey[].class);
    return ckKeyArray[0];
}

From source file:org.apache.james.modules.rabbitmq.RabbitMQModule.java

@Override
protected void configure() {
    bind(Clock.class).toInstance(Clock.systemUTC());
    bind(ThreadLocalRandom.class).toInstance(ThreadLocalRandom.current());

    bind(EnqueuedMailsDAO.class).in(Scopes.SINGLETON);
    bind(DeletedMailsDAO.class).in(Scopes.SINGLETON);
    bind(BrowseStartDAO.class).in(Scopes.SINGLETON);
    bind(CassandraMailQueueBrowser.class).in(Scopes.SINGLETON);
    bind(CassandraMailQueueMailDelete.class).in(Scopes.SINGLETON);
    bind(CassandraMailQueueMailStore.class).in(Scopes.SINGLETON);

    bind(SimpleChannelPool.class).in(Scopes.SINGLETON);
    bind(RabbitMQChannelPool.class).to(SimpleChannelPool.class);

    Multibinder<CassandraModule> cassandraModuleBinder = Multibinder.newSetBinder(binder(),
            CassandraModule.class);
    cassandraModuleBinder.addBinding().toInstance(CassandraMailQueueViewModule.MODULE);

    bind(EventsourcingConfigurationManagement.class).in(Scopes.SINGLETON);
    @SuppressWarnings("rawtypes")
    Multibinder<EventDTOModule> eventDTOModuleBinder = Multibinder.newSetBinder(binder(), EventDTOModule.class);
    eventDTOModuleBinder.addBinding()/*from  ww w . java  2  s  . co  m*/
            .toInstance(CassandraMailQueueViewConfigurationModule.MAIL_QUEUE_VIEW_CONFIGURATION);
}

From source file:com.nirmata.workflow.details.TestJsonSerializer.java

@Test
public void testStartedTask() {
    StartedTask startedTask = new StartedTask(Integer.toString(random.nextInt()),
            LocalDateTime.now(Clock.systemUTC()));
    JsonNode node = newStartedTask(startedTask);
    String str = nodeToString(node);
    System.out.println(str);/*from ww  w  .  j  av  a  2s .  c  o m*/

    StartedTask unStartedTask = getStartedTask(fromString(str));
    Assert.assertEquals(startedTask, unStartedTask);
}

From source file:com.seleniumtests.uipage.PageObject.java

/**
 * Base Constructor./* w  w  w  .  j  av  a  2s  .  c  o  m*/
 * Represents a page on our web site or mobile application.
 *
 * @param   pageIdentifierElement   The element to search for so that we check we are on the right page. 
 *                            May be null if we do not want to check we are on the page
 * @param   url                  the URL to which we should connect. May be null if we do not want to go to a specific URL
 * @throws IOException 
 *
 * @throws  Exception
 */
public PageObject(final HtmlElement pageIdentifierElement, final String url) throws IOException {

    systemClock = Clock.systemUTC();
    Calendar start = Calendar.getInstance();
    start.setTime(new Date());

    if (SeleniumTestsContextManager.getGlobalContext() != null
            && SeleniumTestsContextManager.getGlobalContext().getTestNGContext() != null) {
        suiteName = SeleniumTestsContextManager.getGlobalContext().getTestNGContext().getSuite().getName();
        outputDirectory = SeleniumTestsContextManager.getGlobalContext().getTestNGContext()
                .getOutputDirectory();
    }

    this.pageIdentifierElement = pageIdentifierElement;
    driver = WebUIDriver.getWebDriver();

    // open page
    openPage(url);

    assertCurrentPage(false);

    SeleniumTestsPageListener.informPageLoad(this);

    Calendar end = Calendar.getInstance();
    start.setTime(new Date());

    long startTime = start.getTimeInMillis();
    long endTime = end.getTimeInMillis();
    if ((endTime - startTime) / 1000 > 0) {
        TestLogging.log("Open web page in :" + (endTime - startTime) / 1000 + "seconds");
    }

}

From source file:no.digipost.api.useragreements.client.response.ResponseUtils.java

public static Optional<Duration> parseDelayDurationOfRetryAfterHeader(HttpResponse response) {
    return parseDelayDurationOfRetryAfterHeader(response, Clock.systemUTC());
}