List of usage examples for org.joda.time Period Period
public Period(Object period)
From source file:org.dllearner.core.AbstractCELA.java
License:Open Source License
protected String getDurationAsString(long durationInMillis) { PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d").appendHours() .appendSuffix("h").appendMinutes().appendSuffix("m").appendSeconds().appendSuffix("s") .appendMillis().appendSuffix("ms").printZeroNever().toFormatter(); return formatter.print(new Period(durationInMillis)); }
From source file:org.duracloud.sync.mgmt.SyncSummary.java
License:Apache License
public String getDurationAsString() { long duration = this.stop.getTime() - this.start.getTime(); PeriodFormatter daysHoursMinutes = new PeriodFormatterBuilder().appendDays().appendSuffix(" day", " days") .appendSeparator(" ").appendMinutes().appendSuffix(" min", " min").appendSeparator(" ") .appendSeconds().appendSuffix(" sec", " secs").toFormatter(); Period period = new Period(duration); return daysHoursMinutes.print(period); }
From source file:org.emonocot.harvest.integration.NotifyingJobStatusListener.java
License:Open Source License
@Override public void afterJob(JobExecution jobExecution) { Period duration = new Period(jobExecution.getEndTime().getTime() - jobExecution.getStartTime().getTime()); StringBuffer exitDescription = new StringBuffer(); if (jobExecution.getJobInstance().getJobParameters().getString("resource.identifier") != null) { long info = 0; long warn = 0; long error = 0; Resource resource = resourceService .find(jobExecution.getJobInstance().getJobParameters().getString("resource.identifier")); Map<String, String> selectedFacets = new HashMap<String, String>(); selectedFacets.put("base.class_s", "org.emonocot.model.Annotation"); selectedFacets.put("annotation.job_id_l", new Long(jobExecution.getId()).toString()); try {//w w w.j a v a 2 s. c o m Page<Annotation> result = annotationService.search(null, null, 1, 0, new String[] { "annotation.type_s" }, null, selectedFacets, null, "annotated-obj"); FacetField annotationTypes = result.getFacetField("annotation.type_s"); for (FacetField.Count value : annotationTypes.getValues()) { if (value.getName() == null) { } else { switch (value.getName()) { case "Info": info = value.getCount(); break; case "Warn": warn = value.getCount(); break; case "Error": error = value.getCount(); break; default: break; } } } } catch (SolrServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } exitDescription .append("Harvested " + resource.getTitle() + " " + jobExecution.getExitStatus().getExitCode()); exitDescription.append(". " + jobExecution.getStepExecutions().size() + " Steps Completed."); exitDescription.append(" Duration: " + periodFormatter.print(duration) + "."); exitDescription.append(" Issues - Info: " + info + ", warnings: " + warn + ", Errors: " + error); jobExecution.setExitStatus(jobExecution.getExitStatus().addExitDescription(exitDescription.toString())); jobRepository.update(jobExecution); logger.info(jobExecution.getExitStatus().getExitCode() + " " + jobExecution.getExitStatus().getExitDescription()); User user = userService.find(systemUser); // Create comment if a systemUser exists if (user != null) { Comment comment = new Comment(); comment.setIdentifier(UUID.randomUUID().toString()); comment.setComment(exitDescription.toString()); comment.setCreated(new DateTime()); comment.setStatus(Comment.Status.PENDING); comment.setUser(user); comment.setAboutData(resource); comment.setCommentPage(resource); commentService.save(comment); } } else { exitDescription.append( jobExecution.getJobInstance().getJobName() + " " + jobExecution.getExitStatus().getExitCode()); exitDescription.append(". " + jobExecution.getStepExecutions().size() + " Steps Completed."); exitDescription.append(" Duration: " + periodFormatter.print(duration) + "."); jobExecution.setExitStatus( new ExitStatus(jobExecution.getExitStatus().getExitCode(), exitDescription.toString())); jobRepository.update(jobExecution); logger.info(jobExecution.getExitStatus().getExitCode() + " " + jobExecution.getExitStatus().getExitDescription()); } }
From source file:org.emonocot.model.convert.DurationToStringConverter.java
License:Open Source License
@Override public String convert(Duration source) { if (source == null) { return null; } else {// w w w . j a v a2 s .c o m return formatter.print(new Period(source)); } }
From source file:org.emonocot.portal.view.Functions.java
License:Open Source License
public static String duration(Duration duration) { if (duration == null) { return null; } else {//from w w w . j a v a2s.c o m return PeriodFormat.getDefault().print(new Period(duration)); } }
From source file:org.jadira.usertype.dateandtime.joda.columnmapper.StringColumnPeriodMapper.java
License:Apache License
@Override public Period fromNonNullValue(String s) { int separatorIndex = s.indexOf('{'); if (separatorIndex == -1) { return new Period(s); } else {//ww w . j a v a 2 s .c om Period period = new Period(s.substring(0, separatorIndex)); return period.withPeriodType(determinePeriodType(s.substring(separatorIndex + 1, s.length() - 1))); } }
From source file:org.jasig.portal.events.aggr.PortalEventAggregationManagerImpl.java
License:Apache License
@Value("${org.jasig.portal.event.aggr.PortalEventAggregationManager.dimensionBuffer:P30D}") public void setDimensionBuffer(ReadablePeriod dimensionBuffer) { if (new Period(dimensionBuffer).toStandardDays().getDays() < 1) { throw new IllegalArgumentException("dimensionBuffer must be at least 1 day. Is: " + new Period(dimensionBuffer).toStandardDays().getDays()); }/*from ww w . j a v a 2 s. co m*/ this.dimensionBuffer = dimensionBuffer; }
From source file:org.jasig.portal.events.aggr.PortalEventDimensionPopulatorImpl.java
License:Apache License
@Value("${org.jasig.portal.events.aggr.PortalEventDimensionPopulatorImpl.dimensionBuffer:P30D}") public void setDimensionBuffer(ReadablePeriod dimensionBuffer) { if (new Period(dimensionBuffer).toStandardDays().getDays() < 1) { throw new IllegalArgumentException("dimensionBuffer must be at least 1 day. Is: " + new Period(dimensionBuffer).toStandardDays().getDays()); }//from w w w . j a va2s .c om this.dimensionBuffer = dimensionBuffer; }
From source file:org.kuali.kpme.core.util.TKUtils.java
License:Educational Community License
/** * Method to obtain the timezone offset string for the specified date time. * * Examples:/*from w ww . java2 s. co m*/ * * -0500 * -0800 * * @param date * @return */ public static String getTimezoneOffset(DateTime date) { StringBuilder o = new StringBuilder(); int offsetms = date.getZone().getOffset(date); boolean negative = offsetms < 0; if (negative) offsetms = offsetms * -1; Period period = new Period(offsetms); if (negative) o.append('-'); o.append(StringUtils.leftPad(period.getHours() + "", 2, '0')); o.append(StringUtils.leftPad(period.getMinutes() + "", 2, '0')); return o.toString(); }
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();/*www .j ava 2s.c o m*/ 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)); } } } }