1 16 17 package org.apache.log4j; 18 19 import org.apache.log4j.helpers.AppenderAttachableImpl; 20 import org.apache.log4j.spi.LoggingEvent; 21 22 23 28 class Dispatcher extends Thread { 29 32 private org.apache.log4j.helpers.BoundedFIFO bf; 33 private AppenderAttachableImpl aai; 34 private boolean interrupted = false; 35 AsyncAppender container; 36 37 43 Dispatcher(org.apache.log4j.helpers.BoundedFIFO bf, AsyncAppender container) { 44 this.bf = bf; 45 this.container = container; 46 this.aai = container.aai; 47 48 this.setDaemon(true); 51 52 this.setPriority(Thread.MIN_PRIORITY); 54 this.setName("Dispatcher-" + getName()); 55 56 } 60 61 void close() { 62 synchronized (bf) { 63 interrupted = true; 64 65 if (bf.length() == 0) { 68 bf.notify(); 69 } 70 } 71 } 72 73 83 public void run() { 84 LoggingEvent event; 86 87 while (true) { 88 synchronized (bf) { 89 if (bf.length() == 0) { 90 if (interrupted) { 92 break; 94 } 95 96 try { 97 bf.wait(); 99 } catch (InterruptedException e) { 100 break; 101 } 102 } 103 104 event = bf.get(); 105 106 if (bf.wasFull()) { 107 bf.notify(); 109 } 110 } 111 112 synchronized (container.aai) { 114 if ((aai != null) && (event != null)) { 115 aai.appendLoopOnAppenders(event); 116 } 117 } 118 } 119 120 aai.removeAllAppenders(); 123 } 124 } 125 | Popular Tags |