* ============LICENSE_END============================================
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.aai.champ.graph.impl;
+package org.onap.aai.champcore.graph.impl;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.onap.aai.champ.ChampAPI;
-import org.onap.aai.champ.ChampGraph;
+import org.onap.aai.champcore.ChampAPI;
+import org.onap.aai.champcore.ChampGraph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOGGER = LoggerFactory.getLogger(ChampAPIImpl.class);
private final AtomicBoolean shutdown;
- private final ChampGraph.Type type;
+ private final String type;
private final ConcurrentHashMap<String, ChampGraph> graphs;
- public ChampAPIImpl(ChampGraph.Type type) {
+ public ChampAPIImpl(String type) {
this.type = type;
this.graphs = new ConcurrentHashMap<String, ChampGraph> ();
this.shutdown = new AtomicBoolean(false);
}
private ConcurrentHashMap<String, ChampGraph> getGraphs() {
- return graphs;
+ return graphs;
}
@Override
public ChampGraph getGraph(String graphName) {
- if (shutdown.get()) throw new IllegalStateException("Cannot call getGraph() after shutdown() has been initiated");
+ if (shutdown.get()) {
+ throw new IllegalStateException("Cannot call getGraph() after shutdown() has been initiated");
+ }
- if (getGraphs().containsKey(graphName)) return getGraphs().get(graphName);
+ if (getGraphs().containsKey(graphName)) {
+ return getGraphs().get(graphName);
+ }
- final ChampGraph graph = ChampGraph.Factory.newInstance(type, graphName);
-
- final ChampGraph existingGraph = getGraphs().putIfAbsent(graphName, graph);
-
- if (existingGraph == null) return graph;
-
- return existingGraph;
+ // At this point, we know a graph with this name doesn't exist. Create and return it.
+ final ChampGraph graph = new InMemoryChampGraphImpl.Builder().build();
+ graphs.put(graphName, graph);
+ return graph;
}
@Override
}
@Override
- public ChampGraph.Type getType() {
+ public String getType() {
return type;
}