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(ReadableInstant start, ReadableInstant end) 

Source Link

Document

Creates a duration from the given interval endpoints.

Usage

From source file:azkaban.web.pages.FlowExecutionServlet.java

License:Apache License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("application/xhtml+xml");
    Page page = newPage(req, resp, "azkaban/web/pages/flow_instance.vm");
    final FlowManager allFlows = this.getApplication().getAllFlows();

    if (hasParam(req, "job_id")) {
        String jobID = getParam(req, "job_id");
        ExecutableFlow flow = allFlows.createNewExecutableFlow(jobID);

        page.add("id", "0");
        page.add("name", jobID);

        if (flow == null) {
            addError(req, "Job " + jobID + " not found.");
            page.render();/*from  w  w w .  j  a v  a2  s. c o m*/
            return;
        }

        // This will be used the other
        Flow displayFlow = new Flow(flow.getName(), (Props) null);
        fillFlow(displayFlow, flow);
        displayFlow.validateFlow();

        String flowJSON = createJsonFlow(displayFlow);
        page.add("jsonflow", flowJSON);
        page.add("action", "run");
        page.add("joblist", createJsonJobList(displayFlow));
    } else if (hasParam(req, "id")) {
        long id = Long.parseLong(getParam(req, "id"));
        FlowExecutionHolder holder = allFlows.loadExecutableFlow(id);
        ExecutableFlow executableFlow = holder.getFlow();

        // This will be used the other
        Flow displayFlow = new Flow(executableFlow.getName(), (Props) null);
        fillFlow(displayFlow, executableFlow);
        displayFlow.validateFlow();

        String flowJSON = createJsonFlow(displayFlow);
        page.add("jsonflow", flowJSON);
        page.add("id", id);
        if (executableFlow.getStartTime() != null) {
            page.add("startTime", executableFlow.getStartTime());
            if (executableFlow.getEndTime() != null) {
                page.add("endTime", executableFlow.getEndTime());
                page.add("period",
                        new Duration(executableFlow.getStartTime(), executableFlow.getEndTime()).toPeriod());
            } else {
                page.add("period", new Duration(executableFlow.getStartTime(), new DateTime()).toPeriod());
            }
        }

        page.add("showTimes", true);
        page.add("name", executableFlow.getName());
        page.add("action", "restart");
        page.add("joblist", createJsonJobList(displayFlow));
    }

    page.render();
}

From source file:be.agiv.security.AGIVSecurity.java

License:Open Source License

private boolean requireNewToken(SecurityToken securityToken) {
    if (null == securityToken) {
        return true;
    }/*from   w  w  w. j a v  a 2  s . c om*/
    DateTime now = new DateTime();
    DateTime expires = new DateTime(securityToken.getExpires());
    Duration duration = new Duration(now, expires);
    LOG.debug("token validity: " + duration);
    if (duration.isLongerThan(new Duration(this.tokenRetirementDuration))) {
        LOG.debug("reusing security token: " + securityToken.getAttachedReference());
        return false;
    }
    return true;
}

From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java

License:Open Source License

/**
 * Checks whether the given date-times are close enough next to each other.
 * /*from  w  w w. j  a  v a  2s .  c o m*/
 * @param t1
 * @param t2
 * @param millis
 * @throws XAdESValidationException
 */
public static void checkCloseEnough(DateTime t1, DateTime t2, long millis) throws XAdESValidationException {
    Duration dt;
    if (t1.isBefore(t2)) {
        dt = new Duration(t1, t2);
    } else {
        dt = new Duration(t2, t1);
    }
    if (false == dt.isShorterThan(new Duration(millis))) {
        throw new XAdESValidationException(
                "max dt of " + millis + " ms exceeded between " + t1 + " and " + t2 + " with dt = " + dt);
    }
}

From source file:ch.icclab.cyclops.services.iaas.cloudstack.client.CloudStackScheduler.java

License:Open Source License

/**
 * Compute difference between now and closest full hour
 *
 * @return time in milliseconds/*from w  ww . j a va  2 s  . c o  m*/
 */
private long getSecondsToFullHour() {
    DateTime now = new DateTime(DateTimeZone.UTC);
    DateTime hour = now.hourOfDay().roundCeilingCopy();

    // return difference in milliseconds
    return new Duration(now, hour).getMillis();
}

From source file:classes.ManipulaDatas.java

public static long calculaAtraso(String dataVenc, String dataFim) {
    long calculo = 0;

    try {/*  w  ww. j  a  v  a 2 s .  c o m*/
        java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("dd/MM/yyyy"); // criando um modelo de datas
        java.util.Date d1 = df.parse(dataVenc); //passando os valores das Strings para objetos do tipo Date
        java.util.Date d2 = df.parse(dataFim);

        DateTime dtf2 = new DateTime(d2);
        DateTime dtv2 = new DateTime(d1);

        Duration d = new Duration(dtf2, dtv2);
        long dias = (d.getStandardDays()) * -1;

        calculo = dias;
        calc_datas = calculo; //variavel global que armazena o conteudo do calculo

    } catch (ParseException ex) {
        Logger.getLogger(ManipulaDatas.class.getName()).log(Level.SEVERE, null, ex);
    }

    return calc_datas;
}

From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java

License:Open Source License

public void profileWrites(final ProceedingJoinPoint call, final Object model) throws Throwable {
    if (LOGGER.isTraceEnabled()) {
        final DateTime start = new DateTime();
        call.proceed();/*  w  w w  .  j  a v a  2 s  .co  m*/
        logProfileCall(call, model, (new Duration(start, new DateTime()).getMillis()));
    } else {
        call.proceed();
    }
}

From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java

License:Open Source License

public Object profileFind(final ProceedingJoinPoint call) throws Throwable {
    if (LOGGER.isTraceEnabled()) {
        final DateTime start = new DateTime();
        final Object model = call.proceed();
        logProfileCall(call, model, (new Duration(start, new DateTime()).getMillis()));
        return model;
    } else {/*w  w  w  .  ja v  a 2 s.c  om*/
        return call.proceed();
    }
}

From source file:com.aeells.hibernate.profiling.HibernateProfilingInterceptor.java

License:Open Source License

public Object profileFindList(final ProceedingJoinPoint call) throws Throwable {
    if (LOGGER.isTraceEnabled()) {
        final DateTime start = new DateTime();
        @SuppressWarnings({ "unchecked" })
        final List<Object> models = (List<Object>) call.proceed();
        logProfileCall(call, models, (new Duration(start, new DateTime()).getMillis()));
        return models;
    } else {/*  ww  w. ja  v a 2  s  .  com*/
        return call.proceed();
    }
}

From source file:com.almende.bridge.resources.SimulatedResource.java

License:Apache License

/**
 * Gets the current location of this resource.
 *
 * @return the current location/*from   w  ww .j  a va2 s  . c o m*/
 */
public synchronized ObjectNode getCurrentLocation() {
    final ObjectNode result = JOM.createObjectNode();
    if (route != null) {
        final long millis = new Duration(route.routeBase, DateTime.now().plus((long) (Math.random() * 1000)))
                .getMillis();
        double[] pos = null;
        if (getEta().isBeforeNow()) {
            pos = route.route.get(route.route.size() - 1);
            route = null;
        } else {
            double[] last = null;
            for (int i = route.index; i < route.route.size(); i++) {
                double[] item = route.route.get(i);
                if (item[3] > millis) {
                    if (last != null) {
                        double length = item[3] - last[3];
                        double latDiff = item[1] - last[1];
                        double lonDiff = item[0] - last[0];
                        double part = millis - last[3];

                        final double[] loc = new double[4];
                        loc[0] = last[0] + lonDiff * (part / length) + (Math.random() * 0.0001 - 0.00005);
                        loc[1] = last[1] + latDiff * (part / length) + (Math.random() * 0.0001 - 0.00005);
                        loc[2] = 0;
                        loc[3] = millis;
                        pos = loc;
                    } else {
                        pos = item;
                    }
                    break;
                }
                last = item;
                route.index = route.index > 0 ? route.index - 1 : 0;
            }
        }

        if (pos != null) {
            result.put("lon", pos[0]);
            result.put("lat", pos[1]);
            if (route != null) {
                result.put("eta", getEtaString());
            }
            geoJsonPos = pos;
        }
    } else {
        result.put("lon", geoJsonPos[0]);
        result.put("lat", geoJsonPos[1]);
    }
    if (properties.has("icon")) {
        result.put("icon", properties.get("icon").asText());
    }
    result.put("name", getId());
    return result;
}

From source file:com.almende.bridge.resources.SimulatedResource.java

License:Apache License

private void addRouteProperties(Feature feature) {
    if (route != null) {
        feature.setProperty("eta", getEtaString());
        if (getEta().isAfterNow()) {
            Period period = new Duration(DateTime.now(), getEta()).toPeriod();
            feature.setProperty("minutesRemaining", period.toString(MINANDSECS));
            feature.setProperty("etaShort", getEta().toString("kk:mm:ss"));
        } else {//from www .  j a  v  a 2s  .  com
            feature.setProperty("minutesRemaining", 0);
            feature.setProperty("etaShort", "00:00:00");
        }
    }
}