Java Code Examples for java.time.Instant#ofEpochMilli()
The following examples show how to use
java.time.Instant#ofEpochMilli() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerInfo.java From hadoop-ozone with Apache License 2.0 | 6 votes |
@SuppressWarnings("parameternumber") ContainerInfo( long containerID, HddsProtos.LifeCycleState state, PipelineID pipelineID, long usedBytes, long numberOfKeys, long stateEnterTime, String owner, long deleteTransactionId, long sequenceId, ReplicationFactor replicationFactor, ReplicationType repType) { this.containerID = containerID; this.pipelineID = pipelineID; this.usedBytes = usedBytes; this.numberOfKeys = numberOfKeys; this.lastUsed = Instant.ofEpochMilli(Time.now()); this.state = state; this.stateEnterTime = Instant.ofEpochMilli(stateEnterTime); this.owner = owner; this.deleteTransactionId = deleteTransactionId; this.sequenceId = sequenceId; this.replicationFactor = replicationFactor; this.replicationType = repType; }
Example 2
Source File: BaseEventDelayHandler.java From sakai with Educational Community License v2.0 | 6 votes |
@SuppressWarnings("unchecked") public String createDelay(Event event, String userId, Time fireTime) { // delete previous like delays deleteDelay(event); Object[] fields = new Object[] { event.getEvent(), event.getModify() ? "m" : "a", event.getPriority(), event.getResource(), userId }; sqlService.dbWrite(baseEventDelayHandlerSql.getDelayWriteSql(), fields); List<String> ids = sqlService.dbRead(baseEventDelayHandlerSql.getDelayFindFineSql(), fields, null); String id = null; if (ids.size() > 0) id = (String) ids.get(0); // Schedule the new delayed invocation log.info("Creating new delayed event [" + id + "]"); Instant fireInstant = Instant.ofEpochMilli(fireTime.getTime()); schedInvocMgr.createDelayedInvocation(fireInstant, BaseEventDelayHandler.class.getName(), id); return id; }
Example 3
Source File: NewRelicMetricsService.java From kayenta with Apache License 2.0 | 5 votes |
@Override public List<MetricSet> queryMetrics( String accountName, CanaryConfig canaryConfig, CanaryMetricConfig canaryMetricConfig, CanaryScope canaryScope) throws IOException { NewRelicNamedAccountCredentials accountCredentials = accountCredentialsRepository.getRequiredOne(accountName); NewRelicCredentials credentials = accountCredentials.getCredentials(); NewRelicRemoteService remoteService = accountCredentials.getNewRelicRemoteService(); String query = buildQuery(accountName, canaryConfig, canaryMetricConfig, canaryScope); NewRelicTimeSeries timeSeries = remoteService.getTimeSeries( credentials.getApiKey(), credentials.getApplicationKey(), query); Instant begin = Instant.ofEpochMilli(timeSeries.getMetadata().getBeginTimeMillis()); Instant end = Instant.ofEpochMilli(timeSeries.getMetadata().getEndTimeMillis()); Duration stepDuration = Duration.ofSeconds(canaryScope.getStep()); if (stepDuration.isZero()) { stepDuration = calculateStepDuration(timeSeries); } return Collections.singletonList( MetricSet.builder() .name(canaryMetricConfig.getName()) .startTimeMillis(begin.toEpochMilli()) .startTimeIso(begin.toString()) .stepMillis(stepDuration.toMillis()) .endTimeMillis(end.toEpochMilli()) .endTimeIso(end.toString()) .values(timeSeries.getDataPoints().collect(Collectors.toList())) .attribute("query", query) .build()); }
Example 4
Source File: PodcastServiceImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * If Release Date property not set, check if DISPLAY_DATE exists * and if it does, return it so it can be set as the Release Date. * If DISPLAY_DATE does not exist, default to last modified date. * * @param ResourceProperties * The ResourceProperties to get DISPLAY_DATE from */ private Instant getDisplayDate(ResourceProperties rp) { Date tempDate = null; try { // Convert GMT time stored by Resources into local time tempDate = rp.getDateProperty(DISPLAY_DATE); return Instant.ofEpochMilli(tempDate.getTime()); } catch (Exception e) { try { tempDate = rp.getDateProperty( ResourceProperties.PROP_MODIFIED_DATE); return Instant.ofEpochMilli(tempDate.getTime()); } catch (Exception e1) { // catches EntityPropertyNotDefinedException // EntityPropertyTypeException, ParseException log.info(e1.getMessage() + " while getting DISPLAY_DATE for " + "file in site " + getSiteId() + ". ", e); } } return null; }
Example 5
Source File: MeasurementsTableTest.java From Dhalion with MIT License | 5 votes |
@Test public void between() { Instant oldest = Instant.ofEpochMilli(60); Instant newest = Instant.ofEpochMilli(70); resultTable = testTable.between(oldest, newest); assertEquals(2, resultTable.size()); resultTable.get().forEach(m -> assertTrue(60 <= m.instant().toEpochMilli())); resultTable.get().forEach(m -> assertTrue(70 >= m.instant().toEpochMilli())); }
Example 6
Source File: TCKInstant.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider="plusTemporalAmount") public void test_plusTemporalAmount(TemporalUnit unit, TemporalAmount amount, int seconds, int nanos) { Instant inst = Instant.ofEpochMilli(1000); Instant actual = inst.plus(amount); Instant expected = Instant.ofEpochSecond(seconds, nanos); assertEquals(actual, expected, "plus(TemporalAmount) failed"); }
Example 7
Source File: SbeRequestTest.java From conga with Apache License 2.0 | 5 votes |
@Test public void order() throws MessageException { MutableNewOrderSingle encoder = mutableMessageFactory.getNewOrderSingle(); String clOrdId = "CL0001"; encoder.setClOrdId(clOrdId); int orderQty = 7; encoder.setOrderQty(orderQty); OrdType ordType = OrdType.Limit; encoder.setOrdType(ordType); BigDecimal price = BigDecimal.valueOf(5432, 2); encoder.setPrice(price); Side side = Side.Sell; encoder.setSide(side); String symbol = "SYM1"; encoder.setSymbol(symbol); Instant transactTime = Instant.ofEpochMilli(10000L); encoder.setTransactTime(transactTime); buffer.flip(); Message message = messageFactory.wrap(buffer); if (message instanceof NewOrderSingle) { NewOrderSingle decoder = (NewOrderSingle) message; assertEquals(clOrdId, decoder.getClOrdId()); assertEquals(orderQty, decoder.getOrderQty()); assertEquals(ordType, decoder.getOrdType()); assertEquals(price, decoder.getPrice()); assertEquals(side, decoder.getSide()); assertEquals(symbol, decoder.getSymbol()); assertEquals(transactTime, decoder.getTransactTime()); } else { fail("Wrong message type"); } encoder.release(); }
Example 8
Source File: BdaTimestamp.java From iec61850bean with Apache License 2.0 | 5 votes |
public Instant getInstant() { if (value == null || value.length == 0) { return null; } long time = getSecondsSinceEpoch() * 1000L + (long) (((float) getFractionOfSecond()) / (1 << 24) * 1000 + 0.5); return Instant.ofEpochMilli(time); }
Example 9
Source File: RecordedObject.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private Instant getInstant(long timestamp, String name) { ValueDescriptor v = getValueDescriptor(descriptors, name, null); Timestamp ts = v.getAnnotation(Timestamp.class); if (ts != null) { switch (ts.value()) { case Timestamp.MILLISECONDS_SINCE_EPOCH: return Instant.ofEpochMilli(timestamp); case Timestamp.TICKS: return Instant.ofEpochSecond(0, timeConverter.convertTimestamp(timestamp)); } throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with illegal timestamp unit " + ts.value()); } throw new IllegalArgumentException("Attempt to get " + v.getTypeName() + " field \"" + name + "\" with missing @Timestamp"); }
Example 10
Source File: TestIntervalTest.java From bazel with Apache License 2.0 | 5 votes |
@Test public void testToDurationOnNonMonotonicWallTime() { Instant start = Instant.ofEpochMilli(123456); Instant end = Instant.ofEpochMilli(123456); Duration monotonicStart = Duration.ofMillis(50); Duration monotonicEnd = Duration.ofMillis(150); TestInterval interval = new TestInterval( new TestInstant(start, monotonicStart), new TestInstant(end, monotonicEnd)); assertThat(interval.getStartMillis()).isEqualTo(123456); assertThat(interval.getEndMillis()).isEqualTo(123456); assertThat(interval.toDurationMillis()).isEqualTo(100); }
Example 11
Source File: ServerCommit.java From copycat with Apache License 2.0 | 5 votes |
/** * Resets the commit. * * @param entry The entry. */ void reset(OperationEntry<?> entry, ServerSessionContext session, long timestamp) { if (references.compareAndSet(0, 1)) { this.index = entry.getIndex(); this.session = session; this.instant = Instant.ofEpochMilli(timestamp); this.operation = entry.getOperation(); session.acquire(); references.set(1); } else { throw new IllegalStateException("Cannot recycle commit with " + references.get() + " references"); } }
Example 12
Source File: JdbcScanner.java From jesterj with Apache License 2.0 | 4 votes |
private static String convertDateToString(Object value) { Instant instant = Instant.ofEpochMilli(((Date) value).getTime()); return DATE_FORMATTER.format(instant); }
Example 13
Source File: DateTimeConverters.java From spring4-understanding with Apache License 2.0 | 4 votes |
@Override public Instant convert(Long source) { return Instant.ofEpochMilli(source); }
Example 14
Source File: AuthMePlayerImpl.java From AuthMeReloaded with GNU General Public License v3.0 | 4 votes |
private static Instant toInstant(Long epochMillis) { return epochMillis == null ? null : Instant.ofEpochMilli(epochMillis); }
Example 15
Source File: AbstractTimeSeriesIndex.java From powsybl-core with Mozilla Public License 2.0 | 4 votes |
@Override public Instant getInstantAt(int point) { return Instant.ofEpochMilli(getTimeAt(point)); }
Example 16
Source File: TCKInstant.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="badTemporalAmount",expectedExceptions=DateTimeException.class) public void test_badPlusTemporalAmount(TemporalAmount amount) { Instant inst = Instant.ofEpochMilli(1000); inst.plus(amount); }
Example 17
Source File: TCKInstant.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="badTemporalAmount",expectedExceptions=DateTimeException.class) public void test_badPlusTemporalAmount(TemporalAmount amount) { Instant inst = Instant.ofEpochMilli(1000); inst.plus(amount); }
Example 18
Source File: LoadBalancerEngine.java From titus-control-plane with Apache License 2.0 | 4 votes |
private Instant now() { return Instant.ofEpochMilli(scheduler.now()); }
Example 19
Source File: AuthMeApi.java From AuthMeReloaded with GNU General Public License v3.0 | 2 votes |
/** * Get the last (AuthMe) login timestamp of a player. * * @param playerName The name of the player to process * * @return The timestamp of the last login, or null if the player doesn't exist or has never logged in */ public Instant getLastLoginTime(String playerName) { Long lastLogin = getLastLoginMillis(playerName); return lastLogin == null ? null : Instant.ofEpochMilli(lastLogin); }
Example 20
Source File: Time.java From helper with MIT License | 2 votes |
/** * Gets the current unix time as an {@link Instant}. * * @return the current unix time */ public static Instant now() { return Instant.ofEpochMilli(System.currentTimeMillis()); }