Refine search
/** * Runs the callback function if the current env matches the given name. * * @param name A name to test for. * @param fn A callback function. * @param <T> A resulting type. * @return A resulting object. */ @Nonnull default <T> Optional<T> ifMode(final String name, final Supplier<T> fn) { if (name().equals(name)) { return Optional.of(fn.get()); } return Optional.empty(); }
@Override public void log( @Nonnull String format, @Nullable Object... arguments ) { requireNonNull( format, "format must not be null" ); if ( arguments == null || arguments.length == 0 ) { log( format ); return; } String message = String.format( format, arguments ); PrintWriter writer; synchronized ( lock ) { writer = writerSupplier.get(); writeLog( writer, message ); } maybeFlush( writer ); }
@Override public void log( @Nonnull String message, @Nonnull Throwable throwable ) { requireNonNull( message, "message must not be null" ); if ( throwable == null ) { log( message ); return; } PrintWriter writer; synchronized ( lock ) { writer = writerSupplier.get(); writeLog( writer, message, throwable ); } maybeFlush( writer ); }
/** * Enables the accumulation of {@link CacheStats} during the operation of the cache. Without this * {@link Cache#stats} will return zero for all statistics. Note that recording statistics * requires bookkeeping to be performed with each operation, and thus imposes a performance * penalty on cache operation. Any exception thrown by the supplied {@link StatsCounter} will be * suppressed and logged. * * @param statsCounterSupplier a supplier instance that returns a new {@link StatsCounter} * @return this builder instance */ @Nonnull public Caffeine<K, V> recordStats( @Nonnull Supplier<? extends StatsCounter> statsCounterSupplier) { requireState(this.statsCounterSupplier == null, "Statistics recording was already set"); requireNonNull(statsCounterSupplier); this.statsCounterSupplier = () -> StatsCounter.guardedStatsCounter(statsCounterSupplier.get()); return this; }
/** * Sets line search factory. * * @param lineSearchFactory the line search factory * @return the line search factory */ @Nonnull public RoundRobinTrainer setLineSearchFactory(@Nonnull final Supplier<LineSearchStrategy> lineSearchFactory) { this.lineSearchFactory = s -> lineSearchFactory.get(); return this; }