All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.wildfly.clustering.context.DefaultContextualizerFactory Maven / Gradle / Ivy

There is a newer version: 4.0.0.Beta1
Show newest version
/*
 * 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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy