/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.
*/ package org.apache.juli;
/** * A {@link FileHandler} implementation that uses a queue of log entries. * <p> * Configuration properties are inherited from the {@link FileHandler} class. This class does not add its own * configuration properties for the logging configuration, but relies on the following system properties instead: * </p> * <ul> * <li><code>org.apache.juli.AsyncOverflowDropType</code> Default value: <code>1</code></li> * <li><code>org.apache.juli.AsyncMaxRecordCount</code> Default value: <code>10000</code></li> * </ul> * <p> * See the System Properties page in the configuration reference of Tomcat. * </p>
*/ publicclass AsyncFileHandler extends FileHandler {
@Override publicvoid publish(LogRecord record) { if (!isLoggable(record)) { return;
} // fill source entries, before we hand the record over to another // thread with another class loader
record.getSourceMethodName();
loggerService.execute(new Runnable() {
@Override publicvoid run() { /* * During Tomcat shutdown, the Handlers are closed before the executor queue is flushed therefore the * closed flag is ignored if the executor is shutting down.
*/ if (!closed || loggerService.isTerminating()) {
publishInternal(record);
}
}
});
}
privatestaticfinal ThreadFactory THREAD_FACTORY = new ThreadFactory(THREAD_PREFIX);
/* * Implementation note: Use of this count could be extended to start/stop the LoggerExecutorService but that * would require careful locking as the current size of the queue also needs to be taken into account and there * are lost of edge cases when rapidly starting and stopping handlers.
*/ privatefinal AtomicInteger handlerCount = new AtomicInteger();
LoggerExecutorService(finalint overflowDropType, finalint maxRecords) { super(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingDeque<>(maxRecords), THREAD_FACTORY); switch (overflowDropType) { case OVERFLOW_DROP_LAST: default:
setRejectedExecutionHandler(new DropLastPolicy()); break; case OVERFLOW_DROP_FIRST:
setRejectedExecutionHandler(new DiscardOldestPolicy()); break; case OVERFLOW_DROP_FLUSH:
setRejectedExecutionHandler(new DropFlushPolicy()); break; case OVERFLOW_DROP_CURRENT:
setRejectedExecutionHandler(new DiscardPolicy());
}
}
@Override public LinkedBlockingDeque<Runnable> getQueue() { return (LinkedBlockingDeque<Runnable>) super.getQueue();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.