List of usage examples for java.time Instant ofEpochMilli
public static Instant ofEpochMilli(long epochMilli)
From source file:ch.algotrader.broker.marketdata.ConsumerEventThrottler.java
public List<Subscription> throttle(final List<Subscription> consumers) { List<Subscription> filteredConsumers = new ArrayList<>(); for (Subscription consumer : consumers) { ConsumerInfo info = consumer.getConsumerInfo(); ActiveMQDestination activeMQDestination = consumer.getActiveMQDestination(); ConsumerId consumerId = info.getConsumerId(); String connectionId = consumerId.getConnectionId(); Long lastEvent = this.consumerLastEvent.get(consumerId); if (lastEvent == null) { filteredConsumers.add(consumer); } else {/* www .j a v a 2 s . co m*/ long now = System.currentTimeMillis(); boolean propagate = true; long delta = now - lastEvent; if (delta < this.minPeriodPerConsumer) { Long lastConnectionEvent = this.connectionLastEvent.getOrDefault(connectionId, lastEvent); delta = now - lastConnectionEvent; if (delta <= this.maxPeriodPerConnection) { propagate = false; if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Dropping {} event for {}; last consumer event = {}; last connection event = {}", activeMQDestination, connectionId, Instant.ofEpochMilli(lastEvent), Instant.ofEpochMilli(lastConnectionEvent)); } } } if (propagate) { filteredConsumers.add(consumer); if (this.consumerLastEvent.replace(consumerId, lastEvent, now)) { this.connectionLastEvent.compute(connectionId, (key, previous) -> previous == null || previous < now ? now : previous); } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Dispatching {} event for {}", activeMQDestination, connectionId); } } } } return filteredConsumers; }
From source file:org.janusgraph.graphdb.olap.job.IndexUpdateJob.java
public void workerIterationStart(JanusGraph graph, Configuration config, ScanMetrics metrics) { this.graph = (StandardJanusGraph) graph; Preconditions.checkArgument(config.has(GraphDatabaseConfiguration.JOB_START_TIME), "Invalid configuration for this job. Start time is required."); this.jobStartTime = Instant.ofEpochMilli(config.get(GraphDatabaseConfiguration.JOB_START_TIME)); if (indexName == null) { Preconditions.checkArgument(config.has(INDEX_NAME), "Need to configure the name of the index to be repaired"); indexName = config.get(INDEX_NAME); indexRelationTypeName = config.get(INDEX_RELATION_TYPE); log.info("Read index information: name={} type={}", indexName, indexRelationTypeName); }//w ww. j a va2 s. co m try { this.mgmt = (ManagementSystem) graph.openManagement(); if (isGlobalGraphIndex()) { index = mgmt.getGraphIndex(indexName); } else { indexRelationType = mgmt.getRelationType(indexRelationTypeName); Preconditions.checkArgument(indexRelationType != null, "Could not find relation type: %s", indexRelationTypeName); index = mgmt.getRelationIndex(indexRelationType, indexName); } Preconditions.checkArgument(index != null, "Could not find index: %s [%s]", indexName, indexRelationTypeName); log.info("Found index {}", indexName); validateIndexStatus(); StandardTransactionBuilder txb = this.graph.buildTransaction(); txb.commitTime(jobStartTime); writeTx = (StandardJanusGraphTx) txb.start(); } catch (final Exception e) { if (null != mgmt && mgmt.isOpen()) mgmt.rollback(); if (writeTx != null && writeTx.isOpen()) writeTx.rollback(); metrics.incrementCustom(FAILED_TX); throw new JanusGraphException(e.getMessage(), e); } }
From source file:com.epam.ta.reportportal.database.UniqueBugDocumentHandler.java
public Map<String, List<ChartObject>> getResult() { // Sorting// ww w . j a v a 2 s .c o m for (Map.Entry<String, List<ChartObject>> entry : result.entrySet()) { Collections.sort(entry.getValue(), (o1, o2) -> { Instant one = Instant.ofEpochMilli(Long.valueOf(o1.getStartTime())); Instant next = Instant.ofEpochMilli(Long.valueOf(o2.getStartTime())); return one.compareTo(next); }); result.put(entry.getKey(), entry.getValue()); } return result; }
From source file:RequestStat.java
private String getDateFromInstant(long start) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd " + "HH:mm:ss") .withZone(ZoneId.systemDefault()); return formatter.format(Instant.ofEpochMilli(start)); }
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();/*from w w w .j a va2 s . com*/ Instant expiration = Instant.ofEpochMilli(token.getKeyCreationTime()).plus(Duration.ofMinutes(expiredTime)); boolean before = now.isBefore(expiration); return before; }
From source file:de.qaware.chronix.solr.ingestion.format.InfluxDbFormatParser.java
/** * Extracts the metric timestamp from the parts. * * @param parts Parts.//from ww w. j a v a2s. c om * @return Metric timestamp. * @throws FormatParseException If something went wrong while extracting. */ private Instant getMetricTimestamp(String[] parts) throws FormatParseException { // Timestamp is optional. If it's missing, use the local server time if (parts.length < 3) { return clock.now(); } String value = parts[2]; try { long epochTime = Long.parseLong(value); // epochTime is in nanoseconds, convert to milliseconds return Instant.ofEpochMilli(epochTime / 1000); } catch (NumberFormatException e) { throw new FormatParseException("Can't convert '" + value + "' to long", e); } }
From source file:it.tidalwave.northernwind.frontend.media.impl.DefaultMetadataCacheTest.java
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod/*w w w . j a va2s .c o m*/ public void setup() throws Exception { context = helper.createSpringContext(); underTest = context.getBean(DefaultMetadataCache.class); underTest.setClock(() -> mockClock); metadataLoader = context.getBean(MetadataLoader.class); mediaFile = mock(ResourceFile.class); tiff = new TIFF(); exif = new EXIF(); iptc = new IPTC(); xmp = new XMP(); image = new ImageTestBuilder().withTiff(tiff).withExif(exif).withIptc(iptc).withXmp(xmp).build(); siteNodeProperties = mock(ResourceProperties.class); mediaId = new Id("mediaId"); when(metadataLoader.findMediaResourceFile(same(siteNodeProperties), eq(mediaId))).thenReturn(mediaFile); // Don't use 'thenReturn(new DefaultMetadata(image))' as a new instance must be created each time when(metadataLoader.loadMetadata(same(mediaFile))).thenAnswer(new Answer<DefaultMetadata>() { @Override public DefaultMetadata answer(final @Nonnull InvocationOnMock invocation) { return new DefaultMetadata("media.jpg", image); } }); assertThat(underTest.getMedatataExpirationTime(), is(DefaultMetadataCache.DEFAULT_METADATA_EXPIRATION_TIME)); initialTime = Instant.ofEpochMilli(1369080000000L).atZone(ZoneId.of("GMT")); setTime(initialTime); }
From source file:com.bdb.weather.display.summary.TemperatureDeviationPlotPanel.java
public TemperatureDeviationPlotPanel(SummaryInterval interval, ViewLauncher theLauncher, SummarySupporter theSupporter) { this.setPrefSize(500, 300); this.interval = interval; chart = ChartFactory.createXYBarChart("Deviation from Average Temperature", "Date", true, "Deviation (" + Temperature.getDefaultUnit() + ")", null, PlotOrientation.VERTICAL, true, true, false);/*from w ww .j av a 2s. com*/ chartViewer = new ChartViewer(chart); chartViewer.setPrefSize(500, 300); chartViewer.addChartMouseListener(new ChartMouseListenerFX() { @Override public void chartMouseClicked(ChartMouseEventFX event) { ChartEntity entity = event.getEntity(); // // Was a point on the plot selected? // if (entity instanceof XYItemEntity) { XYItemEntity itemEntity = (XYItemEntity) entity; XYDataset dataset = itemEntity.getDataset(); Number x = dataset.getXValue(itemEntity.getSeriesIndex(), itemEntity.getItem()); LocalDate date = LocalDate.from(Instant.ofEpochMilli(x.longValue())); boolean doubleClick = event.getTrigger().getClickCount() == 2; if (doubleClick) { supporter.launchView(launcher, date); } } } @Override public void chartMouseMoved(ChartMouseEventFX event) { // Do nothing } }); deviationPlot = (XYPlot) chart.getPlot(); this.launcher = theLauncher; this.supporter = theSupporter; DateFormat dateFormat = interval.getLegacyFormat(); StandardXYItemLabelGenerator labelGen = new StandardXYItemLabelGenerator( StandardCategoryItemLabelGenerator.DEFAULT_LABEL_FORMAT_STRING, dateFormat, Temperature.getDefaultFormatter()); StandardXYToolTipGenerator ttGen = new StandardXYToolTipGenerator( StandardCategoryToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT_STRING, dateFormat, Temperature.getDefaultFormatter()); valueAxis = deviationPlot.getRangeAxis(); valueAxis.setUpperMargin(.20); valueAxis.setLowerMargin(.20); deviationPlot.getDomainAxis().setVerticalTickLabels(true); DateAxis dateAxis = (DateAxis) deviationPlot.getDomainAxis(); dateAxis.setDateFormatOverride(dateFormat); //dateAxis.setTickUnit(interval.getDateTickUnit()); //DefaultTableColumnModel colModel = new DefaultTableColumnModel(); dataTable = new TableView(); //dataTable.setModel(tableModel); //dataTable.setColumnModel(colModel); //dataTable.setAutoCreateColumnsFromModel(false); for (int i = 0; i < TABLE_HEADINGS.length; i++) { TableColumn col = new TableColumn(); col.setText(TABLE_HEADINGS[i]); //col.setModelIndex(i); //colModel.addColumn(col); } //tableModel.setColumnCount(TABLE_HEADINGS.length); this.setTabContents(chartViewer, dataTable); lowRenderer.setBasePaint(Color.BLUE); lowRenderer.setBaseItemLabelGenerator(labelGen); lowRenderer.setBaseToolTipGenerator(ttGen); lowRenderer.setBarAlignmentFactor(.6); lowRenderer.setShadowVisible(false); meanRenderer.setSeriesPaint(0, Color.CYAN); meanRenderer.setBaseItemLabelGenerator(labelGen); meanRenderer.setBaseToolTipGenerator(ttGen); meanRenderer.setBarAlignmentFactor(.3); meanRenderer.setShadowVisible(false); highRenderer.setSeriesPaint(0, Color.GRAY); highRenderer.setBaseItemLabelGenerator(labelGen); highRenderer.setBaseToolTipGenerator(ttGen); highRenderer.setShadowVisible(false); }
From source file:org.dcache.ftp.door.GFtpPerfMarker.java
public Optional<Instant> lastUpdated() { return _hasBeenUpdated ? Optional.of(Instant.ofEpochMilli(_timeStamp)) : Optional.empty(); }
From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java
private static Article fillArticle(Status status) { Article article = new Article(); article.setTitle(status.getUser().getName()); article.setDescription(status.getText()); article.setBody(status.getText());//from w w w .j a v a 2s. c o m article.setSource(SourceUtils.TWITTER); for (MediaEntity mediaEntity : status.getMediaEntities()) { if (!mediaEntity.getType().equals("video")) { article.setUrlToImage(mediaEntity.getMediaURL()); break; } } if (article.getUrlToImage().isEmpty()) { article.setUrlToImage(status.getUser().getBiggerProfileImageURL()); } article.setUrl("https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId()); article.setId(status.getId() + ""); article.setAuthor("@" + status.getUser().getScreenName()); Date date = status.getCreatedAt(); Instant instant = Instant.ofEpochMilli(date.getTime()); LocalDateTime createdAt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC); article.setPublishedAt(createdAt.toString()); return article; }