Example usage for java.time Instant now

List of usage examples for java.time Instant now

Introduction

In this page you can find the example usage for java.time Instant now.

Prototype

public static Instant now() 

Source Link

Document

Obtains the current instant from the system clock.

Usage

From source file:org.eclipse.hono.service.cache.SpringBasedExpiringValueCache.java

@Override
public void put(final K key, final V value, final Instant expirationTime) {

    Objects.requireNonNull(key);/*from   w  w w.j  av a2s . c  o m*/
    Objects.requireNonNull(value);
    Objects.requireNonNull(expirationTime);

    if (Instant.now().isBefore(expirationTime)) {
        final ExpiringValue<V> expiringValue = new BasicExpiringValue<>(value, expirationTime);
        cache.put(key, expiringValue);
    } else {
        throw new IllegalArgumentException("value is already expired");
    }
}

From source file:cn.edu.zjnu.acm.judge.domain.Contest.java

@JsonIgnore
@XmlTransient
public boolean isEnded() {
    return endTime != null && endTime.isBefore(Instant.now());
}

From source file:org.ulyssis.ipp.control.commands.Command.java

public Command() {
    this.commandId = generateCommandId();
    this.time = Instant.now();
}

From source file:de.rkl.tools.tzconv.configuration.ConfiguredComponentsProvider.java

@Bean
public Ordering<ZoneId> createZoneIdOrderingByOffsetAndName() {
    return Ordering.<ZoneId>from((left, right) -> {
        final Instant comparisonInstant = Instant.now();
        final ZoneOffset leftOffset = left.getRules().getStandardOffset(comparisonInstant);
        final ZoneOffset rightOffset = right.getRules().getStandardOffset(comparisonInstant);
        return ComparisonChain.start().compare(rightOffset, leftOffset)
                .compare(left.toString(), right.toString()).result();
    }).nullsFirst();//from   w ww  . j  a  v  a2 s.c o m
}

From source file:com.netflix.genie.web.util.UnixProcessCheckerUnitTests.java

/**
 * Setup for the tests./*from www  . j ava 2s. c  om*/
 */
@Before
public void setup() {
    Assume.assumeTrue(SystemUtils.IS_OS_UNIX);
    this.executor = Mockito.mock(Executor.class);
    final Instant tomorrow = Instant.now().plus(1, ChronoUnit.DAYS);
    this.processChecker = new UnixProcessChecker(PID, this.executor, tomorrow);
}

From source file:io.pivotal.strepsirrhini.chaosloris.reaper.EventReaper.java

final Mono<Long> doReap() {
    Instant limit = Instant.now().minus(this.period);

    return Flux.fromIterable(this.eventRepository.findByExecutedAtBefore(limit))
            .flatMap(event -> reap(this.eventRepository, event, this.logger)).count()
            .doOnSubscribe(s -> this.logger.info("Reap Events before {}", limit.toString()))
            .doOnSuccess(count -> this.logger.debug("Reaped {} Events", count));
}

From source file:nl.knaw.huygens.alexandria.endpoint.resource.ResourcePrototypeTest.java

@Test
public void testResourcePrototypeFromJson() throws IOException {
    UUID uuid = UUID.randomUUID();
    Instant instant = Instant.now();
    String json = singleQuotesToDouble("{"//
            + "'resource':{"//
            + "'id':'" + uuid.toString() + "',"//
            + "'ref':'whatever',"//
            + "'provenance':{"//
            + "'when':'" + instant + "'"//
            + "}"//
            + "}}");
    Log.info("json={}", json);
    ResourcePrototype rp = om.readValue(json, ResourcePrototype.class);
    Log.info("resourcePrototype={}", rp);
    assertThat(rp.getId().getValue()).isEqualTo(uuid);
    assertThat(rp.getRef()).isEqualTo("whatever");
    assertThat(rp.getProvenance().isPresent()).isTrue();
    assertThat(rp.getProvenance().get().getWhen()).isEqualTo(instant);
    assertThat(rp.getProvenance().get().getValue().getWho()).isEqualTo(ThreadContext.getUserName());
    assertThat(rp.getProvenance().get().getValue().getWhy()).isEqualTo(AlexandriaProvenance.DEFAULT_WHY);
}

From source file:echange.service.EnvoieMessageService.java

public void envoieMessage(Long idEmetteur, Long idDestinataire, String titre, String msg)
        throws ExceptionUtilisateurInexistant {
    // Dclaration des Exceptions si l'utilisateur ou l'emetteur sont inexistants
    if (utilisateurService.exists(idEmetteur) == false) {
        throw new ExceptionUtilisateurInexistant();
    }/*from  w ww  .  ja v a2  s  . c  o  m*/
    if (utilisateurService.exists(idDestinataire) == false) {
        throw new ExceptionUtilisateurInexistant();
    }
    //Rcupration des emetteur et recepteur
    Utilisateur emetteur = utilisateurService.findOne(idEmetteur);
    Utilisateur destinataire = utilisateurService.findOne(idDestinataire);
    //Cration et Edition des attributs du messages
    Message m = new Message();
    m.setEmeteurMessage(emetteur);
    m.setDestinataireMessage(destinataire);
    m.setTitre(titre);
    m.setContenu(msg);
    m.setLu(false);
    Timestamp date;
    date = Timestamp.from(Instant.now());
    m.setDateCreation(date);
    //Enregistrement du message
    messageService.save(m);
}

From source file:nl.ctrlaltdev.harbinger.filter.BlacklistFilterTest.java

@Test
public void shouldRejectIfOnBlackList() throws IOException, ServletException {
    request.setRemoteAddr("8.8.8.8");
    ctx.blacklist("8.8.8.8", Instant.now().plusSeconds(1));
    filter.doFilter(request, response, chain);
}

From source file:com.pepaproch.gtswsdl.client.RateLimitTest.java

@Test
public void testCOnsumeSLotAsync() {
    RateLimit rate = new RateLimit(5, 10, ChronoUnit.SECONDS);
    ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10);
    final AtomicInteger cc = new AtomicInteger(0);
    Instant start = Instant.now();
    final Instant[] end = new Instant[1];

    Runnable r = () -> {//from w  ww . j  ava2 s  .  c  o  m
        for (int i = 0; i < 21; i++) {
            addTask(cc, scheduler, rate, end);
        }
    };
    Runnable r1 = () -> {
        for (int i = 0; i < 9; i++) {
            addTask(cc, scheduler, rate, end);

        }
    };

    r1.run();
    r.run();

    try {

        scheduler.awaitTermination(5, TimeUnit.SECONDS);

    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    System.out.println(Duration.between(start, end[0]).toMillis());
}