org.terracotta.management.ServiceLocator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ehcache Show documentation
Show all versions of ehcache Show documentation
Ehcache is an open source, standards-based cache used to boost performance,
offload the database and simplify scalability. Ehcache is robust, proven and full-featured and
this has made it the most widely-used Java-based cache.
/*
* All content copyright (c) 2003-2012 Terracotta, Inc., except as may otherwise be noted in a separate copyright
* notice. All rights reserved.
*/
package org.terracotta.management;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
/**
* Implements a dynamic service locator, (see
* http://martinfowler.com/articles/injection.html#UsingAServiceLocator)
*
* The intended use case is the following :
* 1) Initialization
* ServiceLocator locator = new ServiceLocator();
* ConfigServiceImpl configServiceImpl = new ConfigServiceImpl();
* AgentEntity agentEntity = new AgentEntity();
* locator.loadService(ConfigService.class, configServiceImpl).loadService(Serializable.class, agentEntity);
* ServiceLocator.load(locator);
*
* 2) Use of the service locator in the same class loader
* ConfigService value = ServiceLocator.locate(ConfigService.class);
*
* You can not load it more than once (unless you call unload()); you can not start locating before load() was called
*
*
*/
public class ServiceLocator {
private static final AtomicReference