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:se.curity.examples.oauth.jwt.JwkManager.java

private void ensureCacheIsFresh() {
    _logger.info("Called ensureCacheIsFresh");
    Instant lastLoading = _jsonWebKeyByKID.getLastReloadInstant().orElseGet(() -> Instant.MIN);
    boolean cacheIsNotFresh = lastLoading
            .isBefore(Instant.now().minus(_jsonWebKeyByKID.getMinTimeBetweenReloads()));

    if (cacheIsNotFresh) {
        _logger.info("Invalidating JSON WebKeyID cache");
        _jsonWebKeyByKID.clear();//from   w  ww  .ja va2 s.com
    }
}

From source file:hub.backends.jobs.JobsQuery.java

private Thing<Jobs> wrapJobs(Thing<Person> person, Jobs jobs) {
    Thing<Jobs> t = new Thing();
    t.setThingType(typeRegistry.getType(Jobs.class));
    Instant instant = Instant.now();
    t.setId(person.getKey() + "::" + instant.toString());
    t.setKey(person.getKey());/*from w  w w  . j  a  va2 s  .  c  o  m*/
    t.setValue(jobs);
    return t;
}

From source file:com.arrow.acs.client.api.ApiAbstract.java

public <T> T execute(HttpRequestBase request, SearchCriteria criteria, TypeReference<T> typeRef)
        throws IOException {
    Validate.notNull(criteria, "criteria is null");
    Validate.notNull(apiConfig, "apiConfig is not set");
    String method = "execute";
    Instant timestamp = Instant.now();
    ApiRequestSigner signer = getSigner(request, timestamp);
    for (Pair entry : criteria.getAllCriteria()) {
        signer.parameter(entry.getName(), entry.getValue());
    }// w  ww .j a  v  a2s. co m
    String signature = signer.signV1();
    logDebug(method, SIGNATURE_MSG, signature);
    addHeaders(request, timestamp, signature);
    return JsonUtils.fromJson(execute(request), typeRef);
}

From source file:org.ulyssis.ipp.publisher.Score.java

public Score(Snapshot snapshot, boolean publicScore) {
    Config config = Config.getCurrentConfig();
    Instant now = Instant.now();
    this.time = now.toEpochMilli();
    this.lap = config.getTrackLength();
    this.update = snapshot.getUpdateFrequency();
    this.teams = new TreeSet<>();
    this.status = snapshot.getStatus();
    this.message = snapshot.getStatusMessage();
    TeamStates teamStates = publicScore ? snapshot.getPublicTeamStates() : snapshot.getTeamStates();
    for (org.ulyssis.ipp.config.Team team : config.getTeams()) {
        Optional<TeamState> teamState = teamStates.getStateForTeam(team.getTeamNb());
        if (teamState.isPresent()) {
            TeamState t = teamState.get();
            double speed = t.getPredictedSpeed();
            if (Double.isNaN(speed)) {
                teams.add(new Team(lap, team.getTeamNb(), team.getName(), 0, 0, 0, 0));
            } else {
                TagSeenEvent lastEvent = t.getLastTagSeenEvent().get();
                Instant lastTime = t.getLastTagSeenEvent().get().getTime();
                double elapsedSeconds = Duration.between(lastTime, now).toMillis() / 1000D;
                double previousReaderPosition = config.getReader(lastEvent.getReaderId()).getPosition();
                double nonLimitedPosition = previousReaderPosition + elapsedSeconds * speed;
                double position = nonLimitedPosition;
                if (position > config.getTrackLength())
                    position = config.getTrackLength();
                teams.add(new Team(lap, team.getTeamNb(), team.getName(), t.getNbLaps(),
                        position / config.getTrackLength(), nonLimitedPosition / config.getTrackLength(),
                        speed));//from w ww. ja  va  2 s.co m
            }
        } else {
            teams.add(new Team(lap, team.getTeamNb(), team.getName(), 0, 0, 0, 0));
        }
    }
}

From source file:se.crisp.codekvast.agent.daemon.worker.impl.ZipFileDataExporterImpl.java

private void doExportDataTo(File exportFile) throws DataExportException {
    log.debug("Exporting data to {} ...", exportFile);

    File tmpFile = createTempFile(exportFile);

    try (ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(tmpFile)))) {
        String uuid = UUID.randomUUID().toString();
        zip.setComment(format("Export of Codekvast local warehouse for %s at %s, uuid=%s",
                config.getEnvironment(), Instant.now(), uuid));

        Charset charset = Charset.forName("UTF-8");
        doExportMetaInfo(zip, charset,// www . j  a  v a 2s . co m
                ExportFileMetaInfo.builder().uuid(uuid).schemaVersion(SCHEMA_VERSION)
                        .daemonVersion(config.getDaemonVersion()).daemonVcsId(config.getDaemonVcsId())
                        .daemonHostname(getHostname()).environment(config.getEnvironment()).build());

        CSVWriter csvWriter = new CSVWriter(new OutputStreamWriter(zip, charset));
        doExportDatabaseTable(zip, csvWriter, "applications", "id", "name", "version", "createdAtMillis");
        doExportDatabaseTable(zip, csvWriter, "methods", "id", "visibility", "signature", "createdAtMillis",
                "declaringType", "exceptionTypes", "methodName", "modifiers", "packageName", "parameterTypes",
                "returnType");
        doExportDatabaseTable(zip, csvWriter, "jvms", "id", "uuid", "startedAtMillis", "dumpedAtMillis",
                "jvmDataJson");
        doExportDatabaseTable(zip, csvWriter, "invocations", "applicationId", "methodId", "jvmId",
                "invokedAtMillis", "invocationCount", "status");

        zip.finish();
    } catch (Exception e) {
        throw new DataExportException("Cannot create " + exportFile, e);
    }

    if (!tmpFile.renameTo(exportFile)) {
        tmpFile.delete();
        throw new DataExportException(format("Cannot rename %s to %s", tmpFile, exportFile));
    }
}

From source file:net.beaconpe.jraklib.server.Session.java

public Session(SessionManager sessionManager, String address, int port) {
    this.sessionManager = sessionManager;
    this.address = address;
    this.port = port;
    sendQueue = new DataPackets.DATA_PACKET_4();
    lastUpdate = Instant.now().toEpochMilli();
    startTime = Instant.now().toEpochMilli();
    isActive = false;/*from ww w  . j  a va  2 s  .  com*/
    windowStart = -1;
    windowEnd = WINDOW_SIZE;

    reliableWindowStart = 0;
    reliableWindowEnd = WINDOW_SIZE;

    for (byte i = 0; i < 32; i++) {
        channelIndex.put(i, 0);
    }
}

From source file:org.ng200.openolympus.services.ContestService.java

public boolean isContestInProgressForUser(final Contest contest, final User user) {
    if (Instant.now().isBefore(contest.getStartTime().toInstant())) {
        return false;
    }/* w ww . j  a va 2  s .c  o m*/
    return !contest.getStartTime().toInstant()
            .plusMillis(contest.getDuration() + this.getTimeExtensions(contest, user)).isAfter(Instant.now());
}

From source file:com.orange.cepheus.broker.LocalRegistrationsTest.java

@Test
public void testUpdateRegistration() throws Exception {

    RegisterContext registerContext = createRegistrationContext();
    registerContext.setRegistrationId("12345");

    Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext);

    reset(registrationsRepository);/* ww  w  .  jav a 2s  .  com*/
    when(registrationsRepository.getRegistration(any())).thenReturn(registration);

    String registrationId = localRegistrations.updateRegistrationContext(registerContext);
    Assert.hasLength(registrationId);
    assertNotEquals("12345", registrationId);
    Registration registration2 = localRegistrations.getRegistration(registrationId);
    assertNotNull(registration2);
    assertNotNull(registration2.getExpirationDate());

    verify(remoteRegistrations).registerContext(eq(registerContext), eq(registrationId));
    verify(registrationsRepository).getRegistration(eq(registrationId));
    verify(registrationsRepository).updateRegistration(eq(registration));
}

From source file:devbury.dewey.plugins.RemindMe.java

private Date notifyAt(long amount, String units) {
    ChronoUnit chronoUnit = ChronoUnit.SECONDS;
    switch (units) {
    case "weeks":
    case "week":
        chronoUnit = ChronoUnit.WEEKS;
        break;/*from   w w  w.j  a  va  2 s  .  c om*/
    case "months":
    case "month":
        chronoUnit = ChronoUnit.MONTHS;
        break;
    case "days":
    case "day":
        chronoUnit = ChronoUnit.DAYS;
        break;
    case "hours":
    case "hour":
        chronoUnit = ChronoUnit.HOURS;
        break;
    case "minutes":
    case "minute":
        chronoUnit = ChronoUnit.MINUTES;
        break;
    }
    return Date.from(Instant.now().plus(amount, chronoUnit));
}

From source file:org.createnet.raptor.db.mapdb.MapDBConnection.java

@Override
public JsonNode get(String id) {

    Record r = getRecord(id);//from w ww .  j a v  a 2  s.c om

    if (r == null) {
        return null;
    }

    if (r.ttl > 0 && Instant.ofEpochSecond(r.ttl).isBefore(Instant.now())) {
        delete(id);
        return null;
    }

    return r.content;
}