List of usage examples for org.joda.time Duration millis
public static Duration millis(long millis)
From source file:org.graylog2.utilities.SearchUtils.java
License:Open Source License
public static Searches.DateHistogramInterval buildInterval(@Nullable final String intervalParam, final TimeRange timeRange) { if (!isNullOrEmpty(intervalParam)) { final String interval = intervalParam.toUpperCase(Locale.ENGLISH); if (!validateInterval(interval)) { throw new IllegalArgumentException("Invalid interval: \"" + interval + "\""); }// w w w .j a v a 2 s .c o m return Searches.DateHistogramInterval.valueOf(interval); } final Duration duration = Duration.millis(timeRange.getTo().getMillis() - timeRange.getFrom().getMillis()); // This is the same as SearchPage#_determineHistogramResolution() in the UI code if (duration.getStandardHours() < 12) { return Searches.DateHistogramInterval.MINUTE; } else if (duration.getStandardDays() < 3) { return Searches.DateHistogramInterval.HOUR; } else if (duration.getStandardDays() < 30) { return Searches.DateHistogramInterval.DAY; } else if (duration.getStandardDays() < (30 * 2)) { return Searches.DateHistogramInterval.WEEK; } else if (duration.getStandardDays() < (30 * 18)) { return Searches.DateHistogramInterval.MONTH; } else if (duration.getStandardDays() < (365 * 3)) { return Searches.DateHistogramInterval.QUARTER; } else { return Searches.DateHistogramInterval.YEAR; } }
From source file:org.hawkular.metrics.core.jobs.CompressData.java
License:Apache License
public CompressData(MetricsService service, ConfigurationService configurationService) { metricsService = service;/*ww w .j a v a 2 s.c o m*/ Configuration configuration = configurationService.load(CONFIG_ID).toSingle().toBlocking().value(); if (configuration.get("page-size") == null) { pageSize = DEFAULT_PAGE_SIZE; } else { pageSize = Integer.parseInt(configuration.get("page-size")); } if (configuration.get(BLOCK_SIZE) != null) { java.time.Duration parsedDuration = java.time.Duration.parse(configuration.get(BLOCK_SIZE)); blockSize = Duration.millis(parsedDuration.toMillis()); } else { blockSize = DEFAULT_BLOCK_SIZE; } String enabledConfig = configuration.get("enabled", "true"); enabled = Boolean.parseBoolean(enabledConfig); logger.debugf("Job enabled? %b", enabled); }
From source file:org.hawkular.metrics.core.jobs.CompressData.java
License:Apache License
@Override public Completable call(JobDetails jobDetails) { Duration runtimeBlockSize = blockSize; DateTime timeSliceInclusive;//from ww w . j ava2 s.co m Trigger trigger = jobDetails.getTrigger(); if (trigger instanceof RepeatingTrigger) { if (!enabled) { return Completable.complete(); } timeSliceInclusive = new DateTime(trigger.getTriggerTime(), DateTimeZone.UTC).minus(runtimeBlockSize); } else { if (jobDetails.getParameters().containsKey(TARGET_TIME)) { // DateTime parsing fails without casting to Long first Long parsedMillis = Long.valueOf(jobDetails.getParameters().get(TARGET_TIME)); timeSliceInclusive = new DateTime(parsedMillis, DateTimeZone.UTC); } else { logger.error("Missing " + TARGET_TIME + " parameter from manual execution of " + JOB_NAME + " job"); return Completable.complete(); } if (jobDetails.getParameters().containsKey(BLOCK_SIZE)) { java.time.Duration parsedDuration = java.time.Duration .parse(jobDetails.getParameters().get(BLOCK_SIZE)); runtimeBlockSize = Duration.millis(parsedDuration.toMillis()); } } // Rewind to previous timeslice DateTime timeSliceStart = DateTimeService.getTimeSlice(timeSliceInclusive, runtimeBlockSize); long startOfSlice = timeSliceStart.getMillis(); long endOfSlice = timeSliceStart.plus(runtimeBlockSize).getMillis() - 1; Stopwatch stopwatch = Stopwatch.createStarted(); logger.info("Starting compression of timestamps (UTC) between " + startOfSlice + " - " + endOfSlice); Observable<? extends MetricId<?>> metricIds = metricsService.findAllMetrics().map(Metric::getMetricId) .filter(m -> (m.getType() == GAUGE || m.getType() == COUNTER || m.getType() == AVAILABILITY)); PublishSubject<Metric<?>> subject = PublishSubject.create(); subject.subscribe(metric -> { try { this.metricsService.updateMetricExpiration(metric.getMetricId()); } catch (Exception e) { logger.error("Could not update the metric expiration index for metric " + metric.getId() + " of tenant " + metric.getTenantId()); } }); // Fetch all partition keys and compress the previous timeSlice // TODO Optimization - new worker per token - use parallelism in Cassandra (with configured parallelism) return metricsService.compressBlock(metricIds, startOfSlice, endOfSlice, pageSize, subject).doOnError(t -> { subject.onCompleted(); logger.warn("Failed to compress data", t); }).doOnCompleted(() -> { subject.onCompleted(); stopwatch.stop(); logger.info("Finished compressing data in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms"); }); }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.BigIntegerColumnDurationMapper.java
License:Apache License
@Override public Duration fromNonNullValue(BigInteger value) { return Duration.millis(value.divide(BigInteger.valueOf(1000000L)).longValue()); }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.IntegerColumnDurationMapper.java
License:Apache License
@Override public Duration fromNonNullValue(Integer value) { return (value == null ? new Duration(null) : Duration.millis(1000L * value.intValue())); }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.LongColumnDurationMapper.java
License:Apache License
@Override public Duration fromNonNullValue(Long value) { return (value == null ? new Duration(null) : Duration.millis(value)); }
From source file:org.obm.push.protocol.data.TimeZoneConverterImpl.java
License:Open Source License
private int millisToMinutes(int millis) { return Duration.millis(millis).toStandardMinutes().getMinutes(); }
From source file:org.onosproject.restconf.ctl.RestconfDeviceStateMachine.java
License:Apache License
public RestconfDeviceStateMachine(RestconfDevice device) { RestconfDeviceInfo info = device.getDeviceInfo(); this.device = device; connectTimeout = Duration.millis(info.getSocketTimeout()); }
From source file:org.openmrs.module.reporting.dataset.definition.evaluator.RepeatPerTimePeriodDataSetEvaluator.java
License:Open Source License
@Override public DataSet evaluate(DataSetDefinition dataSetDefinition, EvaluationContext evalContext) throws EvaluationException { RepeatPerTimePeriodDataSetDefinition dsd = (RepeatPerTimePeriodDataSetDefinition) dataSetDefinition; Mapped<? extends DataSetDefinition> baseMappedDef = dsd.getBaseDefinition(); MultiParameterDataSetDefinition delegate = new MultiParameterDataSetDefinition( baseMappedDef.getParameterizable()); TimePeriod period = dsd.getRepeatPerTimePeriod(); if (period == null) { throw new IllegalArgumentException("repeatPerTimePeriod is required"); }/*from ww w . j av a 2s.co m*/ DateTime thisPeriodStart = new DateTime(((Date) evalContext.getParameterValue("startDate")).getTime()); DateTime end = new DateTime( DateUtil.getEndOfDayIfTimeExcluded((Date) evalContext.getParameterValue("endDate")).getTime()); while (thisPeriodStart.isBefore(end)) { DateTime nextPeriodStart = thisPeriodStart.plus(period.getJodaPeriod()); boolean lastIteration = !nextPeriodStart.isBefore(end); // i.e. nextPeriodStart >= end DateTime thisPeriodEnd; if (lastIteration) { thisPeriodEnd = end; } else { thisPeriodEnd = nextPeriodStart.minus(Duration.millis(1)); } Map<String, Object> startAndEndDate = new HashMap<String, Object>(); startAndEndDate.put("startDate", thisPeriodStart.toDate()); startAndEndDate.put("endDate", thisPeriodEnd.toDate()); Map<String, Object> iteration = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : baseMappedDef.getParameterMappings().entrySet()) { String iterationParamName = entry.getKey(); Object value = entry.getValue(); if (value instanceof String) { Object evaluated = EvaluationUtil.evaluateExpression((String) value, startAndEndDate); // expressions based on parameters other than startDate/endDate will come out like ${loc} -> "loc" if (value.equals(EvaluationUtil.EXPRESSION_START + evaluated + EvaluationUtil.EXPRESSION_END)) { continue; } value = evaluated; } iteration.put(iterationParamName, value); } delegate.addIteration(iteration); thisPeriodStart = nextPeriodStart; } return dataSetDefinitionService.evaluate(delegate, evalContext); }
From source file:org.springframework.cloud.stream.binder.test.junit.pubsub.PubSubTestSupport.java
License:Apache License
@Override protected void cleanupResource() throws Exception { if (helper != null) { helper.stop(Duration.millis(1000)); } }