use of java.time.Instant in project aroma-data-operations by RedRoma.
the class MemoryTokenRepository method saveToken.
@Override
public void saveToken(AuthenticationToken token) throws TException {
checkThat(token).throwing(ex -> new InvalidTokenException(ex.getMessage())).is(legalToken());
checkThat(token.ownerId).usingMessage("token missing ownerId").throwing(InvalidTokenException.class).is(nonEmptyString());
checkThat(token.tokenType).usingMessage("tokenType is required").throwing(InvalidTokenException.class).is(notNull());
Instant expirationTime = Instant.ofEpochMilli(token.timeOfExpiration);
checkThat(expirationTime).throwing(InvalidArgumentException.class).usingMessage("Token expiration time must be in the future: " + expirationTime).is(TimeAssertions.inTheFuture());
Instant now = Instant.now();
long timeToLiveSeconds = now.until(expirationTime, ChronoUnit.SECONDS);
synchronized (tokens) {
this.tokens.put(token.tokenId, token, timeToLiveSeconds, TimeUnit.SECONDS);
addTokenForOwner(token);
}
}
use of java.time.Instant in project rhino by PLOS.
the class CacheableResponse method serveEntity.
/**
* Serve a view representing a timestamped entity.
*
* @param entity the entity to represent in the response
* @param viewFunction a function that converts the entity into a serializable view
* @param <E> the entity's type
* @param <T> the view's type
* @return a response of the view
*/
public static <T, E extends Timestamped> CacheableResponse<T> serveEntity(E entity, Function<? super E, ? extends T> viewFunction) {
Objects.requireNonNull(viewFunction);
Supplier<T> supplier = () -> viewFunction.apply(entity);
Instant lastModified = entity.getLastModified().toInstant();
return new CacheableResponse<>(lastModified, supplier);
}
use of java.time.Instant in project aroma-data-operations by RedRoma.
the class MemoryTokenRepositoryTest method setUp.
@Before
public void setUp() {
repository = new MemoryTokenRepository();
token = TokenGenerators.authenticationTokens().get();
tokenId = token.getTokenId();
ownerId = token.getOwnerId();
tokens.forEach(t -> t.setOwnerId(ownerId));
Instant timeOfExpiration = one(futureInstants()).plus(1, ChronoUnit.HOURS);
token.setTimeOfExpiration(timeOfExpiration.toEpochMilli());
tokens.forEach(t -> t.setTimeOfExpiration(timeOfExpiration.toEpochMilli()));
}
use of java.time.Instant in project graylog2-server by Graylog2.
the class MongoZonedDateTimeSerializer method serialize.
@Override
public void serialize(ZonedDateTime zonedDateTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
final Instant instant = zonedDateTime.withZoneSameInstant(ZoneOffset.UTC).toInstant();
final Date date = Date.from(instant);
jsonGenerator.writeObject(date);
}
use of java.time.Instant in project jdk8u_jdk by JetBrains.
the class TCKDuration method factory_between_TemporalTemporal_Instant.
@Test(dataProvider = "durationBetweenInstant")
public void factory_between_TemporalTemporal_Instant(long secs1, int nanos1, long secs2, int nanos2, long expectedSeconds, int expectedNanoOfSecond) {
Instant start = Instant.ofEpochSecond(secs1, nanos1);
Instant end = Instant.ofEpochSecond(secs2, nanos2);
Duration t = Duration.between(start, end);
assertEquals(t.getSeconds(), expectedSeconds);
assertEquals(t.getNano(), expectedNanoOfSecond);
}
Aggregations