ceki 2002/12/03 09:41:05 Modified: src/java/org/apache/log4j MDC.java src/java/org/apache/log4j/helpers ThreadLocalMap.java Log: Clean up in the MDC code since log4j 1.3 requires JDK 1.2+. Revision Changes Path 1.12 +36 -91 jakarta-log4j/src/java/org/apache/log4j/MDC.java Index: MDC.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/MDC.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- MDC.java 9 Oct 2002 22:50:02 -0000 1.11 +++ MDC.java 3 Dec 2002 17:41:04 -0000 1.12 @@ -33,114 +33,59 @@ @author Ceki Gülcü */ public class MDC { - final static MDC mdc = new MDC(); - static final int HT_SIZE = 7; - - boolean java1; - Object tlm; + static private final ThreadLocalMap tlm = new ThreadLocalMap(); - private - MDC() { - java1 = Loader.isJava1(); - if(!java1) { - tlm = new ThreadLocalMap(); - } + private MDC() { } /** - Put a context value (the <code>o</code> parameter) as identified - with the <code>key</code> parameter into the current thread's - context map. - - <p>If the current thread does not have a context map it is - created as a side effect. - - */ - static - public - void put(String key, Object o) { - mdc.put0(key, o); + * Put a context value (the <code>o</code> parameter) as identified + * with the <code>key</code> parameter into the current thread's + * context map. + * + * <p>If the current thread does not have a context map it is + * created as a side effect. + * */ + public static void put(String key, Object o) { + Hashtable ht = (Hashtable) tlm.get(); + if(ht == null) { + ht = new Hashtable(HT_SIZE); + tlm.set(ht); + } + ht.put(key, o); } - - /** - Get the context identified by the <code>key</code> parameter. - <p>This method has no side effects. - */ - static - public - Object get(String key) { - return mdc.get0(key); + /** + * Get the context identified by the <code>key</code> parameter. + * + * <p>This method has no side effects. + * */ + static public Object get(String key) { + Hashtable ht = (Hashtable) tlm.get(); + if(ht != null && key != null) { + return ht.get(key); + } else { + return null; + } } /** - Remove the the context identified by the <code>key</code> - parameter. - - */ - static - public - void remove(String key) { - mdc.remove0(key); + * Remove the the context identified by the <code>key</code> + * parameter. */ + public static void remove(String key) { + Hashtable ht = (Hashtable) tlm.get(); + if(ht != null) { + ht.remove(key); + } } - /** * Get the current thread's MDC as a hashtable. This method is * intended to be used internally. * */ public static Hashtable getContext() { - return mdc.getContext0(); - } - - - private - void put0(String key, Object o) { - if(java1) { - return; - } else { - Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get(); - if(ht == null) { - ht = new Hashtable(HT_SIZE); - ((ThreadLocalMap)tlm).set(ht); - } - ht.put(key, o); - } - } - - private - Object get0(String key) { - if(java1) { - return null; - } else { - Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get(); - if(ht != null && key != null) { - return ht.get(key); - } else { - return null; - } - } - } - - private - void remove0(String key) { - if(!java1) { - Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get(); - if(ht != null) { - ht.remove(key); - } - } - } - - - private - Hashtable getContext0() { - if(java1) { - return null; - } else { - return (Hashtable) ((ThreadLocalMap)tlm).get(); - } + return (Hashtable) tlm.get(); } } 1.4 +1 -3 jakarta-log4j/src/java/org/apache/log4j/helpers/ThreadLocalMap.java Index: ThreadLocalMap.java =================================================================== RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/ThreadLocalMap.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ThreadLocalMap.java 13 Aug 2001 10:22:10 -0000 1.3 +++ ThreadLocalMap.java 3 Dec 2002 17:41:05 -0000 1.4 @@ -20,9 +20,7 @@ */ final public class ThreadLocalMap extends InheritableThreadLocal { - public - final - Object childValue(Object parentValue) { + public final Object childValue(Object parentValue) { Hashtable ht = (Hashtable) parentValue; if(ht != null) { return ht.clone();
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>