Example usage for org.joda.time.format PeriodFormat getDefault

List of usage examples for org.joda.time.format PeriodFormat getDefault

Introduction

In this page you can find the example usage for org.joda.time.format PeriodFormat getDefault.

Prototype

public static PeriodFormatter getDefault() 

Source Link

Document

Gets the default formatter that outputs words in English.

Usage

From source file:org.lilyproject.clientmetrics.LilyMetrics.java

License:Apache License

public void outputLilyServerInfo(PrintStream ps) throws Exception {
    Table table = new Table(ps);
    table.addColumn(30, "Lily server", "s");
    table.addColumn(10, "Version", "s");
    table.addColumn(-1, "IndexerMaster", "s");
    table.addColumn(-1, "Max heap", "f");
    table.addColumn(-1, "Used heap", "f");

    table.finishDefinition();//ww  w  .  ja  v  a2 s .c  om

    List<String> lilyServers = zk.getChildren("/lily/repositoryNodes", false);

    table.fullSepLine();
    table.crossColumn("Information on the Lily servers");
    table.columnSepLine();
    table.titles();
    table.columnSepLine();

    ObjectName lily = new ObjectName("Lily:name=Info");
    ObjectName memory = new ObjectName("java.lang:type=Memory");

    // This data structure is used to collect for each index, and for each server, the timestamp of the
    // last WALEdit processed by the SEP
    Map<String, Map<String, Long>> sepTimestampByIndexAndServer = new HashMap<String, Map<String, Long>>() {
        @Override
        public Map<String, Long> get(Object key) {
            Map<String, Long> value = super.get(key);
            if (value == null) {
                value = new HashMap<String, Long>();
                put((String) key, value);
            }
            return value;
        }
    };

    for (String server : lilyServers) {
        int colonPos = server.indexOf(':');
        String address = server.substring(0, colonPos);

        MBeanServerConnection connection = jmxConnections.getConnector(address, LILY_JMX_PORT)
                .getMBeanServerConnection();
        String version = (String) connection.getAttribute(lily, "Version");
        boolean indexerMaster = (Boolean) connection.getAttribute(lily, "IndexerMaster");

        CompositeDataSupport heapMemUsage = (CompositeDataSupport) connection.getAttribute(memory,
                "HeapMemoryUsage");
        double maxHeapMB = ((double) (Long) heapMemUsage.get("max")) / 1024d / 1024d;
        double usedHeapMB = ((double) (Long) heapMemUsage.get("used")) / 1024d / 1024d;

        table.columns(address, version, String.valueOf(indexerMaster), maxHeapMB, usedHeapMB);

        ObjectName indexUpdaterPattern = new ObjectName("Lily:service=SEP,name=IndexUpdater_*");
        Set<ObjectName> indexUpdaterNames = connection.queryNames(indexUpdaterPattern, null);
        for (ObjectName indexUpdater : indexUpdaterNames) {
            Long lastSepTimestamp = (Long) connection.getAttribute(indexUpdater, "lastSepTimestamp");
            String indexName = indexUpdater.getKeyProperty("name").substring("IndexUpdater_".length());
            sepTimestampByIndexAndServer.get(indexName).put(server, lastSepTimestamp);
        }
    }

    table.columnSepLine();

    if (sepTimestampByIndexAndServer.size() > 0) {
        long now = System.currentTimeMillis();
        ps.println();
        ps.println("SEP: how long ago was the timestamp of the last processed event:");
        for (Map.Entry<String, Map<String, Long>> indexEntry : sepTimestampByIndexAndServer.entrySet()) {
            ps.println("  Index " + indexEntry.getKey());
            for (Map.Entry<String, Long> serverEntry : indexEntry.getValue().entrySet()) {
                Period duration = new Period(now - serverEntry.getValue());
                ps.println("    Server " + serverEntry.getKey() + ": "
                        + PeriodFormat.getDefault().print(duration));
            }
        }
    }
}

From source file:org.n52.sos.ds.hibernate.SosCacheFeederDAO.java

License:Open Source License

private void logCacheLoadTime(long startTime) {
    Period cacheLoadPeriod = new Period(startTime, System.currentTimeMillis());
    LOGGER.info("Cache load finished in {} ({} seconds)",
            PeriodFormat.getDefault().print(cacheLoadPeriod.normalizedStandard()),
            cacheLoadPeriod.toStandardSeconds());
}

From source file:org.openvpms.web.jobs.recordlocking.MedicalRecordLockingScheduler.java

License:Open Source License

/**
 * Initialises the scheduler./*from   w  w  w  . ja  v a2  s  .co m*/
 *
 * @param practice  the practice
 * @param updatedBy the user that updated the practice. May be {@code null}
 * @param user      the user to send audit messages to
 * @param audit     if {@code true}, send an audit message, even if nothing has changed
 */
private void init(final Party practice, final String updatedBy, final User user, final boolean audit) {
    final Period newPeriod = rules.getRecordLockPeriod(practice);
    if (newPeriod == null) {
        boolean enabled = disable();
        if (audit || enabled) {
            String subject = updatedBy != null ? Messages.format("recordlocking.disabled.subjectby", updatedBy)
                    : Messages.get("recordlocking.disabled.subject");
            audit(subject, Messages.get("recordlocking.disabled.message"), user);
        }
    } else {
        TransactionTemplate template = new TransactionTemplate(transactionManager);
        template.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(TransactionStatus status) {
                boolean disabled = enable(user);
                Period current;
                synchronized (this) {
                    current = period;
                }
                if (audit || disabled || !ObjectUtils.equals(current, newPeriod)) {
                    String subject = updatedBy != null && (disabled || !ObjectUtils.equals(current, newPeriod))
                            ? Messages.format("recordlocking.enabled.subjectby", updatedBy)
                            : Messages.get("recordlocking.enabled.subject");
                    String periodStr = PeriodFormat.getDefault().print(newPeriod);
                    audit(subject, Messages.format("recordlocking.enabled.message", periodStr), user);
                }
                synchronized (this) {
                    period = newPeriod;
                }
            }
        });
    }
}

From source file:org.sonatype.nexus.extender.NexusContextListener.java

License:Open Source License

@Override
public void contextDestroyed(final ServletContextEvent event) {
    // event is ignored, apparently can also be null

    // remove our dynamic filter
    if (registration != null) {
        registration.unregister();/*from w  ww .  j a v a 2 s.  com*/
        registration = null;
    }

    // log uptime before triggering activity which may run into problems
    long uptime = ManagementFactory.getRuntimeMXBean().getUptime();
    log.info("Uptime: {}", PeriodFormat.getDefault().print(new Period(uptime)));

    try {
        lifecycleManager.to(LOGGING);

        // dispose of JSR-250 components before logging goes
        injector.getInstance(BeanManager.class).unmanage();

        lifecycleManager.to(BOOT);
    } catch (final Exception e) {
        log.error("Failed to stop nexus", e);
    }

    extender.doStop(); // stop tracking bundles

    if (servletContext != null) {
        servletContext = null;
    }

    injector = null;

    SharedMetricRegistries.remove("nexus");
}

From source file:org.sonatype.nexus.internal.app.NxApplication.java

License:Open Source License

@Override
protected void doStop() throws Exception {
    // log uptime before triggering activity which may run into problems
    long uptime = ManagementFactory.getRuntimeMXBean().getUptime();
    log.info("Uptime: {}", PeriodFormat.getDefault().print(new Period(uptime)));

    // Due to no dependency mechanism in NX for components, we need to fire off a hint about shutdown first
    eventBus.post(new NexusStoppingEvent(this));

    // kill services + notify
    eventBus.post(new NexusStoppedEvent(this));
    eventManager.stop();/*from   ww w  .  j  av  a2  s .co  m*/

    securitySystem.stop();

    // must stop database services manually
    orientBootstrap.stop();

    // dispose of JSR-250
    beanManager.unmanage();
}

From source file:views.helpers.DateHelper.java

License:Open Source License

public static Html readableDuration(Duration duration) {
    if (duration == null) {
        return HtmlFormat.empty();
    }//from  www .ja  va 2 s  .  c o  m

    return views.html.partials.dates.duration.render(duration, PeriodFormat.getDefault());
}