Java Code Examples for java.time.Instant#ofEpochMilli()

The following examples show how to use java.time.Instant#ofEpochMilli() . These examples are extracted from open source projects. 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 Project: hadoop-ozone   File: ContainerInfo.java    License: Apache License 2.0 6 votes vote down vote up
@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
@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 Project: bazel   File: TestIntervalTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 4
Source Project: kayenta   File: NewRelicMetricsService.java    License: Apache License 2.0 5 votes vote down vote up
@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 5
/**
 * 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 6
Source Project: Dhalion   File: MeasurementsTableTest.java    License: MIT License 5 votes vote down vote up
@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 7
@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 8
Source Project: conga   File: SbeRequestTest.java    License: Apache License 2.0 5 votes vote down vote up
@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 9
Source Project: iec61850bean   File: BdaTimestamp.java    License: Apache License 2.0 5 votes vote down vote up
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 10
Source Project: copycat   File: ServerCommit.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 11
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 12
private Instant now() {
    return Instant.ofEpochMilli(scheduler.now());
}
 
Example 13
@Test(dataProvider="badTemporalAmount",expectedExceptions=DateTimeException.class)
public void test_badPlusTemporalAmount(TemporalAmount amount) {
    Instant inst = Instant.ofEpochMilli(1000);
    inst.plus(amount);
}
 
Example 14
Source Project: jesterj   File: JdbcScanner.java    License: Apache License 2.0 4 votes vote down vote up
private static String convertDateToString(Object value) {
  Instant instant = Instant.ofEpochMilli(((Date) value).getTime());
  return DATE_FORMATTER.format(instant);
}
 
Example 15
Source Project: hottub   File: TCKInstant.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test(dataProvider="badTemporalAmount",expectedExceptions=DateTimeException.class)
public void test_badPlusTemporalAmount(TemporalAmount amount) {
    Instant inst = Instant.ofEpochMilli(1000);
    inst.plus(amount);
}
 
Example 16
@Override
public Instant getInstantAt(int point) {
    return Instant.ofEpochMilli(getTimeAt(point));
}
 
Example 17
private static Instant toInstant(Long epochMillis) {
    return epochMillis == null ? null : Instant.ofEpochMilli(epochMillis);
}
 
Example 18
@Override
public Instant convert(Long source) {
	return Instant.ofEpochMilli(source);
}
 
Example 19
/**
 * 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 Project: helper   File: Time.java    License: MIT License 2 votes vote down vote up
/**
 * Gets the current unix time as an {@link Instant}.
 *
 * @return the current unix time
 */
public static Instant now() {
    return Instant.ofEpochMilli(System.currentTimeMillis());
}