more componentlocator changes

This commit is contained in:
Alex Huang 2010-11-17 04:49:38 -08:00
parent e22968b5fc
commit 2628b0c994
4 changed files with 40 additions and 32 deletions

View File

@ -3,7 +3,7 @@
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/> <classpathentry kind="lib" path="/thirdparty/log4j-1.2.15.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/console-common"/>
<classpathentry kind="lib" path="/thirdparty/gson.jar"/> <classpathentry kind="lib" path="/thirdparty/gson.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/console"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -2,6 +2,6 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/console-common"/> <classpathentry combineaccessrules="false" kind="src" path="/console"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -82,6 +82,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
protected static final Callback[] s_callbacks = new Callback[] { NoOp.INSTANCE, new DatabaseCallback() }; protected static final Callback[] s_callbacks = new Callback[] { NoOp.INSTANCE, new DatabaseCallback() };
protected static final CallbackFilter s_callbackFilter = new DatabaseCallbackFilter(); protected static final CallbackFilter s_callbackFilter = new DatabaseCallbackFilter();
protected static final HashMap<Class<?>, InjectInfo> s_factories = new HashMap<Class<?>, InjectInfo>(); protected static final HashMap<Class<?>, InjectInfo> s_factories = new HashMap<Class<?>, InjectInfo>();
protected static Boolean s_once = false;
protected HashMap<String, Adapters<? extends Adapter>> _adapterMap; protected HashMap<String, Adapters<? extends Adapter>> _adapterMap;
protected HashMap<String, ComponentInfo<Manager>> _managerMap; protected HashMap<String, ComponentInfo<Manager>> _managerMap;
@ -91,17 +92,6 @@ public class ComponentLocator implements ComponentLocatorMBean {
protected Object _component; protected Object _component;
static { static {
File file = PropertiesUtil.findConfigFile("log4j-cloud.xml");
if (file != null) {
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
} else {
file = PropertiesUtil.findConfigFile("log4j-cloud.properties");
if (file != null) {
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
PropertyConfigurator.configureAndWatch(file.getAbsolutePath());
}
}
Runtime.getRuntime().addShutdownHook(new CleanupThread()); Runtime.getRuntime().addShutdownHook(new CleanupThread());
} }
@ -679,7 +669,24 @@ public class ComponentLocator implements ComponentLocatorMBean {
return new Adapters<Adapter>(key, new ArrayList<ComponentInfo<Adapter>>()); return new Adapters<Adapter>(key, new ArrayList<ComponentInfo<Adapter>>());
} }
protected static ComponentLocator getLocatorInternal(String server, boolean setInThreadLocal, String configFileName) { protected static ComponentLocator getLocatorInternal(String server, boolean setInThreadLocal, String configFileName, String log4jFilename) {
synchronized(s_once) {
if (!s_once) {
File file = PropertiesUtil.findConfigFile(log4jFilename + ".xml");
if (file != null) {
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
} else {
file = PropertiesUtil.findConfigFile(log4jFilename + ".properties");
if (file != null) {
s_logger.info("log4j configuration found at " + file.getAbsolutePath());
PropertyConfigurator.configureAndWatch(file.getAbsolutePath());
}
}
s_once = true;
}
}
ComponentLocator locator; ComponentLocator locator;
synchronized (s_locators) { synchronized (s_locators) {
locator = s_locators.get(server); locator = s_locators.get(server);
@ -700,8 +707,8 @@ public class ComponentLocator implements ComponentLocatorMBean {
return locator; return locator;
} }
public static ComponentLocator getLocator(String server, String configFileName) { public static ComponentLocator getLocator(String server, String configFileName, String log4jFilename) {
return getLocatorInternal(server, true, configFileName); return getLocatorInternal(server, true, configFileName, log4jFilename);
} }
public static ComponentLocator getLocator(String server) { public static ComponentLocator getLocator(String server) {
@ -713,7 +720,7 @@ public class ComponentLocator implements ComponentLocatorMBean {
configFile = "components.xml"; configFile = "components.xml";
} }
} }
return getLocatorInternal(server, true, configFile); return getLocatorInternal(server, true, configFile, "log4j-cloud");
} }
public static ComponentLocator getCurrentLocator() { public static ComponentLocator getCurrentLocator() {

View File

@ -33,7 +33,8 @@ public class ComponentTestCase extends Log4jEnabledTestCase {
if(annotation instanceof ComponentSetup) { if(annotation instanceof ComponentSetup) {
ComponentLocator.getLocator( ComponentLocator.getLocator(
((ComponentSetup)annotation).managerName(), ((ComponentSetup)annotation).managerName(),
((ComponentSetup)annotation).setupXml() ((ComponentSetup)annotation).setupXml(),
((ComponentSetup)annotation).log4j()
); );
break; break;