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

org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider Maven / Gradle / Ivy

Go to download

This jar bundles all the bits of Weld and CDI required for running in a Servlet container.

There is a newer version: 6.0.0.Final
Show newest version
package org.jboss.weld.bootstrap.api.helpers;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.weld.bootstrap.api.Singleton;
import org.jboss.weld.bootstrap.api.SingletonProvider;

/**
 *
 * @author mathieuancelin
 */
public class RegistrySingletonProvider extends SingletonProvider {
    public static final String STATIC_INSTANCE = "STATIC_INSTANCE";

    @Override
    public  Singleton create(Class type) {
        return new RegistrySingleton();
    }

    private static class RegistrySingleton implements Singleton {

        private final Map store = new ConcurrentHashMap();

        public T get(String id) {
            T instance = store.get(id);
            if (instance == null) {
                throw new IllegalStateException("Singleton not set for " + id + " => " + store.keySet());
            }
            return instance;
        }

        public void set(String id, T object) {
            store.put(id, object);
        }

        public void clear(String id) {
            store.remove(id);
        }

        public boolean isSet(String id) {
            return store.containsKey(id);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy