Example usage for org.apache.commons.lang.time DurationFormatUtils formatDurationWords

List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatDurationWords

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DurationFormatUtils formatDurationWords.

Prototype

public static String formatDurationWords(long durationMillis, boolean suppressLeadingZeroElements,
        boolean suppressTrailingZeroElements) 

Source Link

Document

Formats an elapsed time into a plurialization correct string.

This method formats durations using the days and lower fields of the format pattern.

Usage

From source file:com.evolveum.midpoint.web.page.admin.server.PageTasks.java

private String createCurrentRuntime(IModel<TaskDto> taskModel) {
    TaskDto task = taskModel.getObject();

    if (task.getRawExecutionStatus() == TaskExecutionStatus.CLOSED) {

        //todo i18n and proper date/time formatting
        Long time = task.getCompletionTimestamp();
        if (time == null) {
            return "";
        }/*w  w w .ja  v a2s  .c  o m*/
        return "closed at " + new Date(time).toLocaleString();

    } else {

        Long time = task.getCurrentRuntime();
        if (time == null) {
            return "";
        }

        //todo i18n
        return DurationFormatUtils.formatDurationWords(time, true, true);
    }
}

From source file:com.evolveum.midpoint.web.page.admin.server.PageTasks.java

private String createLastCheckInTime(IModel<NodeDto> nodeModel) {
    NodeDto node = nodeModel.getObject();
    Long time = node.getLastCheckInTime();
    if (time == null || time == 0) {
        return "";
    }/*ww  w  .  j a  va2s . co  m*/

    //todo i18n
    return DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - time, true, true) + " ago";
}

From source file:org.codice.solr.factory.SolrHttpRequestRetryHandler.java

@Override
public boolean retryRequest(IOException e, int retryCount, HttpContext httpContext) {
    if (e instanceof InterruptedIOException) {
        LOGGER.error("Connection timeout.");
    }/*from w ww.java2s  .c  o  m*/
    if (e instanceof UnknownHostException) {
        LOGGER.error("Unknown host.");
    }
    if (e instanceof SSLException) {
        LOGGER.error("SSL handshake exception.");
    }
    LOGGER.debug("Connection failed", e);
    try {
        long waitTime = (long) Math.pow(2, Math.min(retryCount, MAX_RETRY_COUNT)) * 50;
        LOGGER.warn("Connection failed, waiting {} before retrying.",
                DurationFormatUtils.formatDurationWords(waitTime, true, true));
        synchronized (this) {
            wait(waitTime);
        }
    } catch (InterruptedException ie) {
        LOGGER.error("Exception while waiting.", ie);
    }
    return true;
}

From source file:org.jahia.utils.DateUtils.java

/**
 * Returns a human-readable representation of the time taken.
 * /*from ww  w . java 2  s .co  m*/
 * @param durationMillis
 *            the time take in milliseconds
 * @return a human-readable representation of the time taken
 * @see DurationFormatUtils#formatDurationWords(long, boolean, boolean)
 */
public static String formatDurationWords(long durationMillis) {
    if (durationMillis <= 1000) {
        return durationMillis + " ms";
    } else {
        return DurationFormatUtils.formatDurationWords(durationMillis, true, true) + " (" + durationMillis
                + " ms)";
    }
}

From source file:org.pdfsam.console.business.parser.CmdParseManager.java

/**
 * Perform command line parsing/*from w  w w .ja va  2s .c  o  m*/
 * @return true if parsed correctly
 * @throws ConsoleException
 */
public boolean parse() throws ConsoleException {
    stopWatch.reset();
    stopWatch.start();
    boolean retVal = false;
    try {
        if (cmdHandler != null) {
            CmdLineHandler cmdLineHandler = cmdHandler.getCommandLineHandler();
            log.debug("Starting arguments parsing.");
            if (cmdLineHandler != null) {
                retVal = cmdLineHandler.parse(inputArguments);
                if (!retVal) {
                    throw new ParseException(ParseException.ERR_PARSE,
                            new String[] { cmdLineHandler.getParseError() });
                }
            } else {
                throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
            }
        } else {
            throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
        }
    } finally {
        stopWatch.stop();
        log.debug("Command '" + getInputCommand() + "' parsed in "
                + DurationFormatUtils.formatDurationWords(stopWatch.getTime(), true, true));
    }
    return retVal;
}

From source file:org.pdfsam.console.business.parser.CmdParseManager.java

/**
 * Perform command validation/*w ww. j  a v  a  2 s  .co m*/
 * @return parsed command
 * @throws ConsoleException
 */
public AbstractParsedCommand validate() throws ConsoleException {
    stopWatch.reset();
    stopWatch.start();
    AbstractParsedCommand retVal = null;
    try {
        if (cmdHandler != null) {
            CmdLineHandler cmdLineHandler = cmdHandler.getCommandLineHandler();
            log.debug("Starting arguments validation.");
            if (cmdLineHandler != null) {
                if (cmdValidator != null) {
                    retVal = cmdValidator.validate(cmdLineHandler);
                } else {
                    throw new ConsoleException(ConsoleException.CMD_LINE_VALIDATOR_NULL);
                }
            } else {
                throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
            }
        } else {
            throw new ConsoleException(ConsoleException.CMD_LINE_HANDLER_NULL);
        }
    } finally {
        stopWatch.stop();
        log.debug("Command '" + getInputCommand() + "' validated in "
                + DurationFormatUtils.formatDurationWords(stopWatch.getTime(), true, true));
    }
    return retVal;
}

From source file:org.pdfsam.console.business.pdf.CmdExecuteManager.java

/**
 * Executes the input parsed command/*from w w w.j av  a2 s  .  com*/
 * 
 * @param parsedCommand
 * @throws ConsoleException
 */
public void execute(AbstractParsedCommand parsedCommand) throws ConsoleException {
    stopWatch.reset();
    stopWatch.start();
    try {
        if (parsedCommand != null) {
            cmdExecutor = getExecutor(parsedCommand);
            if (cmdExecutor != null) {
                cmdExecutor.addObserver(this);
                cmdExecutor.execute(parsedCommand);
                LOG.info("Command '" + parsedCommand.getCommand() + "' executed in "
                        + DurationFormatUtils.formatDurationWords(stopWatch.getTime(), true, true));
            } else {
                throw new ConsoleException(ConsoleException.CMD_LINE_EXECUTOR_NULL,
                        new String[] { "" + parsedCommand.getCommand() });
            }
        } else {
            throw new ConsoleException(ConsoleException.CMD_LINE_NULL);
        }
    } finally {
        stopWatch.stop();
        cleanExecutor();
    }
}

From source file:org.pdfsam.guiclient.gui.frames.JMainFrame.java

public JMainFrame() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();//from w ww  .  j av  a  2 s. c  o m
    log.info("Starting " + GuiClient.getApplicationName() + " Ver. " + GuiClient.getVersion());
    runSplash();
    ToolTipManager.sharedInstance().setDismissDelay(300000);
    initialize();
    closeSplash();
    stopWatch.stop();
    log.info(GuiClient.getApplicationName() + " Ver. " + GuiClient.getVersion() + " "
            + GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(), "started in ")
            + DurationFormatUtils.formatDurationWords(stopWatch.getTime(), true, true));
}

From source file:org.rundeck.api.domain.RundeckEvent.java

/**
 * @return the duration of the event, as a human-readable string : "3 minutes 34 seconds" (or null if the dates are
 *         invalid)/*from   www .  ja  v  a  2  s  .  c  o  m*/
 */
public String getDuration() {
    Long durationInMillis = getDurationInMillis();
    return durationInMillis != null ? DurationFormatUtils.formatDurationWords(durationInMillis, true, true)
            : null;
}

From source file:org.rundeck.api.domain.RundeckSystemInfo.java

/**
 * @return the uptime of the server, as a human-readable string : "42 days 7 hours 3 minutes 34 seconds"
 *///  w ww  .j a  va2 s  .c  o m
public String getUptime() {
    return uptimeInMillis != null ? DurationFormatUtils.formatDurationWords(uptimeInMillis, true, true) : null;
}