Search in sources :

Example 1 with PerformanceLevel

use of org.apache.sis.util.logging.PerformanceLevel in project sis by apache.

the class ConcurrentAuthorityFactory method release.

/**
 * Releases the Data Access Object previously obtained with {@link #getDataAccess()}.
 * This method marks the factory as available for reuse by other threads.
 *
 * <p>All arguments given to this method are for logging purpose only.</p>
 *
 * @param  caller  the caller method, or {@code null} for {@code "create" + type.getSimpleName()}.
 * @param  type    the type of the created object, or {@code null} for performing no logging.
 * @param  code    the code of the created object, or {@code null} if none.
 */
private void release(String caller, final Class<?> type, final String code) {
    // A null value here would be an error in our algorithm.
    final DataAccessRef<DAO> usage = currentDAO.get();
    if (--usage.depth == 0) {
        currentDAO.remove();
        long time = usage.timestamp;
        synchronized (availableDAOs) {
            // Must be done first in case an exception happen after this point.
            remainingDAOs++;
            recycle(usage);
            // We released only one data access, so awake only one thread - not all of them.
            availableDAOs.notify();
            time = usage.timestamp - time;
        }
        /*
             * Log only events that take longer than the threshold (e.g. 10 milliseconds).
             */
        if (time >= DURATION_FOR_LOGGING && type != null) {
            if (caller == null) {
                caller = "create".concat(type.getSimpleName());
            }
            final PerformanceLevel level = PerformanceLevel.forDuration(time, TimeUnit.NANOSECONDS);
            final Double duration = time / (double) StandardDateFormat.NANOS_PER_SECOND;
            final Messages resources = Messages.getResources(null);
            final LogRecord record;
            if (code != null) {
                record = resources.getLogRecord(level, Messages.Keys.CreateDurationFromIdentifier_3, type, code, duration);
            } else {
                record = resources.getLogRecord(level, Messages.Keys.CreateDuration_2, type, duration);
            }
            record.setLoggerName(Loggers.CRS_FACTORY);
            Logging.log(getClass(), caller, record);
        }
    }
    assert usage.depth >= 0 : usage;
}
Also used : Messages(org.apache.sis.util.resources.Messages) LogRecord(java.util.logging.LogRecord) PerformanceLevel(org.apache.sis.util.logging.PerformanceLevel)

Aggregations

LogRecord (java.util.logging.LogRecord)1 PerformanceLevel (org.apache.sis.util.logging.PerformanceLevel)1 Messages (org.apache.sis.util.resources.Messages)1