Skip to content

Commit

Permalink
ISPN-1048 - Be able to enable DEBUG_DEPENDENCIES via a system property
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanne authored and maniksurtani committed Apr 15, 2011
1 parent 3b3992e commit 1366907
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@
@Scope(Scopes.NAMED_CACHE)
public abstract class AbstractComponentRegistry implements Lifecycle, Cloneable {

// Make sure this is ALWAYS false when being checked in to the code repository!
public static final boolean DEBUG_DEPENDENCIES = false;
private static final String DEPENDENCIES_ENABLE_JVMOPTION = "infinispan.debugDependencies";

/**
* Set the system property <li>infinispan.debugDependencies</li> to <li>true</li>
* to enable some extra information to errors generated by the component factory.
*/
public static final boolean DEBUG_DEPENDENCIES = Boolean.getBoolean(DEPENDENCIES_ENABLE_JVMOPTION);
private Stack<String> debugStack = DEBUG_DEPENDENCIES ? new Stack<String>() : null;

/**
Expand Down Expand Up @@ -346,23 +351,24 @@ protected <T> T getOrCreateComponent(Class<T> componentClass, String name) {
protected AbstractComponentFactory getFactory(Class componentClass) {
Map<Class, Class<? extends AbstractComponentFactory>> defaultFactoryMap = getDefaultFactoryMap();
Class<? extends AbstractComponentFactory> cfClass = defaultFactoryMap.get(componentClass);
if (cfClass == null)
throw new ConfigurationException("No registered default factory for component '" + componentClass + "' found! Debug stack: " + debugStack);
if (cfClass == null) {
throwStackAwareConfigurationException("No registered default factory for component '" + componentClass + "' found!");
}
// a component factory is a component too! See if one has been created and exists in the registry
AbstractComponentFactory cf = getComponent(cfClass);
if (cf == null) {
// hasn't yet been created. Create and put in registry
cf = instantiateFactory(cfClass);
if (cf == null)
throw new ConfigurationException("Unable to locate component factory for component " + componentClass + " Debug stack: " + debugStack);
throwStackAwareConfigurationException("Unable to locate component factory for component " + componentClass);
// we simply register this factory. Registration will take care of constructing any dependencies.
registerComponent(cf, cfClass);
}

// ensure the component factory is in the STARTED state!
Component c = lookupComponent(cfClass, cfClass.getName());
if (c.instance != cf)
throw new ConfigurationException("Component factory " + cfClass + " incorrectly registered! Debug stack: " + debugStack);
throwStackAwareConfigurationException("Component factory " + cfClass + " incorrectly registered!");
return cf;
}

Expand Down Expand Up @@ -901,4 +907,13 @@ public String toString() {
}
}

private void throwStackAwareConfigurationException(String message) {
if (debugStack == null) {
throw new ConfigurationException(message + ". To get more detail set the system property " + DEPENDENCIES_ENABLE_JVMOPTION + " to true" );
}
else {
throw new ConfigurationException(message + " Debug stack: " + debugStack);
}
}

}

This file was deleted.

0 comments on commit 1366907

Please sign in to comment.