Example usage for org.joda.time Duration toPeriod

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

Introduction

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

Prototype

public Period toPeriod() 

Source Link

Document

Converts this duration to a Period instance using the standard period type and the ISO chronology.

Usage

From source file:azkaban.app.Scheduler.java

License:Apache License

private ScheduledFuture<?> schedule(final ScheduledJob schedJob, boolean saveResults) {
    // fail fast if there is a problem with this job
    _jobManager.validateJob(schedJob.getId());

    Duration wait = new Duration(new DateTime(), schedJob.getScheduledExecution());
    if (wait.getMillis() < -1000) {
        logger.warn("Job " + schedJob.getId() + " is scheduled for "
                + DateTimeFormat.shortDateTime().print(schedJob.getScheduledExecution()) + " which is "
                + (PeriodFormat.getDefault().print(wait.toPeriod()))
                + " in the past, adjusting scheduled date to now.");
        wait = new Duration(0);
    }/* www.  j  a va 2  s. com*/

    // mark the job as scheduled
    _scheduled.put(schedJob.getId(), schedJob);

    if (saveResults) {
        try {
            saveSchedule();
        } catch (IOException e) {
            throw new RuntimeException("Error saving schedule after scheduling job " + schedJob.getId());
        }
    }

    ScheduledRunnable runnable = new ScheduledRunnable(schedJob);
    schedJob.setScheduledRunnable(runnable);
    return _executor.schedule(runnable, wait.getMillis(), TimeUnit.MILLISECONDS);
}

From source file:azkaban.app.Scheduler.java

License:Apache License

private void sendSuccessEmail(ScheduledJob job, Duration duration, String senderAddress,
        List<String> emailList) {
    if ((emailList == null || emailList.isEmpty()) && _jobSuccessEmail != null) {
        emailList = Arrays.asList(_jobSuccessEmail);
    }/* w  ww . j  a v a 2 s . c  o  m*/

    if (emailList != null && _mailman != null) {
        try {
            _mailman.sendEmailIfPossible(senderAddress, emailList,
                    "Job '" + job.getId() + "' has completed on " + InetAddress.getLocalHost().getHostName()
                            + "!",
                    "The job '" + job.getId() + "' completed in "
                            + PeriodFormat.getDefault().print(duration.toPeriod()) + ".");
        } catch (UnknownHostException uhe) {
            logger.error(uhe);
        }
    }
}

From source file:ch.eitchnet.android.mabea.MabeaParsing.java

License:Open Source License

public static String toHourMin(Duration duration) {
    return new PeriodFormatterBuilder().appendHours().appendSeparator(":").appendMinutes().toFormatter()
            .print(duration.toPeriod());
}

From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java

License:Apache License

public void setMAXIMUM_EARLIER_DEPARTURE(Duration MAXIMUM_EARLIER_DEPARTURE) {
    if (MAXIMUM_EARLIER_DEPARTURE.toPeriod().toStandardDuration()
            .isLongerThan(HARD_MAXIMUM_EARLIER_DEPARTURE.toPeriod().toStandardDuration())) {
        throw new IllegalArgumentException("Must not be longer than hard maximum.");
    }/* w  w  w .j a  v  a 2  s  . co  m*/
    this.MAXIMUM_EARLIER_DEPARTURE = MAXIMUM_EARLIER_DEPARTURE;
}

From source file:ch.oakmountain.tpa.solver.TrainPathAllocationProblemPruningParameters.java

License:Apache License

public void setMAXIMUM_LATER_ARRIVAL(Duration MAXIMUM_LATER_ARRIVAL) {
    if (MAXIMUM_LATER_ARRIVAL.toPeriod().toStandardDuration()
            .isLongerThan(HARD_MAXIMUM_LATER_ARRIVAL.toPeriod().toStandardDuration())) {
        throw new IllegalArgumentException("Must not be longer than hard maximum.");
    }//from w w w .  j a  v a 2s .co m
    this.MAXIMUM_LATER_ARRIVAL = MAXIMUM_LATER_ARRIVAL;
}

From source file:com.brighttag.agathon.dao.zerg.ZergDaoModule.java

License:Apache License

@Provides
@Singleton// w  w  w.  j  a  va 2 s. co  m
AsyncHttpClientConfig provideAsyncHttpClientConfig(
        @Named(ZERG_CONNECTION_TIMEOUT_PROPERTY) Duration connectionTimeout,
        @Named(ZERG_REQUEST_TIMEOUT_PROPERTY) Duration requestTimeout) {
    PeriodFormatter formatter = PeriodFormat.getDefault();
    log.info("Using connection timeout {} and request timeout {}",
            formatter.print(connectionTimeout.toPeriod()), formatter.print(requestTimeout.toPeriod()));
    return new AsyncHttpClientConfig.Builder().setAllowPoolingConnection(true)
            .setConnectionTimeoutInMs(Ints.saturatedCast(connectionTimeout.getMillis()))
            .setRequestTimeoutInMs(Ints.saturatedCast(requestTimeout.getMillis())).setFollowRedirects(true)
            .setMaximumNumberOfRedirects(3).setMaxRequestRetry(1).build();
}

From source file:com.chiorichan.Loader.java

License:Mozilla Public License

public static String getUptime() {
    Duration duration = new Duration(System.currentTimeMillis() - startTime);
    PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix(" Day(s) ").appendHours()
            .appendSuffix(" Hour(s) ").appendMinutes().appendSuffix(" Minute(s) ").appendSeconds()
            .appendSuffix(" Second(s)").toFormatter();
    return formatter.print(duration.toPeriod());
}

From source file:com.chiorichan.tasks.Timings.java

License:Open Source License

/**
 * Converts the input value into a human readable string, e.g., 0 Day(s) 3 Hour(s) 13 Minutes(s) 42 Second(s).
 *
 * @param seconds The duration in seconds
 * @return Human readable duration string
 *///from   w  ww . j  a  va  2 s.c o m
public static String readoutDuration(Number seconds) {
    Duration duration = new Duration(seconds);
    PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix(" Day(s) ").appendHours()
            .appendSuffix(" Hour(s) ").appendMinutes().appendSuffix(" Minute(s) ").appendSeconds()
            .appendSuffix(" Second(s)").toFormatter();
    return formatter.print(duration.toPeriod());
}

From source file:com.chiorichan.utils.UtilSystem.java

License:Open Source License

public static String uptime() {
    Duration duration = new Duration(System.currentTimeMillis() - AppLoader.startTime);
    PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix(" Day(s) ").appendHours()
            .appendSuffix(" Hour(s) ").appendMinutes().appendSuffix(" Minute(s) ").appendSeconds()
            .appendSuffix(" Second(s)").toFormatter();
    return formatter.print(duration.toPeriod());
}

From source file:com.fengduo.bee.commons.util.StringFormatter.java

License:Open Source License

public static String formatDuration(long durationMs, String prefix) {
    Duration duration = new Duration(durationMs);
    String print = formatter.print(duration.toPeriod());
    return (prefix == null ? "" : prefix) + print + " (" + durationMs + ")ms";
}