List of usage examples for org.joda.time Duration toStandardSeconds
public Seconds toStandardSeconds()
From source file:com.axelor.apps.crm.service.EventService.java
License:Open Source License
public int getDuration(Duration duration) { return duration.toStandardSeconds().getSeconds(); }
From source file:com.axelor.apps.production.service.OperationOrderWorkflowService.java
License:Open Source License
public long getDuration(Duration duration) { return duration.toStandardSeconds().getSeconds(); }
From source file:com.mastfrog.acteur.util.CacheControl.java
License:Open Source License
public CacheControl add(CacheControlTypes type, Duration value) { if (!type.takesValue) { throw new IllegalArgumentException(type + " requires a value"); }//w w w. j a va2 s . c o m for (Iterator<E> it = entries.iterator(); it.hasNext();) { E e = it.next(); if (e.type == type) { it.remove(); } } entries.add(new E(type, value.toStandardSeconds().getSeconds())); return this; }
From source file:edu.jhu.hlt.concrete.stanford.ConcreteStanfordRunner.java
License:Open Source License
public void run(Path inPath, Path outPath, Analytic<? extends TokenizedCommunication> analytic) { LOGGER.debug("Checking input and output directories."); try {/* w w w.ja va 2 s.c om*/ prepareInputOutput(inPath, outPath); } catch (IOException e) { LOGGER.error("Caught IOException when checking input and output directories.", e); } String lowerOutPathStr = inPath.toString().toLowerCase(); try { sed.disable(); // Outcomes of outPathStr ending: // No valid ending (program exit) // Ends with .concrete (first if) // Ends with .tar (else, first if) // Ends with .tar.gz (else, second if) boolean isTarExt = lowerOutPathStr.endsWith(".tar"); boolean isTarGzExt = lowerOutPathStr.endsWith(".tar.gz") || lowerOutPathStr.endsWith(".tgz"); boolean isConcreteExt = lowerOutPathStr.endsWith(".concrete") || lowerOutPathStr.endsWith(".comm"); int nElementsInitPath = inPath.getNameCount(); Path inputFileName = inPath.getName(nElementsInitPath - 1); // If no extention matches, exit. if (!isTarExt && !isTarGzExt && !isConcreteExt) { LOGGER.error("Input file extension was not '.concrete', '.comm', '.tar', or '.tar.gz'; exiting."); System.exit(1); } else if (isConcreteExt) { // IF .concrete, run single communication. LOGGER.info("Annotating single .concrete file at: {}", inPath.toString()); try (InputStream in = Files.newInputStream(inPath); BufferedInputStream bin = new BufferedInputStream(in, 1024 * 8 * 24);) { byte[] inputBytes = IOUtils.toByteArray(bin); Communication c = ser.fromBytes(inputBytes); WrappedCommunication annotated = analytic.annotate(c); Communication ar = annotated.getRoot(); WritableCommunication wc = new WritableCommunication(ar); if (Files.isDirectory(outPath)) wc.writeToFile(outPath.resolve(inputFileName), true); else wc.writeToFile(outPath, true); } catch (AnalyticException e) { LOGGER.error("Caught exception when running the analytic.", e); } } else { Path localOutPath; if (Files.isDirectory(outPath)) // if directory, use same extension as input. localOutPath = outPath.resolve(inputFileName); else localOutPath = outPath; // Iterate over the archive. AutoCloseableIterator<byte[]> iter; try (InputStream is = Files.newInputStream(inPath); BufferedInputStream bis = new BufferedInputStream(is, 1024 * 8 * 24);) { // open iterator based on file extension iter = isTarExt ? new TarArchiveEntryByteIterator(bis) : new TarGzArchiveEntryByteIterator(bis); try (OutputStream os = Files.newOutputStream(localOutPath); BufferedOutputStream bos = new BufferedOutputStream(os, 1024 * 8 * 24);) { TarArchiver archiver = isTarExt ? new TarArchiver(bos) : new TarArchiver(new GzipCompressorOutputStream(bos)); final StopWatch sw = new StopWatch(); sw.start(); int docCtr = 0; final AtomicInteger tokenCtr = new AtomicInteger(0); LOGGER.info("Iterating over archive: {}", inPath.toString()); while (iter.hasNext()) { Communication n = ser.fromBytes(iter.next()); LOGGER.info("Annotating communication: {}", n.getId()); try { TokenizedCommunication a = analytic.annotate(n); a.getTokenizations().parallelStream() .map(tkzToInt -> tkzToInt.getTokenList().getTokenListSize()) .forEach(ct -> tokenCtr.addAndGet(ct)); archiver.addEntry(new ArchivableCommunication(a.getRoot())); docCtr++; } catch (AnalyticException | IOException | StringIndexOutOfBoundsException e) { LOGGER.error("Caught exception processing document: " + n.getId(), e); } } try { archiver.close(); iter.close(); } catch (Exception e) { // unlikely. LOGGER.info("Caught exception closing iterator.", e); } sw.stop(); Duration rt = new Duration(sw.getTime()); Seconds st = rt.toStandardSeconds(); Minutes m = rt.toStandardMinutes(); int minutesInt = m.getMinutes(); LOGGER.info("Complete."); LOGGER.info("Runtime: approximately {} minutes.", minutesInt); LOGGER.info("Processed {} documents.", docCtr); final int tokens = tokenCtr.get(); LOGGER.info("Processed {} tokens.", tokens); if (docCtr > 0 && minutesInt > 0) { final float minutesFloat = minutesInt; float perMin = docCtr / minutesFloat; LOGGER.info("Processed approximately {} documents/minute.", perMin); LOGGER.info("Processed approximately {} tokens/second.", st.getSeconds() / minutesFloat); } } } } } catch (IOException | ConcreteException e) { LOGGER.error("Caught exception while running the analytic over archive.", e); } }
From source file:org.hawkular.metrics.core.impl.cassandra.ComputeTTL.java
License:Apache License
@Override public List<T> apply(List<T> data) { for (T d : data) { Duration duration = new Duration(DateTime.now().minus(d.getWriteTime()).getMillis()); d.setTTL(originalTTL - duration.toStandardSeconds().getSeconds()); }//from w ww . j av a 2s . c o m return data; }
From source file:org.hawkular.metrics.core.impl.Functions.java
License:Apache License
public static TTLDataPoint<Double> getTTLGaugeDataPoint(Row row, int originalTTL) { long writeTime = row.getLong(GAUGE_COLS.WRITE_TIME.ordinal()) / 1000; DataPoint<Double> dataPoint = getGaugeDataPoint(row); Duration duration = new Duration(now().minus(writeTime).getMillis()); int newTTL = originalTTL - duration.toStandardSeconds().getSeconds(); return new TTLDataPoint<>(dataPoint, newTTL); }
From source file:org.hawkular.metrics.core.impl.Functions.java
License:Apache License
public static TTLDataPoint<AvailabilityType> getTTLAvailabilityDataPoint(Row row, int originalTTL) { long writeTime = row.getLong(GAUGE_COLS.WRITE_TIME.ordinal()) / 1000; DataPoint<AvailabilityType> dataPoint = getAvailabilityDataPoint(row); Duration duration = new Duration(now().minus(writeTime).getMillis()); int newTTL = originalTTL - duration.toStandardSeconds().getSeconds(); return new TTLDataPoint<>(dataPoint, newTTL); }