/** * Boilerplate method the directly handle the given exception without a special message * * @param log the logger used to log the exception * @param e the exception to handle * @return a <tt>HandledException</tt> which notifies surrounding calls that an error occurred, which has * already been taken care of. */ public static HandledException handle(Log log, Throwable e) { return handle().error(e).to(log).handle(); }
/** * Boilerplate method the directly handle the given exception without a special message or logger * * @param e the exception to handle * @return a <tt>HandledException</tt> which notifies surrounding calls that an error occurred, which has * already been taken care of. */ public static HandledException handle(Throwable e) { return handle().error(e).handle(); }
private void ensureReady() { if (!ready) { throw Exceptions.handle().to(LOG).withSystemErrorMessage("Index is not ready yet.").handle(); } }
/** * Checks if the value is non-null or the property accepts null values. * * @param propertyValue the value to check */ protected void checkNullability(Object propertyValue) { if (!isNullable() && propertyValue == null) { throw Exceptions.createHandled().withNLSKey("Property.fieldNotNullable").set("field", getLabel()).handle(); } }
/** * The number of tasks which were executed by this executor * * @return the number of tasks executed so far */ public long getExecuted() { return executed.getCount(); }
@Override public void handleLogMessage(LogMessage msg) { if (msg.isReceiverWouldLog()) { synchronized (messages) { messages.add(0, msg); numLogMessages.inc(); while (messages.size() > maxMsg) { messages.remove(messages.size() - 1); } } } }
WrappedConnection(Connection c, Database database) { super(c); this.database = database; Databases.numUses.inc(); }
/** * Adds the given value to the set of values on which the average is based. * <p> * If the sum of all values is greater as <tt>Double.MAX_VALUE / 2</tt> or the count of all values is greater as * <tt>Long.Max_VALUE / 2</tt>, the average is resetted. * * @param value to value to add to the average */ public void addValue(long value) { addValue((double) value); }
@Override public String toString() { return getAvg() + " (" + count + ")"; } }
/** * Adds the given value to the set of values on which the average is based. * <p> * If the sum of all values is greater as <tt>Double.MAX_VALUE / 2</tt> or the count of all values is greater as * <tt>Long.Max_VALUE / 2</tt>, the average is resetted. * * @param value to value to add to the average */ public void addValue(double value) { addValues(1, value); }
/** * Generates a new {@link ErrorHandler} which gracefully handles all kinds of errors * * @return a new <tt>ErrorHandler</tt> to handle an error or exception */ public static ErrorHandler handle() { return new ErrorHandler(true); }
/** * Increments the counter by one * * @return the update value of the counter */ public long inc() { return add(1); }
protected Timing(String category, String key) { this.category = category; this.key = key; this.avg = new Average(); }
private static void verifyUniquenessOfName(String name) { if (caches.containsKey(name)) { throw Exceptions.handle() .to(LOG) .withSystemErrorMessage("A cache named '%s' has already been created!", name) .handle(); } }
/** * Returns the total number of unique incidents (with different locations) encountered. * * @return the total number of unique incidents so far. */ public long getNumUniqueIncidents() { return numUniqueIncidents.getCount(); } }
protected void addNanos(long durationInNanos) { avg.addValue(durationInNanos / 1000); changedSinceLastCheck = true; } }
/** * The average duration of a task in milliseconds. * * @return the average execution time of a task in milliseconds */ public double getAverageDuration() { return duration.getAvg(); }
/** * Generates a new {@link ErrorHandler} which creates a <tt>HandledException</tt> without actually logging or * processing it. * <p> * This can be used to generate a <tt>HandledException</tt> based on a user error (invalid input) * which doesn't need to be logged. * * @return a new <tt>ErrorHandler</tt> to handle an error or exception */ public static ErrorHandler createHandled() { return new ErrorHandler(false); }
/** * Returns the total number of log messages encountered. * * @return the total number of log messages so far. */ public long getNumLogMessages() { return numLogMessages.getCount(); }
/** * Returns the total number of incidents (exceptions) encountered. * * @return the total number of incidents so far. */ public long getNumIncidents() { return numIncidents.getCount(); }