public VomsPlugin(Properties properties) throws CertificateException, CRLException, IOException { caDir = properties.getProperty(CADIR); vomsDir = properties.getProperty(VOMSDIR); trustAnchorsUpdateInterval = getMillis(properties,TRUST_ANCHORS_REFRESH_INTERVAL); checkArgument(caDir != null, "Undefined property: " + CADIR); checkArgument(vomsDir != null, "Undefined property: " + VOMSDIR); checkArgument(trustAnchorsUpdateInterval > 0, TRUST_ANCHORS_REFRESH_INTERVAL + " has to be positive non-zero integer, specified: " + trustAnchorsUpdateInterval); }
public static CharSequence duration(long duration, TimeUnit units, TimeUnitFormat unitFormat) { return appendDuration(new StringBuilder(), duration, units, unitFormat); }
/** * Append a description of some point in time using some reference point. * The appended text is {@code <timestamp> <space> <open-parenth> <integer> * <space> <time-unit-word> <space> <relation> <close-parenth>}. Here are * two examples: * <pre> * 2014-04-20 22:40:32.965 (7 seconds ago) * 2014-04-21 02:40:32.965 (3 hours in the future) * </pre> */ public static StringBuilder appendRelativeTimestamp(StringBuilder sb, long when, long current) { return appendRelativeTimestamp(sb, when, current, TimeUnitFormat.LONG); }
public static String describeDuration(double duration, TimeUnit units) { TimeUnit targetUnits = displayUnitFor(Math.round(duration), units); double scaledDuration = convert(duration, units, targetUnits); return toThreeSigFig(scaledDuration, 2000) + " " + SHORT_TIMEUNIT_NAMES.get(targetUnits); }
public static String describeDuration(StatisticalSummary duration, TimeUnit units) { double min = duration.getMin(); double max = duration.getMax(); if (min == max) { return describeDuration(max, units); } else { double mean = duration.getMean(); double sem = duration.getStandardDeviation() / Math.sqrt(duration.getN()); String meanDescription; if (sem == 0) { meanDescription = describeDuration(mean, units); } else { TimeUnit targetUnits = displayUnitFor(Math.round(mean), units); double scaledMean = convert(mean, units, targetUnits); double scaledSem = convert(sem, units, targetUnits); meanDescription = "(" + toThreeSigFig(scaledMean, 2000, scaledSem) + ") " + SHORT_TIMEUNIT_NAMES.get(targetUnits); } double sd = duration.getStandardDeviation(); return " min. " + describeDuration(min, units) + ", mean " + meanDescription + ", SD " + describeDuration(sd, units) + ", max. " + describeDuration(max, units); } }
public static Optional<String> describe(Duration duration) { if (duration.isZero()) { return Optional.empty(); } Optional<String> value = inUnits(duration, ChronoUnit.DAYS, "days"); if (!value.isPresent()) { value = inUnits(duration, ChronoUnit.HOURS, "hours"); } if (!value.isPresent()) { value = inUnits(duration, ChronoUnit.MINUTES, "minutes"); } if (!value.isPresent()) { value = inUnits(duration, ChronoUnit.SECONDS, "s"); } if (!value.isPresent()) { value = inUnits(duration, ChronoUnit.MILLIS, "ms"); } if (!value.isPresent()) { value = inUnits(duration, ChronoUnit.MICROS, "\u00B5s"); } if (!value.isPresent()) { value = Optional.of(convert(duration, ChronoUnit.NANOS, "ns")); } return value; }
/** * Provide a short, simple human understandable string describing the * supplied duration. The duration is a non-negative value. The output is * appended to the supplied StringBuilder and has the form * {@code <number> <space> <units>}, where {@code <number>} * is an integer and {@code <units>} is defined by the value of unitFormat. */ public static StringBuilder appendDuration(StringBuilder sb, long duration, TimeUnit units, TimeUnitFormat unitFormat) { checkArgument(duration >= 0); Map<TimeUnit,String> unitsFormat = (unitFormat == TimeUnitFormat.SHORT) ? SHORT_TIMEUNIT_NAMES : LONG_TIMEUNIT_NAMES; TimeUnit targetUnit = displayUnitFor(duration, units); return sb.append(targetUnit.convert(duration, units)).append(' '). append(unitsFormat.get(targetUnit)); }
private static Optional<String> inUnits(Duration duration, ChronoUnit unit, String name) { Duration cutoff = unit.getDuration().multipliedBy(2); if (duration.compareTo(cutoff) >= 0) { return Optional.of(convert(duration, unit, name)); } else { return Optional.empty(); } }
/** * Returns string representation of this RequestExecutionTimeGauge * Only long term statistics is printed */ @Override public synchronized String toString() { String aName = (name.length() > 34) ? name.substring(0, 34) : name; long updatePeriod = System.currentTimeMillis() - startTime; StringBuilder sb = new StringBuilder(); try (Formatter formatter = new Formatter(sb)) { formatter.format("%-34s %,12.2f\u00B1%,10.2f %,12d %,12d %,12.2f %,12d %12s", aName, statistics.getMean(), statistics.getStandardError(), getMinExecutionTime(), getMaxExecutionTime(), statistics.getSampleStandardDeviation(), statistics.getSampleSize(), TimeUtils.duration(updatePeriod, TimeUnit.MILLISECONDS, TimeUtils.TimeUnitFormat.SHORT)); } return sb.toString(); }
public HtpasswdPlugin(Properties properties) { this(new FileSupplier( Paths.get(properties.getProperty("gplazma.htpasswd.file")), getMillis(properties, "gplazma.htpasswd.file.cache-period"), StandardCharsets.US_ASCII)); }
/** * Returns a description of some point in time using some reference point. * The appended text is {@code <timestamp> <space> <open-parenth> <integer> * <space> <time-unit-word> <space> <relation> <close-parenth>}. Here are * two examples: * <pre> * 2014-04-20 22:40:32.965 (7 seconds ago) * 2014-04-21 02:40:32.965 (3 hours in the future) * </pre> */ public static CharSequence relativeTimestamp(long when, long current) { return appendRelativeTimestamp(new StringBuilder(), when, current); }
public static StringBuilder appendRelativeTimestamp(StringBuilder sb, long when, long current, TimeUnitFormat format) { checkArgument(when > 0); checkArgument(current > 0); SimpleDateFormat iso8601 = new SimpleDateFormat(TIMESTAMP_FORMAT); sb.append(iso8601.format(new Date(when))); long diff = Math.abs(when - current); sb.append(" ("); appendDuration(sb, diff, MILLISECONDS, format); sb.append(' '); sb.append(when < current ? "ago" : "in the future"); sb.append(')'); return sb; }
public static CharSequence relativeTimestamp(Instant when) { return appendRelativeTimestamp(new StringBuilder(), when.toEpochMilli(), System.currentTimeMillis(), TimeUnitFormat.SHORT); }