Lines 42-48
import java.util.Enumeration;
Link Here
|
42 |
import java.util.MissingResourceException; |
42 |
import java.util.MissingResourceException; |
43 |
import java.util.ResourceBundle; |
43 |
import java.util.ResourceBundle; |
44 |
import java.util.Vector; |
44 |
import java.util.Vector; |
45 |
|
45 |
import java.util.concurrent.locks.ReadWriteLock; |
|
|
46 |
import java.util.concurrent.locks.ReentrantReadWriteLock; |
46 |
|
47 |
|
47 |
/** |
48 |
/** |
48 |
* <font color="#AA2222"><b>This class has been deprecated and |
49 |
* <font color="#AA2222"><b>This class has been deprecated and |
Lines 117-122
public class Category implements AppenderAttachable {
Link Here
|
117 |
getFQCN method. */ |
118 |
getFQCN method. */ |
118 |
private static final String FQCN = Category.class.getName(); |
119 |
private static final String FQCN = Category.class.getName(); |
119 |
|
120 |
|
|
|
121 |
private ReadWriteLock lock = new ReentrantReadWriteLock(); |
122 |
|
120 |
protected ResourceBundle resourceBundle; |
123 |
protected ResourceBundle resourceBundle; |
121 |
|
124 |
|
122 |
// Categories need to know what Hierarchy they are in |
125 |
// Categories need to know what Hierarchy they are in |
Lines 155-168
public class Category implements AppenderAttachable {
Link Here
|
155 |
<p>If <code>newAppender</code> is already in the list of |
158 |
<p>If <code>newAppender</code> is already in the list of |
156 |
appenders, then it won't be added again. |
159 |
appenders, then it won't be added again. |
157 |
*/ |
160 |
*/ |
158 |
synchronized |
|
|
159 |
public |
161 |
public |
160 |
void addAppender(Appender newAppender) { |
162 |
void addAppender(Appender newAppender) { |
161 |
if(aai == null) { |
163 |
lock.writeLock().lock(); |
162 |
aai = new AppenderAttachableImpl(); |
164 |
try { |
|
|
165 |
if(aai == null) { |
166 |
aai = new AppenderAttachableImpl(); |
167 |
} |
168 |
aai.addAppender(newAppender); |
169 |
repository.fireAddAppenderEvent(this, newAppender); |
170 |
} finally { |
171 |
lock.writeLock().unlock(); |
163 |
} |
172 |
} |
164 |
aai.addAppender(newAppender); |
|
|
165 |
repository.fireAddAppenderEvent(this, newAppender); |
166 |
} |
173 |
} |
167 |
|
174 |
|
168 |
/** |
175 |
/** |
Lines 201-218
public class Category implements AppenderAttachable {
Link Here
|
201 |
|
208 |
|
202 |
for(Category c = this; c != null; c=c.parent) { |
209 |
for(Category c = this; c != null; c=c.parent) { |
203 |
// Protected against simultaneous call to addAppender, removeAppender,... |
210 |
// Protected against simultaneous call to addAppender, removeAppender,... |
204 |
synchronized(c) { |
211 |
c.lock.readLock().lock(); |
|
|
212 |
try { |
205 |
if(c.aai != null) { |
213 |
if(c.aai != null) { |
206 |
writes += c.aai.appendLoopOnAppenders(event); |
214 |
writes += c.aai.appendLoopOnAppenders(event); |
207 |
} |
215 |
} |
208 |
if(!c.additive) { |
216 |
if(!c.additive) { |
209 |
break; |
217 |
break; |
210 |
} |
218 |
} |
|
|
219 |
} finally { |
220 |
c.lock.readLock().unlock(); |
211 |
} |
221 |
} |
212 |
} |
222 |
} |
213 |
|
223 |
|
214 |
if(writes == 0) { |
224 |
if(writes == 0) { |
215 |
repository.emitNoAppenderWarning(this); |
225 |
lock.writeLock().lock(); |
|
|
226 |
try { |
227 |
repository.emitNoAppenderWarning(this); |
228 |
} finally { |
229 |
lock.writeLock().unlock(); |
230 |
} |
216 |
} |
231 |
} |
217 |
} |
232 |
} |
218 |
|
233 |
|
Lines 221-236
public class Category implements AppenderAttachable {
Link Here
|
221 |
interface. |
236 |
interface. |
222 |
@since 1.0 |
237 |
@since 1.0 |
223 |
*/ |
238 |
*/ |
224 |
synchronized |
|
|
225 |
void closeNestedAppenders() { |
239 |
void closeNestedAppenders() { |
226 |
Enumeration enumeration = this.getAllAppenders(); |
240 |
lock.writeLock().lock(); |
227 |
if(enumeration != null) { |
241 |
try { |
228 |
while(enumeration.hasMoreElements()) { |
242 |
Enumeration enumeration = this.getAllAppenders(); |
229 |
Appender a = (Appender) enumeration.nextElement(); |
243 |
if(enumeration != null) { |
230 |
if(a instanceof AppenderAttachable) { |
244 |
while(enumeration.hasMoreElements()) { |
231 |
a.close(); |
245 |
Appender a = (Appender) enumeration.nextElement(); |
232 |
} |
246 |
if(a instanceof AppenderAttachable) { |
|
|
247 |
a.close(); |
248 |
} |
249 |
} |
233 |
} |
250 |
} |
|
|
251 |
} finally { |
252 |
lock.writeLock().unlock(); |
234 |
} |
253 |
} |
235 |
} |
254 |
} |
236 |
|
255 |
|
Lines 406-418
public class Category implements AppenderAttachable {
Link Here
|
406 |
is returned. |
425 |
is returned. |
407 |
|
426 |
|
408 |
@return Enumeration An enumeration of the appenders in this category. */ |
427 |
@return Enumeration An enumeration of the appenders in this category. */ |
409 |
synchronized |
|
|
410 |
public |
428 |
public |
411 |
Enumeration getAllAppenders() { |
429 |
Enumeration getAllAppenders() { |
412 |
if(aai == null) |
430 |
lock.readLock().lock(); |
413 |
return NullEnumeration.getInstance(); |
431 |
try { |
414 |
else |
432 |
if(aai == null) |
415 |
return aai.getAllAppenders(); |
433 |
return NullEnumeration.getInstance(); |
|
|
434 |
else |
435 |
return aai.getAllAppenders(); |
436 |
} finally { |
437 |
lock.readLock().unlock(); |
438 |
} |
416 |
} |
439 |
} |
417 |
|
440 |
|
418 |
/** |
441 |
/** |
Lines 423-432
public class Category implements AppenderAttachable {
Link Here
|
423 |
synchronized |
446 |
synchronized |
424 |
public |
447 |
public |
425 |
Appender getAppender(String name) { |
448 |
Appender getAppender(String name) { |
426 |
if(aai == null || name == null) |
449 |
lock.readLock().lock(); |
427 |
return null; |
450 |
try { |
428 |
|
451 |
if(aai == null || name == null) |
429 |
return aai.getAppender(name); |
452 |
return null; |
|
|
453 |
|
454 |
return aai.getAppender(name); |
455 |
} finally { |
456 |
lock.readLock().unlock(); |
457 |
} |
430 |
} |
458 |
} |
431 |
|
459 |
|
432 |
/** |
460 |
/** |
Lines 880-898
public class Category implements AppenderAttachable {
Link Here
|
880 |
|
908 |
|
881 |
<p>This is useful when re-reading configuration information. |
909 |
<p>This is useful when re-reading configuration information. |
882 |
*/ |
910 |
*/ |
883 |
synchronized |
|
|
884 |
public |
911 |
public |
885 |
void removeAllAppenders() { |
912 |
void removeAllAppenders() { |
886 |
if(aai != null) { |
913 |
lock.writeLock().lock(); |
887 |
Vector appenders = new Vector(); |
914 |
try { |
888 |
for (Enumeration iter = aai.getAllAppenders(); iter != null && iter.hasMoreElements();) { |
915 |
if(aai != null) { |
889 |
appenders.add(iter.nextElement()); |
916 |
Vector appenders = new Vector(); |
890 |
} |
917 |
for (Enumeration iter = aai.getAllAppenders(); iter != null && iter.hasMoreElements();) { |
891 |
aai.removeAllAppenders(); |
918 |
appenders.add(iter.nextElement()); |
892 |
for(Enumeration iter = appenders.elements(); iter.hasMoreElements();) { |
919 |
} |
|
|
920 |
aai.removeAllAppenders(); |
921 |
for(Enumeration iter = appenders.elements(); iter.hasMoreElements();) { |
893 |
fireRemoveAppenderEvent((Appender) iter.nextElement()); |
922 |
fireRemoveAppenderEvent((Appender) iter.nextElement()); |
|
|
923 |
} |
924 |
aai = null; |
894 |
} |
925 |
} |
895 |
aai = null; |
926 |
} finally { |
|
|
927 |
lock.writeLock().unlock(); |
896 |
} |
928 |
} |
897 |
} |
929 |
} |
898 |
|
930 |
|
Lines 902-916
public class Category implements AppenderAttachable {
Link Here
|
902 |
|
934 |
|
903 |
@since 0.8.2 |
935 |
@since 0.8.2 |
904 |
*/ |
936 |
*/ |
905 |
synchronized |
|
|
906 |
public |
937 |
public |
907 |
void removeAppender(Appender appender) { |
938 |
void removeAppender(Appender appender) { |
908 |
if(appender == null || aai == null) |
939 |
lock.writeLock().lock(); |
909 |
return; |
940 |
try { |
910 |
boolean wasAttached = aai.isAttached(appender); |
941 |
if(appender == null || aai == null) |
911 |
aai.removeAppender(appender); |
942 |
return; |
912 |
if (wasAttached) { |
943 |
boolean wasAttached = aai.isAttached(appender); |
|
|
944 |
aai.removeAppender(appender); |
945 |
if (wasAttached) { |
913 |
fireRemoveAppenderEvent(appender); |
946 |
fireRemoveAppenderEvent(appender); |
|
|
947 |
} |
948 |
} finally { |
949 |
lock.writeLock().unlock(); |
914 |
} |
950 |
} |
915 |
} |
951 |
} |
916 |
|
952 |
|
Lines 919-932
public class Category implements AppenderAttachable {
Link Here
|
919 |
list of appenders. |
955 |
list of appenders. |
920 |
|
956 |
|
921 |
@since 0.8.2 */ |
957 |
@since 0.8.2 */ |
922 |
synchronized |
|
|
923 |
public |
958 |
public |
924 |
void removeAppender(String name) { |
959 |
void removeAppender(String name) { |
925 |
if(name == null || aai == null) return; |
960 |
lock.writeLock().lock(); |
926 |
Appender appender = aai.getAppender(name); |
961 |
try { |
927 |
aai.removeAppender(name); |
962 |
if(name == null || aai == null) return; |
928 |
if (appender != null) { |
963 |
Appender appender = aai.getAppender(name); |
|
|
964 |
aai.removeAppender(name); |
965 |
if (appender != null) { |
929 |
fireRemoveAppenderEvent(appender); |
966 |
fireRemoveAppenderEvent(appender); |
|
|
967 |
} |
968 |
} finally { |
969 |
lock.writeLock().unlock(); |
930 |
} |
970 |
} |
931 |
} |
971 |
} |
932 |
|
972 |
|