List of usage examples for org.joda.time DateTime getMillis
public long getMillis()
From source file:com.animedetour.android.schedule.notification.EventNotificationManager.java
License:Open Source License
/** * Schedules an alarm 15 minutes before the specified event. * * This will NOT schedule an alarm if the user has the notification * preference turned off./* w w w .ja v a 2 s. c om*/ * * @param event The event to schedule an alarm for. */ public void scheduleNotification(Event event) { if (false == this.preferenceManager.receiveEventNotifications()) { return; } DateTime notificationTime = event.getStart().minusMinutes(15); if (notificationTime.isBeforeNow()) { return; } this.logger.trace("Scheduling event notification: " + event); PendingIntent intent = this.getEventIntent(event); this.alarmManager.set(AlarmManager.RTC, notificationTime.getMillis(), intent); }
From source file:com.antsoft.framework.datetime.DateTimeTypeHandler.java
License:Apache License
@Override public void setParameter(PreparedStatement preparedStatement, int i, DateTime dateTime, JdbcType jdbcType) throws SQLException { if (dateTime != null) { preparedStatement.setTimestamp(i, new Timestamp(dateTime.getMillis())); } else {/*from w w w.jav a 2 s . c om*/ preparedStatement.setTimestamp(i, null); } }
From source file:com.arpnetworking.kairosdb.aggregators.MovingWindowAggregator.java
License:Apache License
/** * For YEARS, MONTHS, WEEKS, DAYS: Computes the timestamp of the first * millisecond of the day of the timestamp. For HOURS, Computes the timestamp of * the first millisecond of the hour of the timestamp. For MINUTES, Computes the * timestamp of the first millisecond of the minute of the timestamp. For * SECONDS, Computes the timestamp of the first millisecond of the second of the * timestamp. For MILLISECONDS, returns the timestamp * * @param timestamp Timestamp in milliseconds to use as a basis for range alignment * @return timestamp aligned to the configured sampling unit *//*from www. j a va 2 s . c o m*/ @SuppressWarnings("fallthrough") @SuppressFBWarnings("SF_SWITCH_FALLTHROUGH") private long alignRangeBoundary(final long timestamp) { DateTime dt = new DateTime(timestamp, _timeZone); final TimeUnit tu = m_sampling.getUnit(); switch (tu) { case YEARS: dt = dt.withDayOfYear(1).withMillisOfDay(0); break; case MONTHS: dt = dt.withDayOfMonth(1).withMillisOfDay(0); break; case WEEKS: dt = dt.withDayOfWeek(1).withMillisOfDay(0); break; case DAYS: dt = dt.withHourOfDay(0); case HOURS: dt = dt.withMinuteOfHour(0); case MINUTES: dt = dt.withSecondOfMinute(0); case SECONDS: default: dt = dt.withMillisOfSecond(0); break; } return dt.getMillis(); }
From source file:com.arpnetworking.metrics.generator.util.IntervalExecutor.java
License:Apache License
/** * Public constructor.//from w w w . j a va 2s. c o m * * @param start Interval start time. * @param end Interval end time. * @param generators List of UOW generators. * @param outputPath File to write metrics to. * @param clusterName The cluster to generate metrics for. * @param serviceName The service to generate metrics for. */ public IntervalExecutor(final DateTime start, final DateTime end, final List<UnitOfWorkSchedule> generators, final Path outputPath, final String clusterName, final String serviceName) { final long nanoStart = TimeUnit.NANOSECONDS.convert(start.getMillis(), TimeUnit.MILLISECONDS); _nanoEnd = TimeUnit.NANOSECONDS.convert(end.getMillis(), TimeUnit.MILLISECONDS); _workEntries = new PriorityQueue<>(generators.size(), new WorkItemOrdering()); for (final UnitOfWorkSchedule generator : generators) { final long unitStart = generator.getScheduler().next(nanoStart); _workEntries.add(new WorkEntry(generator, unitStart)); } _modifyingSink = new GeneratorSink(outputPath, start); _metricsFactory = new TsdMetricsFactory.Builder().setClusterName(clusterName).setServiceName(serviceName) .setSinks(Collections.<Sink>singletonList(_modifyingSink)).build(); }
From source file:com.arpnetworking.metrics.mad.PeriodWorker.java
License:Apache License
static DateTime getStartTime(final DateTime dateTime, final Period period) { // This effectively uses Jan 1, 1970 at 00:00:00 as the anchor point // for non-standard bucket sizes (e.g. 18 min) that do not divide // equally into an hour or day. Such use cases are rather uncommon. final long periodMillis = period.toStandardDuration().getMillis(); final long dateTimeMillis = dateTime.getMillis(); return new DateTime(dateTimeMillis - (dateTimeMillis % periodMillis), DateTimeZone.UTC); }
From source file:com.arpnetworking.tsdcore.limiter.legacy.DefaultMetricsLimiter.java
License:Apache License
/** * Consider whether a <code>AggregatedData</code> instance should be * processed further given predefined limits on the number of unique * instances./*from w w w. j a v a 2 s. com*/ * * @param data <code>AggregatedData</code> instance to consider. * @param time The current date and time. * @return True if and only if the data was accepted. */ @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "DM_EXIT") public boolean offer(final AggregatedData data, final DateTime time) { final String key = data.getFQDSN().getCluster() + "-" + data.getFQDSN().getService() + "-" + data.getFQDSN().getMetric() + "-" + data.getFQDSN().getStatistic().getName() + "-" + data.getPeriod(); final long now = time.getMillis(); final int nNewAggregations = 1; // We're updating the marks list and it's size together, so need a mutex section synchronized (_updateMarksMutex) { // If the metric is in the marks, list, it is already incorporated in _nAggregations so just add it // to the aggregations if (_marks.containsKey(key)) { _marks.get(key)._time = now; return true; } // Age out metrics to free up some slots if we're going exceed the maximum if (_nAggregations + nNewAggregations > _maxAggregations) { ageOutAggregations(now); } // If we now have enough room, create a marks entry, update _nAggregations and add the aggregations if (_nAggregations + nNewAggregations <= _maxAggregations) { _marks.putIfAbsent(key, new Mark(nNewAggregations, now)); _nAggregations += nNewAggregations; _stateManager.requestWrite(); return true; } } // If we get here, there was no room for the new aggregations, log it (but not too often) and then ignore final Long lastLogged = _lastLogged.get(key); if (lastLogged == null || now - lastLogged.longValue() >= _loggingInterval.getMillis()) { LOGGER.error(String.format("Limited aggregate %s; already aggregating %d", key, Integer.valueOf(_nAggregations))); _lastLogged.put(key, Long.valueOf(now)); } return false; }
From source file:com.attribyte.essem.DefaultResponseGenerator.java
License:Apache License
protected void parseGraph(JsonNode sourceParent, List<String> fields, RateUnit rateUnit, ObjectNode targetMeta, ArrayNode targetGraph) {//w w w. java2 s .c om DateTimeFormatter parser = ISODateTimeFormat.basicDateTime(); Map<MetricKey, ArrayNode> outputGraphs = Maps.newHashMapWithExpectedSize(4); JsonNode hitsObj = sourceParent.get("hits"); if (hitsObj != null) { JsonNode hitsArr = hitsObj.get("hits"); if (hitsArr != null) { for (JsonNode hitObj : hitsArr) { JsonNode fieldsObj = hitObj.get("fields"); if (fieldsObj != null) { MetricKey key = new MetricKey(getStringField(fieldsObj, "name"), getStringField(fieldsObj, "application"), getStringField(fieldsObj, "host"), getStringField(fieldsObj, "instance")); ArrayNode samplesArr = outputGraphs.get(key); if (samplesArr == null) { ObjectNode graphObj = targetGraph.addObject(); addMeta(key, graphObj, targetMeta); samplesArr = graphObj.putArray("samples"); outputGraphs.put(key, samplesArr); } ArrayNode sampleArr = samplesArr.addArray(); DateTime timestamp = parser.parseDateTime(getStringField(fieldsObj, "ts")); sampleArr.add(timestamp.getMillis()); sampleArr.add(1); //Samples.. for (String field : fields) { if (!graphIgnoreProperties.contains(field)) { JsonNode fieldNode = getFieldNode(fieldsObj, field); if (rateUnit == RAW_RATE_UNIT || fieldNode == null || !rateFields.contains(field)) { if (fieldNode != null) { sampleArr.add(fieldNode); } else { sampleArr.addNull(); } } else { sampleArr.add(fieldNode.doubleValue() * rateUnit.mult); } } } } } } } }
From source file:com.attribyte.essem.MGraphResponseGenerator.java
License:Apache License
protected void parseGraph(JsonNode sourceParent, List<String> fields, EnumSet<Option> options, RateUnit rateUnit, ArrayNode targetGraph) { DateTimeFormatter parser = ISODateTimeFormat.basicDateTime(); SimpleDateFormat formatter = new SimpleDateFormat(DT_FORMAT); Map<MetricKey, List<ObjectNode>> outputGraphs = Maps.newHashMapWithExpectedSize(4); JsonNode hitsObj = sourceParent.get("hits"); if (hitsObj != null) { JsonNode hitsArr = hitsObj.get("hits"); if (hitsArr != null) { for (JsonNode hitObj : hitsArr) { JsonNode fieldsObj = hitObj.get("fields"); if (fieldsObj != null) { ObjectNode outObj = mapper.createObjectNode(); DateTime timestamp = parser.parseDateTime(getStringField(fieldsObj, "ts")); outObj.put("timestamp", timestamp.getMillis()); outObj.put("date", formatter.format(timestamp.getMillis())); MetricKey key = new MetricKey(getStringField(fieldsObj, "name"), getStringField(fieldsObj, "application"), getStringField(fieldsObj, "host"), getStringField(fieldsObj, "instance")); Iterator<Map.Entry<String, JsonNode>> fieldIter = fieldsObj.fields(); while (fieldIter.hasNext()) { Map.Entry<String, JsonNode> currField = fieldIter.next(); if (!graphIgnoreProperties.contains(currField.getKey())) { JsonNode currValueNode = currField.getValue(); if (currValueNode.isArray() && currValueNode.size() > 0) { setFieldValue(rateUnit, outObj, currField.getKey(), currValueNode.get(0)); } else if (!currValueNode.isArray()) { setFieldValue(rateUnit, outObj, currField.getKey(), currValueNode); }/* w w w .j a v a 2s .c o m*/ } } List<ObjectNode> graph = outputGraphs.get(key); if (graph == null) { graph = Lists.newArrayListWithExpectedSize(1024); outputGraphs.put(key, graph); } graph.add(outObj); } } } } if (outputGraphs.size() == 1) { List<ObjectNode> graphNodes = outputGraphs.values().iterator().next(); for (ObjectNode outObj : graphNodes) { targetGraph.add(outObj); } } else { for (Map.Entry<MetricKey, List<ObjectNode>> graphEntry : outputGraphs.entrySet()) { MetricKey key = graphEntry.getKey(); ObjectNode outputGraphNode = targetGraph.addObject(); outputGraphNode.put("name", key.name); outputGraphNode.put("application", key.application); outputGraphNode.put("host", key.host); outputGraphNode.put("instance", key.instance); ArrayNode currOutputGraph = outputGraphNode.putArray("graph"); for (ObjectNode outObj : graphEntry.getValue()) { currOutputGraph.add(outObj); } } } }
From source file:com.auditbucket.engine.repo.neo4j.model.TrackLogRelationship.java
License:Open Source License
protected TrackLogRelationship() { DateTime now = new DateTime().toDateTime(DateTimeZone.UTC); this.sysWhen = now.getMillis(); }
From source file:com.auditbucket.engine.repo.neo4j.model.TrackLogRelationship.java
License:Open Source License
public TrackLogRelationship(MetaHeader header, ChangeLog log, DateTime fortressWhen) { this();/*from w w w .j a v a2s. com*/ this.metaHeader = (MetaHeaderNode) header; this.changeLog = (ChangeLogNode) log; if (fortressWhen != null && fortressWhen.getMillis() != 0) { this.fortressWhen = fortressWhen.getMillis(); } else { // "now" in the fortress default timezone this.fortressWhen = new DateTime(sysWhen, DateTimeZone.forTimeZone(TimeZone.getTimeZone(header.getFortress().getTimeZone()))).getMillis(); } }