Example usage for java.time Instant isBefore

List of usage examples for java.time Instant isBefore

Introduction

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

Prototype

public boolean isBefore(Instant otherInstant) 

Source Link

Document

Checks if this instant is before the specified instant.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    System.out.println(instant.isBefore(Instant.now()));

}

From source file:com.offbynull.voip.kademlia.model.InternalValidate.java

static void forwardTime(Instant previousTime, Instant currentTime) {
    // throws illegalstateexception, because if you made it to this point you should never encounter these conditions
    Validate.validState(previousTime != null);
    Validate.validState(currentTime != null);

    if (currentTime.isBefore(previousTime)) {
        throw new BackwardTimeException(previousTime, currentTime);
    }//from  www  .j a va2 s . c o m
}

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();/*w  w w  .j  ava  2 s.c  o m*/
    }
}

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();
    Instant expiration = Instant.ofEpochMilli(token.getKeyCreationTime()).plus(Duration.ofMinutes(expiredTime));
    boolean before = now.isBefore(expiration);

    return before;

}

From source file:io.gravitee.management.service.impl.InstanceServiceImpl.java

@Override
public InstanceEntity findById(String eventId) {
    EventEntity event = eventService.findById(eventId);
    Instant nowMinusXMinutes = Instant.now().minus(5, ChronoUnit.MINUTES);

    Map<String, String> props = event.getProperties();
    InstanceEntity instance = new InstanceEntity(props.get("id"));
    instance.setLastHeartbeatAt(new Date(Long.parseLong(props.get("last_heartbeat_at"))));
    instance.setStartedAt(new Date(Long.parseLong(props.get("started_at"))));

    if (event.getPayload() != null) {
        try {/*  w ww.  j  a va2s.  c  om*/
            InstanceInfo info = objectMapper.readValue(event.getPayload(), InstanceInfo.class);
            instance.setHostname(info.getHostname());
            instance.setIp(info.getIp());
            instance.setVersion(info.getVersion());
            instance.setTags(info.getTags());
            instance.setSystemProperties(info.getSystemProperties());
            instance.setPlugins(info.getPlugins());
        } catch (IOException ioe) {
            LOGGER.error("Unexpected error while getting instance informations from event payload", ioe);
        }
    }

    if (event.getType() == EventType.GATEWAY_STARTED) {
        instance.setState(InstanceState.STARTED);
        // If last heartbeat timestamp is < now - 5m, set as unknown state
        Instant lastHeartbeat = Instant.ofEpochMilli(instance.getLastHeartbeatAt().getTime());
        if (lastHeartbeat.isBefore(nowMinusXMinutes)) {
            instance.setState(InstanceState.UNKNOWN);
        }
    } else {
        instance.setState(InstanceState.STOPPED);
        instance.setStoppedAt(new Date(Long.parseLong(props.get("stopped_at"))));
    }

    return instance;
}

From source file:io.gravitee.management.service.impl.InstanceServiceImpl.java

@Override
public Collection<InstanceListItem> findInstances(boolean includeStopped) {
    Set<EventEntity> events;

    if (includeStopped) {
        events = eventService.findByType(instancesAllState);
    } else {//from w  w w.j  a va2 s  . c o  m
        events = eventService.findByType(instancesRunningOnly);
    }

    Instant nowMinusXMinutes = Instant.now().minus(5, ChronoUnit.MINUTES);
    return events.stream().map(event -> {
        Map<String, String> props = event.getProperties();
        InstanceListItem instance = new InstanceListItem(props.get("id"));
        instance.setEvent(event.getId());
        instance.setLastHeartbeatAt(new Date(Long.parseLong(props.get("last_heartbeat_at"))));
        instance.setStartedAt(new Date(Long.parseLong(props.get("started_at"))));

        if (event.getPayload() != null) {
            try {
                InstanceInfo info = objectMapper.readValue(event.getPayload(), InstanceInfo.class);
                instance.setHostname(info.getHostname());
                instance.setIp(info.getIp());
                instance.setVersion(info.getVersion());
                instance.setTags(info.getTags());
                instance.setOperatingSystemName(info.getSystemProperties().get("os.name"));
            } catch (IOException ioe) {
                LOGGER.error("Unexpected error while getting instance informations from event payload", ioe);
            }
        }

        if (event.getType() == EventType.GATEWAY_STARTED) {
            instance.setState(InstanceState.STARTED);
            // If last heartbeat timestamp is < now - 5m, set as unknown state
            Instant lastHeartbeat = Instant.ofEpochMilli(instance.getLastHeartbeatAt().getTime());
            if (lastHeartbeat.isBefore(nowMinusXMinutes)) {
                instance.setState(InstanceState.UNKNOWN);
            }
        } else {
            instance.setState(InstanceState.STOPPED);
            instance.setStoppedAt(new Date(Long.parseLong(props.get("stopped_at"))));
        }

        return instance;
    }).collect(Collectors.toList());
}

From source file:com.offbynull.voip.kademlia.model.BackwardTimeException.java

BackwardTimeException(Instant previousTime, Instant inputTime) {
    super("Time is (" + inputTime + ") is before " + previousTime);
    Validate.notNull(previousTime);/*from w w  w .jav a2s . co  m*/
    Validate.notNull(inputTime);
    // what's the point of throwing an exception for going backwards in time if you're going forward in time?
    Validate.isTrue(!inputTime.isBefore(previousTime));
    this.previousTime = previousTime;
    this.inputTime = inputTime;
}

From source file:org.noorganization.instalist.server.api.ListResource.java

/**
 * Updates a existing list.//  w  w w . j ava  2  s  .c o m
 * @param _groupId The id of the group containing the list.
 * @param _listUUID The uuid of the list to update.
 * @param _listInfo Information for changing the list. Not all information needs to be set.
 */
@PUT
@TokenSecured
@Path("{listuuid}")
@Consumes("application/json")
@Produces({ "application/json" })
public Response putList(@PathParam("groupid") int _groupId, @PathParam("listuuid") String _listUUID,
        ListInfo _listInfo) throws Exception {
    if ((_listInfo.getDeleted() != null && _listInfo.getDeleted())
            || (_listInfo.getName() != null && _listInfo.getName().length() == 0)
            || (_listInfo.getUUID() != null && !_listInfo.getUUID().equals(_listUUID)))
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA);

    UUID listUUID;
    UUID categoryUUID = null;
    boolean removeCategory = false;
    try {
        listUUID = UUID.fromString(_listUUID);
        if (_listInfo.getCategoryUUID() != null)
            categoryUUID = UUID.fromString(_listInfo.getCategoryUUID());
        else if (_listInfo.getRemoveCategory() != null && _listInfo.getRemoveCategory())
            removeCategory = true;
    } catch (IllegalArgumentException _e) {
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_UUID);
    }
    Instant updated;
    Instant now = Instant.now();
    if (_listInfo.getLastChanged() != null) {
        updated = _listInfo.getLastChanged().toInstant();
        if (now.isBefore(updated))
            return ResponseFactory.generateBadRequest(CommonEntity.INVALID_CHANGEDATE);
    } else
        updated = now;

    EntityManager manager = DatabaseHelper.getInstance().getManager();
    IListController listController = ControllerFactory.getListController(manager);
    try {
        listController.update(_groupId, listUUID, _listInfo.getName(), categoryUUID, removeCategory, updated);
    } catch (ConflictException _e) {
        return ResponseFactory.generateConflict(
                new Error().withMessage("The new data is in " + "conflict with a saved list."));
    } catch (NotFoundException _e) {
        return ResponseFactory.generateNotFound(new Error().withMessage("The list was not " + "found."));
    } catch (GoneException _e) {
        return ResponseFactory.generateGone(new Error().withMessage("The list was " + "deleted already."));
    } catch (BadRequestException _e) {
        return ResponseFactory.generateBadRequest(CommonEntity.INVALID_DATA);
    } finally {
        manager.close();
    }
    return ResponseFactory.generateOK(null);
}

From source file:ws.salient.session.Session.java

public boolean expired(Instant instant) {
    Instant minsAgo = Instant.now().minus(15, ChronoUnit.MINUTES);
    return (instant != null && instant.isBefore(minsAgo));
}