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

apollo.spring.property.SpringValueRegistry Maven / Gradle / Ivy

The newest version!
package apollo.spring.property;

import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import org.springframework.beans.factory.BeanFactory;

import java.util.Collection;
import java.util.Map;

public class SpringValueRegistry {

  private final Map> registry = Maps.newConcurrentMap();
  private final Object LOCK = new Object();

  public void register(BeanFactory beanFactory, String key, SpringValue springValue) {
    if (!registry.containsKey(beanFactory)) {
      synchronized (LOCK) {
        if (!registry.containsKey(beanFactory)) {
          registry.put(beanFactory, LinkedListMultimap.create());
        }
      }
    }

    registry.get(beanFactory).put(key, springValue);
  }

  public Collection get(BeanFactory beanFactory, String key) {
    Multimap beanFactorySpringValues = registry.get(beanFactory);
    if (beanFactorySpringValues == null) {
      return null;
    }
    return beanFactorySpringValues.get(key);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy