List of usage examples for org.joda.time Period toStandardDuration
public Duration toStandardDuration()
From source file:com.claresco.tinman.json.XapiResultJson.java
License:Open Source License
@Override public XapiResult deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException { JsonObject theResult = JsonUtility.convertJsonElementToJsonObject(arg0); XapiScore theScore = JsonUtility.delegateDeserialization(arg2, JsonUtility.findJsonElementWithKey(theResult, "score"), XapiScore.class); Boolean theSuccess = JsonUtility.getElementAsBool(theResult, "success"); Boolean theCompletion = JsonUtility.getElementAsBool(theResult, "completion"); String theResponse = JsonUtility.getElementAsString(theResult, "response"); String theStringDuration = JsonUtility.getElementAsString(theResult, "duration"); Period thePeriodDuration = null; Duration theDuration = null;//from w ww . j av a 2 s .c o m try { if (theStringDuration != null) { thePeriodDuration = Period.parse(theStringDuration); theDuration = thePeriodDuration.toStandardDuration(); } } catch (IllegalArgumentException e) { throw new XapiBadResultException("Invalid Duration"); } XapiExtension theExtension = null; if (JsonUtility.hasElement(theResult, "extensions")) { theExtension = JsonUtility.delegateDeserialization(arg2, JsonUtility.get(theResult, "extensions"), XapiExtension.class); } XapiResult theResultObject = new XapiResult(theScore, theSuccess, theCompletion, theResponse, theDuration, theExtension); if (theResultObject.isEmpty()) { return null; } return theResultObject; }
From source file:com.hortonworks.releng.hdpbuildredirect.Resource.java
License:Apache License
private static long getTimeout() { PeriodFormatter formatter = new PeriodFormatterBuilder().appendHours().appendSuffix("h").appendMinutes() .appendSuffix("m").appendSeconds().appendSuffix("s").toFormatter(); Period period = formatter.parsePeriod(System.getProperty("cache.timeout", "15m")); long millis = period.toStandardDuration().getMillis(); return millis; }
From source file:com.linkedin.pinot.controller.helix.core.relocation.RealtimeSegmentRelocator.java
License:Apache License
private long getRunFrequencySeconds(String timeStr) { long seconds; try {/*from w w w . j ava 2 s . c o m*/ Period p = PERIOD_FORMATTER.parsePeriod(timeStr); seconds = p.toStandardDuration().getStandardSeconds(); } catch (Exception e) { throw new RuntimeException("Invalid time spec '" + timeStr + "' (Valid examples: '3h', '4h30m', '30m')", e); } return seconds; }
From source file:com.linkedin.pinot.core.realtime.impl.kafka.KafkaHighLevelStreamProviderConfig.java
License:Apache License
protected long convertToMs(String timeStr) { long ms = -1; try {/*from ww w. j av a 2s . c om*/ ms = Long.valueOf(timeStr); } catch (NumberFormatException e1) { try { Period p = PERIOD_FORMATTER.parsePeriod(timeStr); Duration d = p.toStandardDuration(); ms = d.getStandardSeconds() * 1000L; } catch (Exception e2) { throw new RuntimeException("Invalid time spec '" + timeStr + "' (Valid examples: '3h', '4h30m')", e2); } } return ms; }
From source file:com.metamx.druid.realtime.firehose.GracefulShutdownFirehose.java
License:Open Source License
public GracefulShutdownFirehose(Firehose firehose, IndexGranularity segmentGranularity, Period windowPeriod) { this.firehose = firehose; this.segmentGranularity = segmentGranularity; this.windowMillis = windowPeriod.toStandardDuration().getMillis() * 2; this.scheduledExecutor = Executors.newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("firehose_scheduled_%d").build()); final long truncatedNow = segmentGranularity.truncate(new DateTime()).getMillis(); final long end = segmentGranularity.increment(truncatedNow); this.rejectionPolicy = new IntervalRejectionPolicyFactory(new Interval(truncatedNow, end)) .create(windowPeriod);/* w w w . j ava2 s. co m*/ }
From source file:com.metamx.druid.realtime.plumber.MessageTimeRejectionPolicyFactory.java
License:Open Source License
@Override public RejectionPolicy create(final Period windowPeriod) { final long windowMillis = windowPeriod.toStandardDuration().getMillis(); return new RejectionPolicy() { private volatile long maxTimestamp = Long.MIN_VALUE; @Override/* w w w . j a va 2 s . co m*/ public DateTime getCurrMaxTime() { return new DateTime(maxTimestamp); } @Override public boolean accept(long timestamp) { maxTimestamp = Math.max(maxTimestamp, timestamp); return timestamp >= (maxTimestamp - windowMillis); } @Override public String toString() { return String.format("messageTime-%s", windowPeriod); } }; }
From source file:com.metamx.druid.realtime.plumber.ServerTimeRejectionPolicyFactory.java
License:Open Source License
@Override public RejectionPolicy create(final Period windowPeriod) { final long windowMillis = windowPeriod.toStandardDuration().getMillis(); return new RejectionPolicy() { @Override/*from ww w.j a v a2s.co m*/ public DateTime getCurrMaxTime() { return new DateTime(); } @Override public boolean accept(long timestamp) { return timestamp >= (System.currentTimeMillis() - windowMillis); } @Override public String toString() { return String.format("serverTime-%s", windowPeriod); } }; }
From source file:com.microsoft.azure.management.servicebus.implementation.TimeSpan.java
License:Open Source License
/** * Gets TimeSpan from given period./* w w w .j ava 2s . c om*/ * * @param period duration in period format * @return TimeSpan */ public static TimeSpan fromPeriod(Period period) { // Normalize (e.g. move weeks to hour part) // Period p = new Period(period.toStandardDuration().getMillis()); return TimeSpan .parse((new TimeSpan().withDays(p.getDays()).withHours(p.getHours()).withMinutes(p.getMinutes()) .withSeconds(p.getSeconds()).withMilliseconds(p.getMillis())).toString()); }
From source file:com.phloc.datetime.PDTUtils.java
License:Apache License
/** * Compare two periods. The problem is, that * <code>period1.equals (period2)</code> is not equal even though they are * semantically equal./*from w w w. j a v a 2 s . co m*/ * * @param aPeriod1 * First period. May not be <code>null</code>. * @param aPeriod2 * Second period. May not be <code>null</code>. * @return negative value if aPeriod1 is less aPeriod2, 0 if equal, or * positive value if aPeriod1 greater aPeriod2 */ public static int compare(@Nonnull final Period aPeriod1, @Nonnull final Period aPeriod2) { return aPeriod1.toStandardDuration().compareTo(aPeriod2.toStandardDuration()); }
From source file:com.tkmtwo.timex.WallClock.java
License:Apache License
/** * Returns a copy of this <code>WallClock</code> plus * the specified <code>Period</code>. * <p>//from w w w. j a va2 s .c om * * <code>Period.toStandardDuration()</code> is used * to calculate seconds. * <p> * * @param p an <code>Period</code> representing the amount of time * @return a <code>WallClock</code> value */ public WallClock plus(Period p) { checkNotNull(p, "Need a Period."); return plus(p.toStandardDuration()); }