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:de.cubeisland.engine.core.util.converter.DurationConverter.java

License:Open Source License

@Override
public Duration fromNode(Node node) throws ConversionException {
    try {// www .  j a va2s.c o  m
        if (node instanceof IntNode) {
            return new Duration(((IntNode) node).getValue().longValue());
        }
        return this.formatter.parsePeriod(node.asText()).toStandardDuration();
    } catch (Exception e) {
        throw ConversionException.of(this, node, "Unknown error while parsing Duration!", e);
    }
}

From source file:de.ifgi.fmt.mongo.conv.DurationConverter.java

License:Open Source License

/**
 * /*from ww  w  .j  a v  a  2 s .  c o  m*/
 * @param c
 * @param o
 * @param i
 * @return
 * @throws MappingException
 */
@Override
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 {
        return new Duration(o);
    }
}

From source file:de.sub.goobi.config.ConfigCore.java

License:Open Source License

/**
 * Request Duration parameter from configuration.
 *
 * @return Parameter as Duration//from   ww w  . j av a2  s.  c o m
 */
public static Duration getDurationParameter(String inParameter, TimeUnit timeUnit, long inDefault) {
    long duration = getLongParameter(inParameter, inDefault);
    return new Duration(TimeUnit.MILLISECONDS.convert(duration, timeUnit));
}

From source file:de.sub.goobi.helper.tasks.EmptyTask.java

License:Open Source License

/**
 * The function getDurationDead() returns the duration the task is dead. If
 * a time of death has not yet been recorded, null is returned.
 *
 * @return the duration since the task died
 *///  w  w  w.java2 s. c  o  m
Duration getDurationDead() {
    if (passedAway == null) {
        return null;
    }
    long elapsed = System.nanoTime() - passedAway;
    return new Duration(TimeUnit.MILLISECONDS.convert(elapsed, TimeUnit.NANOSECONDS));
}

From source file:de.topobyte.osm4j.extra.extracts.TimeTable.java

License:Open Source License

public String htime(String key) {
    long millis = time(key);
    Duration duration = new Duration(millis);
    Period period = duration.toPeriod();

    return formatter.print(period);
}

From source file:de.zib.gndms.common.model.gorfx.types.io.PropertyReadWriteAux.java

License:Apache License

public static FutureTime readFutureTime(@NotNull Properties prop, @NotNull String key) {
    String s = pruneEmptyProperty(prop, key);
    if (s == null)
        return null;

    try {/*w w w.j a va  2 s  .  c  o m*/
        long offsetInMs = Long.parseLong(s.trim());
        return FutureTime.atOffset(new Duration(offsetInMs));
    } catch (NumberFormatException nfe) {
        return FutureTime.atTime(new DateTime(s));
    }
}

From source file:de.zib.gndms.GORFX.action.StagedTransferORQCalculator.java

License:Apache License

@Override
public TransientContract createOffer() throws Exception {

    // create provider staging orq using this this offer type
    AbstractProviderStageInORQCalculator psi_calc = AbstractProviderStageInORQCalculator.class
            .cast(getSystem().getInstanceDir().newORQCalculator(getSystem().getEntityManagerFactory(),
                    GORFXConstantURIs.PROVIDER_STAGE_IN_URI));

    psi_calc.setKey(getKey());//www  .j  av a 2s .c o  m
    psi_calc.setORQArguments(getORQArguments());

    TransientContract c = psi_calc.createOffer();

    if (c.hasExpectedSize()) {
        long s = c.getExpectedSize();

        String src = ServiceHost.getBaseURL().getHost();
        URI dst_uri = destinationURI(getORQArguments().getGridSite());
        String dst = dst_uri.getHost();
        Float ebw = NetworkAuxiliariesProvider.getBandWidthEstimater().estimateBandWidthFromTo(src, dst);

        if (ebw == null)
            throw new RuntimeException("No connection beween" + src + " and " + dst);

        getORQArguments().setActGridSiteURI(dst);

        long ms = NetworkAuxiliariesProvider.calculateTransferTime(s, ebw, 10000);

        c.setDeadline(FutureTime.atOffset(new Duration(ms)));
    }

    return c;
}

From source file:de.zib.gndms.gritserv.typecon.types.FutureTimeXSDReader.java

License:Apache License

public static FutureTime read(FutureTimeT ft) {
    if (ft == null)
        return null;
    if (ft.getTime() == null) {
        return FutureTime.atOffset(new Duration(ft.getOffset()));
    } else/*  w  w  w.ja  va  2s .  c  o m*/
        return FutureTime.atTime(new DateTime(ft.getTime()));
}

From source file:de.zib.gndms.logic.model.gorfx.AbstractTransferORQCalculator.java

License:Apache License

/**
 * PRECONDITION estimateTransferSize and estimateBandWidth or their associated setters
 *              must have been called before.
 * @return The band width NULL if it wasn't estimated yet.
 *//*from w w  w  .j ava 2s. c  om*/
protected TransientContract calculateOffer() {

    // may at least take 10 s to cover comunication overhead.
    long ms = NetworkAuxiliariesProvider.calculateTransferTime(estimatedTransferSize, estimatedBandWidth,
            10000);

    TransientContract ct = new TransientContract();
    ct.setDeadline(FutureTime.atOffset(new Duration(ms)));
    // none means forever
    // ct.setResultValidity( FutureTime.atTime(dat.plusHours( ContractConstants.FILE_TRANSFER_RESULT_VALIDITY )) );

    return ct;
}

From source file:de.zib.gndms.taskflows.filetransfer.server.logic.AbstractTransferQuoteCalculator.java

License:Apache License

/**
 * PRECONDITION estimateTransferSize and estimateBandWidth or their associated setters
 *              must have been called before.
 * @return The band width NULL if it wasn't estimated yet.
 *///from   w  w w  .j a v  a 2 s.c  o m
protected Quote calculateOffer() {

    // may at least take 10 s to cover communication overhead.
    long ms = NetworkAuxiliariesProvider.calculateTransferTime(estimatedTransferSize, estimatedBandWidth,
            10000);

    Quote quote = new Quote();
    quote.setDeadline(FutureTime.atOffset(new Duration(ms)));
    quote.setExpectedSize(estimatedTransferSize);

    return quote;
}