List of usage examples for org.joda.time Duration Duration
public Duration(ReadableInstant start, ReadableInstant end)
From source file:net.sourceforge.fenixedu.domain.time.chronologies.durationFields.AcademicSemestersDurationField.java
License:Open Source License
@Override public long add(long instant, int value) { int academicSemester = chronology.getAcademicSemester(instant); if (academicSemester != 0) { AcademicSemesterCE academicSemesterCE = chronology.getAcademicSemesterIn(academicSemester); AcademicSemesterCE academicSemesterCEAfter = chronology.getAcademicSemesterIn(academicSemester + value); if (academicSemesterCEAfter != null) { long result = academicSemesterCEAfter.getBegin().getMillis() + new Duration(academicSemesterCE.getBegin().getMillis(), instant).getMillis(); return result < academicSemesterCE.getEnd().getMillis() ? result : academicSemesterCE.getEnd().getMillis(); }/*w w w . j av a2s .c om*/ } throw unsupported(); }
From source file:net.sourceforge.fenixedu.domain.time.chronologies.durationFields.AcademicSemestersDurationField.java
License:Open Source License
@Override public long getMillis(int value, long instant) { int academicSemester = chronology.getAcademicSemester(instant); if (academicSemester != 0) { AcademicSemesterCE academicSemesterCE = chronology.getAcademicSemesterIn(academicSemester); AcademicSemesterCE academicSemesterCEAfter = chronology.getAcademicSemesterIn(academicSemester + value); if (academicSemesterCEAfter != null) { long result = academicSemesterCEAfter.getBegin().getMillis() + new Duration(academicSemesterCE.getBegin().getMillis(), instant).getMillis(); return result < academicSemesterCE.getEnd().getMillis() ? result - instant : academicSemesterCE.getEnd().getMillis() - instant; }/*w w w. jav a 2s . co m*/ } throw unsupported(); }
From source file:net.sourceforge.fenixedu.domain.time.chronologies.durationFields.AcademicYearsDurationField.java
License:Open Source License
@Override public long add(long instant, int value) { int academicYear = chronology.getAcademicYear(instant); if (academicYear != 0) { AcademicYearCE academicYearCE = chronology.getAcademicYearIn(academicYear); AcademicYearCE academicYearCEAfter = chronology.getAcademicYearIn(academicYear + value); if (academicYearCEAfter != null) { long result = academicYearCEAfter.getBegin().getMillis() + new Duration(academicYearCE.getBegin().getMillis(), instant).getMillis(); return result < academicYearCE.getEnd().getMillis() ? result : academicYearCE.getEnd().getMillis(); }/*from ww w.j a va 2s .c om*/ } throw unsupported(); }
From source file:net.sourceforge.fenixedu.domain.time.chronologies.durationFields.AcademicYearsDurationField.java
License:Open Source License
@Override public long getMillis(int value, long instant) { int academicYear = chronology.getAcademicYear(instant); if (academicYear != 0) { AcademicYearCE academicYearCE = chronology.getAcademicYearIn(academicYear); AcademicYearCE academicYearCEAfter = chronology.getAcademicYearIn(academicYear + value); if (academicYearCEAfter != null) { long result = academicYearCEAfter.getBegin().getMillis() + new Duration(academicYearCE.getBegin().getMillis(), instant).getMillis(); return result < academicYearCE.getEnd().getMillis() ? result - instant : academicYearCE.getEnd().getMillis() - instant; }// ww w . j a va 2 s . c o m } throw unsupported(); }
From source file:no.digipost.api.client.MessageSender.java
License:Apache License
public DigipostPublicKey getEncryptionKeyForPrint() { DateTime now = DateTime.now();/*from w w w .j av a 2s . c o m*/ if (printKeyCachedTime == null || new Duration(printKeyCachedTime, now).isLongerThan(Duration.standardMinutes(5))) { log("*** STARTER INTERAKSJON MED API: HENT KRYPTERINGSNKKEL FOR PRINT ***"); Response response = apiService.getEncryptionKeyForPrint(); checkResponse(response); EncryptionKey encryptionKey = response.readEntity(EncryptionKey.class); cachedPrintKey = new DigipostPublicKey(encryptionKey); printKeyCachedTime = now; return cachedPrintKey; } else { log("Bruker cachet krypteringsnkkel for print"); return cachedPrintKey; } }
From source file:org.aludratest.hpalm.listener.HpAlmTestListener.java
License:Apache License
@Override public void newTestStep(RunnerLeaf runnerLeaf, TestStepInfo testStepInfo) { TestCaseData data = (TestCaseData) runnerLeaf.getAttribute("hpalmData"); if (data == null || data.testSteps.isEmpty()) { return;/*from w ww . j a v a2 s . c o m*/ } // log test step to description TestStepData step = data.testSteps.get(data.testSteps.size() - 1); StringBuilder sb = step.sbDescription; for (Attachment attachment : testStepInfo.getAttachments()) { step.attachments.add(attachment); } sb.append("<tr ").append(cellStyle.get(testStepInfo.getTestStatus())).append(">"); // Started String value = ""; DateTime dt = testStepInfo.getStartingTime(); if (dt != null && data.startTime != null) { value = new Duration(data.startTime, dt).getStandardSeconds() + "s"; } sb.append("<td>").append(value).append("</td>"); // Command sb.append("<td>").append(nullAsEmpty(testStepInfo.getCommand())).append("</td>"); // Element Type sb.append("<td>").append(nullAsEmpty(getSingleStringArgument(testStepInfo, ElementType.class))) .append("</td>"); // Element Name sb.append("<td>").append(nullAsEmpty(getSingleStringArgument(testStepInfo, ElementName.class))) .append("</td>"); // Data sb.append("<td>").append(getArgumentsString(testStepInfo, null)).append("</td>"); // Error Message sb.append("<td>").append(nullAsEmpty(testStepInfo.getErrorMessage())).append("</td>"); // Technical Locator sb.append("<td>").append(nullAsEmpty(getSingleStringArgument(testStepInfo, TechnicalLocator.class))) .append("</td>"); // Technical Arguments sb.append("<td>").append(getArgumentsString(testStepInfo, TechnicalArgument.class)).append("</td>"); // Comment sb.append("<td>"); // convert stack trace into comment if (testStepInfo.getError() != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); testStepInfo.getError().printStackTrace(pw); pw.flush(); sb.append(HTMLUtil.escape(sw.toString()).replace("\n", "<br />")); } sb.append("</td>"); sb.append("</tr>"); if (data.alreadyFailed) { return; } // switch last step to FAILED if failed RunStepBuilder lastStep = step.runStepBuilder; switch (testStepInfo.getTestStatus()) { case FAILED: case FAILEDACCESS: case FAILEDAUTOMATION: case FAILEDPERFORMANCE: case INCONCLUSIVE: lastStep.setStatus(RunStepStatus.FAILED); // do not update status of BLOCKED runs if (!RunStepStatus.BLOCKED.displayName() .equals(data.testRunBuilder.create().getStringFieldValue("status"))) { data.testRunBuilder.setStatus(RunStepStatus.FAILED.displayName()); } data.alreadyFailed = true; break; default: break; } }
From source file:org.aludratest.impl.log4testing.AbstractNamedTestLogElementImpl.java
License:Apache License
@Override public synchronized Duration getDuration() { if (startTime == null) { return null; }/* w w w .j av a 2 s . c o m*/ return new Duration(startTime, endTime == null ? new DateTime() : endTime); }
From source file:org.apache.beam.sdk.nexmark.Main.java
License:Apache License
/** Print summary of {@code actual} vs (if non-null) {@code baseline}. */ private static void saveSummary(@Nullable String summaryFilename, Iterable<NexmarkConfiguration> configurations, Map<NexmarkConfiguration, NexmarkPerf> actual, @Nullable Map<NexmarkConfiguration, NexmarkPerf> baseline, Instant start, NexmarkOptions options) { List<String> lines = new ArrayList<>(); lines.add(""); lines.add(LINE);/* w w w . ja v a 2 s . c o m*/ lines.add(String.format("Run started %s and ran for %s", start, new Duration(start, Instant.now()))); lines.add(""); lines.add("Default configuration:"); lines.add(NexmarkConfiguration.DEFAULT.toString()); lines.add(""); lines.add("Configurations:"); lines.add(" Conf Description"); int conf = 0; for (NexmarkConfiguration configuration : configurations) { lines.add(String.format(" %04d %s", conf++, configuration.toShortString())); NexmarkPerf actualPerf = actual.get(configuration); if (actualPerf != null && actualPerf.jobId != null) { lines.add(String.format(" %4s [Ran as job %s]", "", actualPerf.jobId)); } } lines.add(""); lines.add("Performance:"); lines.add(String.format(" %4s %12s %12s %12s %12s %12s %12s", "Conf", "Runtime(sec)", "(Baseline)", "Events(/sec)", "(Baseline)", "Results", "(Baseline)")); conf = 0; for (NexmarkConfiguration configuration : configurations) { String line = String.format(" %04d ", conf++); NexmarkPerf actualPerf = actual.get(configuration); if (actualPerf == null) { line += "*** not run ***"; } else { NexmarkPerf baselinePerf = baseline == null ? null : baseline.get(configuration); double runtimeSec = actualPerf.runtimeSec; line += String.format("%12.1f ", runtimeSec); if (baselinePerf == null) { line += String.format("%12s ", ""); } else { double baselineRuntimeSec = baselinePerf.runtimeSec; double diff = ((runtimeSec - baselineRuntimeSec) / baselineRuntimeSec) * 100.0; line += String.format("%+11.2f%% ", diff); } double eventsPerSec = actualPerf.eventsPerSec; line += String.format("%12.1f ", eventsPerSec); if (baselinePerf == null) { line += String.format("%12s ", ""); } else { double baselineEventsPerSec = baselinePerf.eventsPerSec; double diff = ((eventsPerSec - baselineEventsPerSec) / baselineEventsPerSec) * 100.0; line += String.format("%+11.2f%% ", diff); } long numResults = actualPerf.numResults; line += String.format("%12d ", numResults); if (baselinePerf == null) { line += String.format("%12s", ""); } else { long baselineNumResults = baselinePerf.numResults; long diff = numResults - baselineNumResults; line += String.format("%+12d", diff); } } lines.add(line); if (actualPerf != null) { List<String> errors = actualPerf.errors; if (errors == null) { errors = new ArrayList<>(); errors.add("NexmarkGoogleRunner returned null errors list"); } for (String error : errors) { lines.add(String.format(" %4s *** %s ***", "", error)); } } } lines.add(LINE); lines.add(""); for (String line : lines) { System.out.println(line); } if (summaryFilename != null) { try { Files.write(Paths.get(summaryFilename), lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND); } catch (IOException e) { throw new RuntimeException("Unable to save summary file: ", e); } NexmarkUtils.console("appended summary to summary file %s.", summaryFilename); } }
From source file:org.apache.beam.sdk.nexmark.Main.java
License:Apache License
/** * Write all perf data and any baselines to a javascript file which can be used by graphing page * etc./*w w w. j av a 2s.c o m*/ */ private static void saveJavascript(@Nullable String javascriptFilename, Iterable<NexmarkConfiguration> configurations, Map<NexmarkConfiguration, NexmarkPerf> actual, @Nullable Map<NexmarkConfiguration, NexmarkPerf> baseline, Instant start) { if (javascriptFilename == null) { return; } List<String> lines = new ArrayList<>(); lines.add(String.format("// Run started %s and ran for %s", start, new Duration(start, Instant.now()))); lines.add("var all = ["); for (NexmarkConfiguration configuration : configurations) { lines.add(" {"); lines.add(String.format(" config: %s", configuration)); NexmarkPerf actualPerf = actual.get(configuration); if (actualPerf != null) { lines.add(String.format(" ,perf: %s", actualPerf)); } NexmarkPerf baselinePerf = baseline == null ? null : baseline.get(configuration); if (baselinePerf != null) { lines.add(String.format(" ,baseline: %s", baselinePerf)); } lines.add(" },"); } lines.add("];"); try { Files.write(Paths.get(javascriptFilename), lines, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); } catch (IOException e) { throw new RuntimeException("Unable to save javascript file: ", e); } NexmarkUtils.console("saved javascript to file %s.", javascriptFilename); }
From source file:org.apache.beam.sdk.nexmark.NexmarkLauncher.java
License:Apache License
/** * Monitor the performance and progress of a running job. Return final performance if it was * measured.// w w w .java2 s .co m */ @Nullable private NexmarkPerf monitor(NexmarkQuery query) { if (!options.getMonitorJobs()) { return null; } if (configuration.debug) { NexmarkUtils.console("Waiting for main pipeline to 'finish'"); } else { NexmarkUtils.console("--debug=false, so job will not self-cancel"); } PipelineResult job = mainResult; PipelineResult publisherJob = publisherResult; List<NexmarkPerf.ProgressSnapshot> snapshots = new ArrayList<>(); long startMsSinceEpoch = System.currentTimeMillis(); long endMsSinceEpoch = -1; if (options.getRunningTimeMinutes() != null) { endMsSinceEpoch = startMsSinceEpoch + Duration.standardMinutes(options.getRunningTimeMinutes()).getMillis() - Duration.standardSeconds(configuration.preloadSeconds).getMillis(); } long lastActivityMsSinceEpoch = -1; NexmarkPerf perf = null; boolean waitingForShutdown = false; boolean cancelJob = false; boolean publisherCancelled = false; List<String> errors = new ArrayList<>(); while (true) { long now = System.currentTimeMillis(); if (endMsSinceEpoch >= 0 && now > endMsSinceEpoch && !waitingForShutdown) { NexmarkUtils.console("Reached end of test, cancelling job"); try { cancelJob = true; job.cancel(); } catch (IOException e) { throw new RuntimeException("Unable to cancel main job: ", e); } if (publisherResult != null) { try { publisherJob.cancel(); } catch (IOException e) { throw new RuntimeException("Unable to cancel publisher job: ", e); } publisherCancelled = true; } waitingForShutdown = true; } PipelineResult.State state = job.getState(); NexmarkUtils.console("%s %s%s", state, queryName, waitingForShutdown ? " (waiting for shutdown)" : ""); NexmarkPerf currPerf; if (configuration.debug) { currPerf = currentPerf(startMsSinceEpoch, now, job, snapshots, query.eventMonitor, query.resultMonitor); } else { currPerf = null; } if (perf == null || perf.anyActivity(currPerf)) { lastActivityMsSinceEpoch = now; } if (options.isStreaming() && !waitingForShutdown) { Duration quietFor = new Duration(lastActivityMsSinceEpoch, now); long fatalCount = new MetricsReader(job, query.getName()).getCounterMetric("fatal"); if (fatalCount == -1) { fatalCount = 0; } if (fatalCount > 0) { NexmarkUtils.console("ERROR: job has fatal errors, cancelling."); errors.add(String.format("Pipeline reported %s fatal errors", fatalCount)); waitingForShutdown = true; cancelJob = true; } else if (configuration.debug && configuration.numEvents > 0 && currPerf.numEvents == configuration.numEvents && currPerf.numResults >= 0 && quietFor.isLongerThan(DONE_DELAY)) { NexmarkUtils.console("streaming query appears to have finished waiting for completion."); waitingForShutdown = true; } else if (quietFor.isLongerThan(STUCK_TERMINATE_DELAY)) { NexmarkUtils.console( "ERROR: streaming query appears to have been stuck for %d minutes, cancelling job.", quietFor.getStandardMinutes()); errors.add(String.format("Cancelling streaming job since it appeared stuck for %d min.", quietFor.getStandardMinutes())); waitingForShutdown = true; cancelJob = true; } else if (quietFor.isLongerThan(STUCK_WARNING_DELAY)) { NexmarkUtils.console("WARNING: streaming query appears to have been stuck for %d min.", quietFor.getStandardMinutes()); } if (cancelJob) { try { job.cancel(); } catch (IOException e) { throw new RuntimeException("Unable to cancel main job: ", e); } } } perf = currPerf; boolean running = true; switch (state) { case UNKNOWN: case UNRECOGNIZED: case STOPPED: case RUNNING: // Keep going. break; case DONE: // All done. running = false; break; case CANCELLED: running = false; if (!cancelJob) { errors.add("Job was unexpectedly cancelled"); } break; case FAILED: case UPDATED: // Abnormal termination. running = false; errors.add("Job was unexpectedly updated"); break; } if (!running) { break; } if (lastActivityMsSinceEpoch == now) { NexmarkUtils.console("new perf %s", perf); } else { NexmarkUtils.console("no activity"); } try { Thread.sleep(PERF_DELAY.getMillis()); } catch (InterruptedException e) { Thread.interrupted(); NexmarkUtils.console("Interrupted: pipeline is still running"); } } perf.errors = errors; perf.snapshots = snapshots; if (publisherResult != null) { NexmarkUtils.console("Shutting down publisher pipeline."); try { if (!publisherCancelled) { publisherJob.cancel(); } publisherJob.waitUntilFinish(Duration.standardMinutes(5)); } catch (IOException e) { throw new RuntimeException("Unable to cancel publisher job: ", e); } } return perf; }