List of usage examples for org.joda.time Period Period
public Period(Object period)
From source file:com.netflix.suro.queue.Queue4Server.java
License:Apache License
@Inject public Queue4Server(ServerConfig config) { if (config.getQueueType().equals("memory")) { queue = new ArrayBlockingQueue<TMessageSet>(config.getQueueSize()); } else {/* ww w . ja v a 2s .c o m*/ isFile = true; try { queue = new FileBlockingQueue<TMessageSet>(config.getFileQueuePath(), config.getFileQueueName(), new Period(config.getFileQueueGCPeriod()).toStandardSeconds().getSeconds(), new MessageSetSerDe(), config.getFileQueueSizeLimit()); } catch (IOException e) { logger.error("Exception on initializing Queue4Server: " + e.getMessage(), e); } } }
From source file:com.netflix.suro.sink.localfile.LocalFileSink.java
License:Apache License
@JsonCreator public LocalFileSink(@JsonProperty("outputDir") String outputDir, @JsonProperty("writer") FileWriter writer, @JsonProperty("notice") Notice notice, @JsonProperty("maxFileSize") long maxFileSize, @JsonProperty("rotationPeriod") String rotationPeriod, @JsonProperty("minPercentFreeDisk") int minPercentFreeDisk, @JsonProperty("queue4Sink") MessageQueue4Sink queue4Sink, @JsonProperty("batchSize") int batchSize, @JsonProperty("batchTimeout") int batchTimeout, @JsonProperty("pauseOnLongQueue") boolean pauseOnLongQueue, @JacksonInject SpaceChecker spaceChecker) { if (!outputDir.endsWith("/")) { outputDir += "/"; }// w ww . jav a2s .com Preconditions.checkNotNull(outputDir, "outputDir is needed"); this.outputDir = outputDir; this.writer = writer == null ? new TextFileWriter(null) : writer; this.maxFileSize = maxFileSize == 0 ? 200 * 1024 * 1024 : maxFileSize; this.rotationPeriod = new Period(rotationPeriod == null ? "PT2m" : rotationPeriod); this.minPercentFreeDisk = minPercentFreeDisk == 0 ? 15 : minPercentFreeDisk; this.notice = notice == null ? new QueueNotice<String>() : notice; this.spaceChecker = spaceChecker; Monitors.registerObject(outputDir.replace('/', '_'), this); initialize("localfile_" + outputDir.replace('/', '_'), queue4Sink == null ? new MemoryQueue4Sink(10000) : queue4Sink, batchSize, batchTimeout, pauseOnLongQueue); }
From source file:com.ning.billing.util.clock.ClockMock.java
License:Apache License
public synchronized void addDeltaFromReality(final long delta) { adjustTo(new Period(delta)); }
From source file:com.phloc.datetime.config.PDTTypeConverterRegistrar.java
License:Apache License
public void registerTypeConverter(@Nonnull final ITypeConverterRegistry aRegistry) { // Register Joda native converters _registerJodaConverter();//from w w w . java2 s. co m // DateTime aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return new DateTime(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(LocalDate.class, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return PDTFactory.createDateTime((LocalDate) aSource); } }); aRegistry.registerTypeConverter(LocalTime.class, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return PDTFactory.createDateTime((LocalTime) aSource); } }); aRegistry.registerTypeConverter(LocalDateTime.class, DateTime.class, new ITypeConverter() { @Nonnull public DateTime convert(@Nonnull final Object aSource) { return PDTFactory.createDateTime((LocalDateTime) aSource); } }); // LocalDateTime aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return new LocalDateTime(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(DateTime.class, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDateTime((DateTime) aSource); } }); aRegistry.registerTypeConverter(LocalDate.class, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDateTime((LocalDate) aSource); } }); aRegistry.registerTypeConverter(LocalTime.class, LocalDateTime.class, new ITypeConverter() { @Nonnull public LocalDateTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDateTime((LocalTime) aSource); } }); // LocalDate aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, LocalDate.class, new ITypeConverter() { @Nonnull public LocalDate convert(@Nonnull final Object aSource) { return new LocalDate(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(DateTime.class, LocalDate.class, new ITypeConverter() { @Nonnull public LocalDate convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDate((DateTime) aSource); } }); aRegistry.registerTypeConverter(LocalDateTime.class, LocalDate.class, new ITypeConverter() { @Nonnull public LocalDate convert(@Nonnull final Object aSource) { return PDTFactory.createLocalDate((LocalDateTime) aSource); } }); // LocalTime aRegistry.registerTypeConverter( new Class<?>[] { String.class, Calendar.class, GregorianCalendar.class, Date.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, LocalTime.class, new ITypeConverter() { @Nonnull public LocalTime convert(@Nonnull final Object aSource) { return new LocalTime(aSource, PDTConfig.getDefaultChronology()); } }); aRegistry.registerTypeConverter(DateTime.class, LocalTime.class, new ITypeConverter() { @Nonnull public LocalTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalTime((DateTime) aSource); } }); aRegistry.registerTypeConverter(LocalDateTime.class, LocalTime.class, new ITypeConverter() { @Nonnull public LocalTime convert(@Nonnull final Object aSource) { return PDTFactory.createLocalTime((LocalDateTime) aSource); } }); // Duration aRegistry.registerTypeConverter(new Class<?>[] { String.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, Duration.class, new ITypeConverter() { @Nonnull public Duration convert(@Nonnull final Object aSource) { return new Duration(aSource); } }); // Duration aRegistry.registerTypeConverter(new Class<?>[] { String.class, AtomicInteger.class, AtomicLong.class, BigDecimal.class, BigInteger.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class }, Period.class, new ITypeConverter() { @Nonnull public Period convert(@Nonnull final Object aSource) { return new Period(aSource); } }); }
From source file:com.quant.TimeSeries.java
License:Open Source License
/** * Computes the time period of the series. *///from w ww.j a v a 2 s . c om private void computeTimePeriod() { Period minPeriod = null; for (int i = beginIndex; i < endIndex; i++) { // For each tick interval... // Looking for the minimum period. long currentPeriodMillis = getTick(i + 1).getEndTime().getMillis() - getTick(i).getEndTime().getMillis(); if (minPeriod == null) { minPeriod = new Period(currentPeriodMillis); } else { long minPeriodMillis = minPeriod.getMillis(); if (minPeriodMillis > currentPeriodMillis) { minPeriod = new Period(currentPeriodMillis); } } } if (minPeriod == null || Period.ZERO.equals(minPeriod)) { // Minimum period not found (or zero ms found) // --> Use a one-day period minPeriod = Period.days(1); } timePeriod = minPeriod; }
From source file:com.rusticisoftware.tincan.Result.java
License:Apache License
public Result(JsonNode jsonNode) throws URISyntaxException { this();//from w w w . j a va 2 s . c o m JsonNode scoreNode = jsonNode.path("score"); if (!scoreNode.isMissingNode()) { this.setScore(new Score(scoreNode)); } JsonNode successNode = jsonNode.path("success"); if (!successNode.isMissingNode()) { this.setSuccess(successNode.booleanValue()); } JsonNode completionNode = jsonNode.path("completion"); if (!completionNode.isMissingNode()) { this.setCompletion(completionNode.booleanValue()); } JsonNode durationNode = jsonNode.path("duration"); if (!durationNode.isMissingNode()) { this.setDuration(new Period(durationNode.textValue())); } JsonNode responseNode = jsonNode.path("response"); if (!responseNode.isMissingNode()) { this.setResponse(responseNode.textValue()); } JsonNode extensionsNode = jsonNode.path("extensions"); if (!extensionsNode.isMissingNode()) { this.setExtensions(new Extensions(extensionsNode)); } }
From source file:com.stratio.ingestion.sink.druid.DruidSink.java
License:Apache License
private Service buildDruidService() { curator = buildCurator();/*www . j av a 2 s . c om*/ final TimestampSpec timestampSpec = new TimestampSpec(timestampField, "auto"); final Timestamper<Map<String, Object>> timestamper = getTimestamper(); final DruidLocation druidLocation = DruidLocation.create(indexService, firehosePattern, dataSource); final DruidRollup druidRollup = DruidRollup.create(DruidDimensions.specific(dimensions), aggregators, queryGranularity); final ClusteredBeamTuning clusteredBeamTuning = ClusteredBeamTuning.builder() .segmentGranularity(segmentGranularity).windowPeriod(new Period(period)).partitions(partitions) .replicants(replicants).build();//TODO revise return DruidBeams.builder(timestamper).curator(curator).discoveryPath(discoveryPath).location(druidLocation) .timestampSpec(timestampSpec).rollup(druidRollup).tuning(clusteredBeamTuning).buildJavaService(); }
From source file:com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetricAssessor.java
License:Apache License
@Override @SuppressWarnings("unchecked") public void assess(FeedOnTimeArrivalMetric metric, MetricAssessmentBuilder builder) { LOG.debug("Assessing metric: ", metric); builder.metric(metric);//from ww w .j a v a 2 s .c om String feedName = metric.getFeedName(); DateTime lastFeedTime = feedProvider.getLastActiveTimeStamp(feedName); HashMap<String, String> data = new HashMap<>(); data.put("feed", feedName); Long nowDiff = 0L; Period nowDiffPeriod = new Period(nowDiff.longValue()); if (lastFeedTime != null) { nowDiff = DateTime.now().getMillis() - lastFeedTime.getMillis(); nowDiffPeriod = new Period(nowDiff.longValue()); } Long latePeriodMillis = metric.getLatePeriod().toStandardDuration().getMillis(); Long duration = CronExpressionUtil.getCronInterval(metric.getExpectedExpression()); Period acceptedPeriod = new Period(duration + latePeriodMillis); Date expectedDate = CronExpressionUtil.getPreviousFireTime(metric.getExpectedExpression()); DateTime expectedTime = new DateTime(expectedDate); LOG.debug("Calculated the Expected Date to be {} ", expectedTime); DateTime lateTime = expectedTime.plus(metric.getLatePeriod()); LOG.debug("CurrentTime is: {}. Comparing {} against the lateTime of {} ", DateTime.now(), lastFeedTime, lateTime); builder.compareWith(expectedDate, feedName); data.put("expectedTime", expectedTime.toString()); data.put("expectedTimeMillis", expectedTime.getMillis() + ""); data.put("lateTime", expectedTime.toString()); data.put("lateTimeMillis", expectedTime.getMillis() + ""); if (lastFeedTime != null) { data.put("lastFeedTime", lastFeedTime.toString()); data.put("lastFeedTimeMillis", lastFeedTime.getMillis() + ""); } builder.data(data); if (lastFeedTime == null) { LOG.debug("Feed with the specified name {} not found", feedName); builder.message("Feed with the specified name " + feedName + " not found ") .result(AssessmentResult.WARNING); } else if (lastFeedTime.isAfter(expectedTime) && lastFeedTime.isBefore(lateTime)) { LOG.debug("Data for feed {} arrived on {}, which was before late time: {}", feedName, lastFeedTime, lateTime); builder.message("Data for feed " + feedName + " arrived on " + lastFeedTime + ", which was before late time: " + lateTime).result(AssessmentResult.SUCCESS); } else if (lastFeedTime.isAfter(lateTime)) { LOG.debug("Data for feed {} has not arrived before the late time: {} ", feedName, lateTime); builder.message("Data for feed " + feedName + " has not arrived before the late time: " + lateTime + "\n The last successful feed was on " + lastFeedTime).result(AssessmentResult.FAILURE); } else if (nowDiff <= (duration + latePeriodMillis)) { LOG.debug( "Data for feed {} has arrived before the late time: {}. The last successful feed was on {}. It has been {} since data has arrived. The allowed duration is {} ", feedName, lateTime, lastFeedTime, DateTimeUtil.formatPeriod(nowDiffPeriod), DateTimeUtil.formatPeriod(acceptedPeriod)); builder.message( "Data for feed " + feedName + " has arrived on time. \n The last successful feed was on " + lastFeedTime + ". It has been " + DateTimeUtil.formatPeriod(nowDiffPeriod) + " since data has arrived. The allowed duration is " + DateTimeUtil.formatPeriod(acceptedPeriod)) .result(AssessmentResult.SUCCESS); } else if (nowDiff > (duration + latePeriodMillis)) { //error its been greater that the duration of the cron + lateTime LOG.debug( "Data for feed {} has not arrived before the late time: {}. The last successful feed was on {}. It has been {} since data has arrived. The allowed duration is {} ", feedName, lateTime, lastFeedTime, DateTimeUtil.formatPeriod(nowDiffPeriod), DateTimeUtil.formatPeriod(acceptedPeriod)); builder.message( "Data for feed " + feedName + " has not arrived on time. \n The last successful feed was on " + lastFeedTime + ". It has been " + DateTimeUtil.formatPeriod(nowDiffPeriod) + " since data has arrived. The allowed duration is " + DateTimeUtil.formatPeriod(acceptedPeriod)) .result(AssessmentResult.FAILURE); } else if (DateTime.now().isBefore(lateTime)) { //&& lastFeedTime.isBefore(expectedTime) LOG.debug("CurrentTime {} is before the lateTime of {}. Not Assessing", DateTime.now(), lateTime); return; } else { LOG.debug("Data for feed {} has not arrived before the late time: {} ", feedName, lateTime); builder.message("Data for feed " + feedName + " has not arrived before the late time: " + lateTime + "\n The last successful feed was on " + lastFeedTime).result(AssessmentResult.FAILURE); } }
From source file:com.worktoken.engine.TimeExpression.java
License:Apache License
/** * Calculates alarm date for time duration elements * * @return Alarm date or null, if alarm date is in the past *///www . j a va2 s .c om public Date calculateDurationAlarmDate() { DateTime now = new DateTime(); if (endDate != null) { return endDate; } Date start; if (startDate != null) { start = startDate; } else if (duration != null) { start = now.toDate(); } else { throw new IllegalStateException("Invalid duration definition"); } Period period = new Period(duration); Duration dur = period.toStandardDuration(); DateTime alarm; if (dur.getStandardSeconds() > 24 * 60 * 60) { alarm = new DateTime(start).plus(period); } else { alarm = new DateTime(start).plus(dur); } if (alarm.isBefore(now)) { return null; } return alarm.toDate(); }
From source file:cz.klajmajk.camunda.varna.ManagedBean.java
public String getStageEnd(String pid) { Date start = sessionBean.getStageStart(pid); if (start != null) { Long stageLength = ((Long) sessionBean.getSubProcessVariable(pid, "time")) * 60000; Period period = new Period( sessionBean.getStageStart(pid).getTime() + stageLength - new Date().getTime()); return formatter.print(period); }//from w w w .jav a 2 s . c o m return "Neprobh"; }