Example usage for org.joda.time Duration Duration

List of usage examples for org.joda.time Duration Duration

Introduction

In this page you can find the example usage for org.joda.time Duration Duration.

Prototype

public Duration(Object duration) 

Source Link

Document

Creates a duration from the specified object using the org.joda.time.convert.ConverterManager ConverterManager .

Usage

From source file:org.apache.druid.server.log.FileRequestLogger.java

License:Apache License

@LifecycleStart
@Override//from w  w w .ja v  a  2 s  .  c o  m
public void start() {
    try {
        baseDir.mkdirs();

        MutableDateTime mutableDateTime = DateTimes.nowUtc().toMutableDateTime(ISOChronology.getInstanceUTC());
        mutableDateTime.setMillisOfDay(0);
        synchronized (lock) {
            currentDay = mutableDateTime.toDateTime(ISOChronology.getInstanceUTC());

            fileWriter = getFileWriter();
        }
        long nextDay = currentDay.plusDays(1).getMillis();
        Duration initialDelay = new Duration(nextDay - System.currentTimeMillis());

        ScheduledExecutors.scheduleWithFixedDelay(exec, initialDelay, Duration.standardDays(1),
                new Callable<ScheduledExecutors.Signal>() {
                    @Override
                    public ScheduledExecutors.Signal call() {
                        try {
                            synchronized (lock) {
                                currentDay = currentDay.plusDays(1);
                                CloseQuietly.close(fileWriter);
                                fileWriter = getFileWriter();
                            }
                        } catch (Exception e) {
                            throw new RuntimeException(e);
                        }

                        return ScheduledExecutors.Signal.REPEAT;
                    }
                });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.apache.gobblin.source.PartitionAwareFileRetrieverUtils.java

License:Apache License

/**
 * Retrieve the lead time duration from the LEAD_TIME and LEAD_TIME granularity config settings.
 *//*from  w  w  w.j a  v a2 s .  c o  m*/
public static Duration getLeadTimeDurationFromConfig(State state) {
    String leadTimeProp = state.getProp(DATE_PARTITIONED_SOURCE_PARTITION_LEAD_TIME);
    if (leadTimeProp == null || leadTimeProp.length() == 0) {
        return DEFAULT_PARTITIONED_SOURCE_PARTITION_LEAD_TIME;
    }

    int leadTime = Integer.parseInt(leadTimeProp);

    DatePartitionType leadTimeGranularity = DEFAULT_DATE_PARTITIONED_SOURCE_PARTITION_LEAD_TIME_GRANULARITY;

    String leadTimeGranularityProp = state.getProp(DATE_PARTITIONED_SOURCE_PARTITION_LEAD_TIME_GRANULARITY);
    if (leadTimeGranularityProp != null) {
        leadTimeGranularity = DatePartitionType.valueOf(leadTimeGranularityProp);
    }

    return new Duration(leadTime * leadTimeGranularity.getUnitMilliseconds());
}

From source file:org.datanucleus.store.types.jodatime.converters.JodaDurationLongConverter.java

License:Open Source License

public Duration toMemberType(Long val) {
    if (val == null) {
        return null;
    }//w  w  w .ja  v  a 2s  . c  om

    return new Duration(((Number) val).longValue());
}

From source file:org.datanucleus.store.types.jodatime.converters.JodaDurationStringConverter.java

License:Open Source License

public Duration toMemberType(String str) {
    if (str == null) {
        return null;
    }/*from  w  ww . jav a 2 s .  c  o m*/

    return new Duration(str);
}

From source file:org.envirocar.server.mongo.convert.DurationConverter.java

License:Open Source License

@Override
@SuppressWarnings("rawtypes")
public Object decode(Class c, Object o, MappedField i) throws MappingException {
    if (o == null) {
        return null;
    } else if (o instanceof Duration) {
        return o;
    } else if (o instanceof Number) {
        return new Duration(((Number) o).longValue());
    } else {/*from w  w w.j a  v a  2  s. c  o m*/
        return new Duration(o);
    }
}

From source file:org.graylog.collector.metrics.MetricServiceConfiguration.java

License:Open Source License

@Inject
public MetricServiceConfiguration(Config config) {
    if (config.hasPath("metrics")) {
        final Config metrics = config.getConfig("metrics");

        this.enableLog = metrics.hasPath("enable-logging") && metrics.getBoolean("enable-logging");

        if (metrics.hasPath("log-duration")) {
            this.reportDuration = new Duration(metrics.getDuration("log-duration", TimeUnit.MILLISECONDS));
        }//from w  w  w  .jav a2s .co  m
    }
}

From source file:org.hawkular.metrics.core.impl.cassandra.ComputeTTL.java

License:Apache License

@Override
public List<T> apply(List<T> data) {
    for (T d : data) {
        Duration duration = new Duration(DateTime.now().minus(d.getWriteTime()).getMillis());
        d.setTTL(originalTTL - duration.toStandardSeconds().getSeconds());
    }/*w  w w . j  a va2 s.c o  m*/
    return data;
}

From source file:org.hawkular.metrics.core.impl.Functions.java

License:Apache License

public static TTLDataPoint<Double> getTTLGaugeDataPoint(Row row, int originalTTL) {
    long writeTime = row.getLong(GAUGE_COLS.WRITE_TIME.ordinal()) / 1000;
    DataPoint<Double> dataPoint = getGaugeDataPoint(row);
    Duration duration = new Duration(now().minus(writeTime).getMillis());
    int newTTL = originalTTL - duration.toStandardSeconds().getSeconds();
    return new TTLDataPoint<>(dataPoint, newTTL);
}

From source file:org.hawkular.metrics.core.impl.Functions.java

License:Apache License

public static TTLDataPoint<AvailabilityType> getTTLAvailabilityDataPoint(Row row, int originalTTL) {
    long writeTime = row.getLong(GAUGE_COLS.WRITE_TIME.ordinal()) / 1000;
    DataPoint<AvailabilityType> dataPoint = getAvailabilityDataPoint(row);
    Duration duration = new Duration(now().minus(writeTime).getMillis());
    int newTTL = originalTTL - duration.toStandardSeconds().getSeconds();
    return new TTLDataPoint<>(dataPoint, newTTL);
}

From source file:org.hawkular.metrics.tasks.api.RepeatingTrigger.java

License:Apache License

private RepeatingTrigger(Long interval, Long delay, Integer repeatCount) {
    if (interval == null && delay == null) {
        throw new IllegalArgumentException("Both [interval] and [delay] cannot be null");
    }//  www. j  av  a2  s  .  co m
    this.interval = interval;
    this.delay = delay == null ? 0 : delay;
    this.repeatCount = repeatCount;
    this.executionCount = 1;

    triggerTime = getExecutionTime(now.get() + this.delay, new Duration(interval)).getMillis();
}