3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.clustering.stub.internal;
12 import java.util.ArrayList;
13 import java.util.concurrent.ConcurrentHashMap;
14 import java.net.UnknownHostException;
15 import java.net.InetAddress;
16 import java.util.List;
17 import java.util.Properties;
19 import java.util.concurrent.ConcurrentMap;
21 import javax.transaction.HeuristicMixedException;
22 import javax.transaction.HeuristicRollbackException;
23 import javax.transaction.NotSupportedException;
24 import javax.transaction.RollbackException;
25 import javax.transaction.SystemException;
26 import javax.transaction.Transaction;
27 import javax.transaction.TransactionManager;
29 import org.opendaylight.controller.clustering.services.CacheConfigException;
30 import org.opendaylight.controller.clustering.services.CacheExistException;
31 import org.opendaylight.controller.clustering.services.CacheListenerAddException;
32 import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
33 import org.opendaylight.controller.clustering.services.IClusterServices;
34 import org.opendaylight.controller.clustering.services.IClusterServicesCommon;
35 import org.opendaylight.controller.clustering.services.ICoordinatorChangeAware;
36 import org.opendaylight.controller.clustering.services.IListenRoleChange;
37 import org.opendaylight.controller.clustering.services.ListenRoleChangeAddException;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 import java.util.Dictionary;
42 import java.util.Collections;
43 import java.util.HashSet;
44 import org.apache.felix.dm.Component;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
48 public abstract class ClusterManagerCommon implements IClusterServicesCommon {
49 protected String containerName = "";
50 protected static final Logger logger = LoggerFactory
51 .getLogger(ClusterManagerCommon.class);
52 private InetAddress loopbackAddress;
53 private ConcurrentMap<String, ConcurrentMap<?, ?>> caches = new ConcurrentHashMap<String, ConcurrentMap<?, ?>>();
55 protected ClusterManagerCommon() throws UnknownHostException {
56 loopbackAddress = InetAddress.getByName("127.0.0.1");
60 * Function called by the dependency manager when all the required
61 * dependencies are satisfied
64 void init(Component c) {
65 Dictionary props = c.getServiceProperties();
67 this.containerName = (String) props.get("containerName");
68 logger.debug("Running containerName: {}", this.containerName);
70 // In the Global instance case the containerName is empty
71 this.containerName = "";
76 * Function called by the dependency manager when any of the required
77 * dependencies are going away
81 // Clear the caches, will restart on the new life
86 public ConcurrentMap<?, ?> createCache(String cacheName,
87 Set<IClusterServices.cacheMode> cMode) throws CacheExistException,
88 CacheConfigException {
89 ConcurrentMap<?, ?> res = this.caches.get(cacheName);
91 res = new ConcurrentHashMap<Object, Object>();
92 this.caches.put(cacheName, res);
95 throw new CacheExistException();
99 public ConcurrentMap<?, ?> getCache(String cacheName) {
100 return this.caches.get(cacheName);
104 public void destroyCache(String cacheName) {
105 this.caches.remove(cacheName);
109 public boolean existCache(String cacheName) {
110 return (this.caches.get(cacheName) != null);
114 public Set<String> getCacheList() {
115 return this.caches.keySet();
119 public Properties getCacheProperties(String cacheName) {
124 public void tbegin() throws NotSupportedException, SystemException {
128 public void tcommit() throws RollbackException, HeuristicMixedException,
129 HeuristicRollbackException, java.lang.SecurityException,
130 java.lang.IllegalStateException, SystemException {
134 public void trollback() throws java.lang.IllegalStateException,
135 java.lang.SecurityException, SystemException {
139 public Transaction tgetTransaction() throws SystemException {
144 public List<InetAddress> getClusteredControllers() {
145 List<InetAddress> res = new ArrayList<InetAddress>();
146 res.add(loopbackAddress);
151 public InetAddress getMyAddress() {
152 return loopbackAddress;
156 public InetAddress getCoordinatorAddress() {
157 return loopbackAddress;
161 public boolean amICoordinator() {