From c043e2bf1ce13fdc45002be25dbcb38925677408 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Thu, 8 Jan 2009 05:44:33 +0000 Subject: [PATCH] Removed cyclic dependencies --- .../java/org/jboss/netty/util/MapUtil.java | 57 ++++--------------- .../netty/util/ThreadRenamingRunnable.java | 6 -- 2 files changed, 12 insertions(+), 51 deletions(-) diff --git a/src/main/java/org/jboss/netty/util/MapUtil.java b/src/main/java/org/jboss/netty/util/MapUtil.java index e85c8f7003..778a5df480 100644 --- a/src/main/java/org/jboss/netty/util/MapUtil.java +++ b/src/main/java/org/jboss/netty/util/MapUtil.java @@ -28,9 +28,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.jboss.netty.logging.InternalLogger; -import org.jboss.netty.logging.InternalLoggerFactory; - /** * A set of utility methods related with a {@link Map}. * @@ -40,8 +37,6 @@ import org.jboss.netty.logging.InternalLoggerFactory; * @version $Rev$, $Date$ */ public class MapUtil { - private static final InternalLogger logger = - InternalLoggerFactory.getInstance(MapUtil.class); /** * Returns {@code true} if and only if the specified {@code map} is an @@ -51,81 +46,53 @@ public class MapUtil { public static boolean isOrderedMap(Map map) { Class mapType = map.getClass(); if (LinkedHashMap.class.isAssignableFrom(mapType)) { - if (logger.isDebugEnabled()) { - logger.debug(mapType.getSimpleName() + " is an ordered map."); - } + // LinkedHashMap is an ordered map. return true; } - if (logger.isDebugEnabled()) { - logger.debug( - mapType.getName() + " is not a " + - LinkedHashMap.class.getSimpleName()); - } + // Not a LinkedHashMap - start autodetection. // Detect Apache Commons Collections OrderedMap implementations. Class type = mapType; while (type != null) { for (Class i: type.getInterfaces()) { if (i.getName().endsWith("OrderedMap")) { - if (logger.isDebugEnabled()) { - logger.debug( - mapType.getSimpleName() + - " is an ordered map (guessed from that it " + - " implements OrderedMap interface.)"); - } + // Seems like it's an ordered map - guessed from that + // it implements OrderedMap interface. return true; } } type = type.getSuperclass(); } - if (logger.isDebugEnabled()) { - logger.debug( - mapType.getName() + - " does not implement OrderedMap interface."); - } - - // Last resort: try to create a new instance and test if it maintains - // the insertion order. - logger.debug( - "Last resort; trying to create a new map instance with a " + - "default constructor and test if insertion order is " + - "maintained."); - + // Does not implement OrderedMap interface. As a last resort, try to + // create a new instance and test if the insertion order is maintained. Map newMap; try { newMap = (Map) mapType.newInstance(); } catch (Exception e) { - if (logger.isDebugEnabled()) { - logger.debug( - "Failed to create a new map instance of '" + - mapType.getName() +"'.", e); - } + // No default constructor - cannot proceed anymore. return false; } + // Run some tests. List expectedKeys = new ArrayList(); String dummyValue = "dummyValue"; - for (int i = 0; i < ORDER_TEST_SAMPLES.length; i ++) { - String key = String.valueOf(ORDER_TEST_SAMPLES[i]); + for (short element: ORDER_TEST_SAMPLES) { + String key = String.valueOf(element); newMap.put(key, dummyValue); expectedKeys.add(key); Iterator it = expectedKeys.iterator(); for (Object actualKey: newMap.keySet()) { if (!it.next().equals(actualKey)) { - if (logger.isDebugEnabled()) { - logger.debug( - "The specified map didn't pass the insertion " + - "order test after " + (i + 1) + " tries."); - } + // Did not pass the test. return false; } } } - logger.debug("The specified map passed the insertion order test."); + // The specified map passed the insertion order test. return true; } diff --git a/src/main/java/org/jboss/netty/util/ThreadRenamingRunnable.java b/src/main/java/org/jboss/netty/util/ThreadRenamingRunnable.java index cfcc5c7faf..ab1fdc3f09 100644 --- a/src/main/java/org/jboss/netty/util/ThreadRenamingRunnable.java +++ b/src/main/java/org/jboss/netty/util/ThreadRenamingRunnable.java @@ -22,8 +22,6 @@ */ package org.jboss.netty.util; -import org.jboss.netty.logging.InternalLogger; -import org.jboss.netty.logging.InternalLoggerFactory; /** * Meta {@link Runnable} that changes the current thread name and reverts it @@ -36,8 +34,6 @@ import org.jboss.netty.logging.InternalLoggerFactory; * */ public class ThreadRenamingRunnable implements Runnable { - private static final InternalLogger logger = - InternalLoggerFactory.getInstance(ThreadRenamingRunnable.class); private final Runnable runnable; private final String threadName; @@ -69,8 +65,6 @@ public class ThreadRenamingRunnable implements Runnable { renamed = true; } catch (Exception e) { // Probably SecurityException. - logger.warn( - "Failed to set the current thread name.", e); } // Run the actual runnable and revert the name back when it ends.