2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j;
20 import org.apache.log4j.helpers.AppenderAttachableImpl;
21 import org.apache.log4j.spi.LoggingEvent;
25 * Obsolete AsyncAppender dispatcher provided for compatibility only.
27 * @deprecated Since 1.3.
29 class Dispatcher extends Thread {
33 private org.apache.log4j.helpers.BoundedFIFO bf;
34 private AppenderAttachableImpl aai;
35 private boolean interrupted = false;
36 AsyncAppender container;
44 Dispatcher(org.apache.log4j.helpers.BoundedFIFO bf, AsyncAppender container) {
46 this.container = container;
47 this.aai = container.aai;
49 // It is the user's responsibility to close appenders before
53 // set the dispatcher priority to lowest possible value
54 this.setPriority(Thread.MIN_PRIORITY);
55 this.setName("Dispatcher-" + getName());
57 // set the dispatcher priority to MIN_PRIORITY plus or minus 2
58 // depending on the direction of MIN to MAX_PRIORITY.
59 //+ (Thread.MAX_PRIORITY > Thread.MIN_PRIORITY ? 1 : -1)*2);
66 // We have a waiting dispacther if and only if bf.length is
67 // zero. In that case, we need to give it a death kiss.
68 if (bf.length() == 0) {
75 * The dispatching strategy is to wait until there are events in the buffer
76 * to process. After having processed an event, we release the monitor
77 * (variable bf) so that new events can be placed in the buffer, instead of
78 * keeping the monitor and processing the remaining events in the buffer.
81 * Other approaches might yield better results.
85 //Category cat = Category.getInstance(Dispatcher.class.getName());
90 if (bf.length() == 0) {
91 // Exit loop if interrupted but only if the the buffer is empty.
93 //cat.info("Exiting.");
98 //LogLog.debug("Waiting for new event to dispatch.");
100 } catch (InterruptedException e) {
108 //LogLog.debug("Notifying AsyncAppender about freed space.");
114 synchronized (container.aai) {
115 if ((aai != null) && (event != null)) {
116 aai.appendLoopOnAppenders(event);
122 // close and remove all appenders
123 aai.removeAllAppenders();