
org.terracotta.management.ServiceLocator Maven / Gradle / Ivy
The newest version!
/*
* 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
© 2015 - 2025 Weber Informatics LLC | Privacy Policy