org.wildfly.clustering.context.DefaultContextualizerFactory Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.clustering.context;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ServiceLoader;
/**
* Default {@link Contextualizer} factory that applies a number of contexts.
* @author Paul Ferraro
*/
public enum DefaultContextualizerFactory implements ContextualizerFactory {
INSTANCE;
private final List factories = new LinkedList<>();
DefaultContextualizerFactory() {
this.factories.add(new ContextualizerFactory() {
@Override
public Contextualizer createContextualizer(ClassLoader loader) {
return Contextualizer.withContextProvider(ContextClassLoaderReference.INSTANCE.provide(loader));
}
});
ServiceLoader.load(ContextualizerFactory.class, ContextualizerFactory.class.getClassLoader()).forEach(this.factories::add);
}
@Override
public Contextualizer createContextualizer(ClassLoader loader) {
List contextualizers = new ArrayList<>(this.factories.size());
for (ContextualizerFactory factory : this.factories) {
contextualizers.add(factory.createContextualizer(loader));
}
return Contextualizer.composite(contextualizers);
}
}