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

com.ctrip.framework.apollo.spring.property.SpringValueRegistry Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package com.ctrip.framework.apollo.spring.property;

import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.Map;
import org.springframework.beans.factory.BeanFactory;

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 - 2025 Weber Informatics LLC | Privacy Policy