You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/10/03 06:12:38 UTC
[2/2] git commit: Use OrderComparator instead of WeightedFactory.
Use OrderComparator instead of WeightedFactory.
- Works nicely with future use of OrderComparator for all plugins.
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/0bf8ead3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/0bf8ead3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/0bf8ead3
Branch: refs/heads/master
Commit: 0bf8ead304b0338a716af6e91c0ebc7f956d1b29
Parents: 1bcd311
Author: Matt Sicker <ma...@apache.org>
Authored: Thu Oct 2 23:11:27 2014 -0500
Committer: Matt Sicker <ma...@apache.org>
Committed: Thu Oct 2 23:11:27 2014 -0500
----------------------------------------------------------------------
.../log4j/core/config/ConfigurationFactory.java | 47 +++-----------------
1 file changed, 6 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0bf8ead3/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
index e982e29..23c9565 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
@@ -30,7 +30,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
-import java.util.TreeSet;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -140,22 +139,18 @@ public abstract class ConfigurationFactory {
final PluginManager manager = new PluginManager(CATEGORY);
manager.collectPlugins();
final Map<String, PluginType<?>> plugins = manager.getPlugins();
- final Collection<WeightedFactory> ordered = new TreeSet<WeightedFactory>();
+ final List<Class<? extends ConfigurationFactory>> ordered =
+ new ArrayList<Class<? extends ConfigurationFactory>>(plugins.size());
for (final PluginType<?> type : plugins.values()) {
try {
- final Class<? extends ConfigurationFactory> clazz = type.getPluginClass().asSubclass(
- ConfigurationFactory.class);
- final Order order = clazz.getAnnotation(Order.class);
- if (order != null) {
- final int weight = order.value();
- ordered.add(new WeightedFactory(weight, clazz));
- }
+ ordered.add(type.getPluginClass().asSubclass(ConfigurationFactory.class));
} catch (final Exception ex) {
LOGGER.warn("Unable to add class {}", type.getPluginClass(), ex);
}
}
- for (final WeightedFactory wf : ordered) {
- addFactory(list, wf.factoryClass);
+ Collections.sort(ordered, OrderComparator.getInstance());
+ for (Class<? extends ConfigurationFactory> clazz : ordered) {
+ addFactory(list, clazz);
}
// see above comments about double-checked locking
//noinspection NonThreadSafeLazyInitialization
@@ -374,36 +369,6 @@ public abstract class ConfigurationFactory {
}
/**
- * Factory that chooses a ConfigurationFactory based on weighting.
- */
- private static class WeightedFactory implements Comparable<WeightedFactory> {
- private final int weight;
- private final Class<? extends ConfigurationFactory> factoryClass;
-
- /**
- * Constructor.
- * @param weight The weight.
- * @param clazz The class.
- */
- public WeightedFactory(final int weight, final Class<? extends ConfigurationFactory> clazz) {
- this.weight = weight;
- this.factoryClass = clazz;
- }
-
- @Override
- public int compareTo(final WeightedFactory wf) {
- final int w = wf.weight;
- if (weight == w) {
- return 0;
- } else if (weight > w) {
- return -1;
- } else {
- return 1;
- }
- }
- }
-
- /**
* Default Factory.
*/
private static class Factory extends ConfigurationFactory {