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.net.InetAddress;
13 import java.net.UnknownHostException;
14 import java.util.ArrayList;
15 import java.util.Dictionary;
16 import java.util.List;
17 import java.util.Properties;
19 import java.util.concurrent.ConcurrentHashMap;
20 import java.util.concurrent.ConcurrentMap;
21 import java.util.concurrent.TimeUnit;
23 import javax.transaction.HeuristicMixedException;
24 import javax.transaction.HeuristicRollbackException;
25 import javax.transaction.NotSupportedException;
26 import javax.transaction.RollbackException;
27 import javax.transaction.SystemException;
28 import javax.transaction.Transaction;
30 import org.apache.felix.dm.Component;
31 import org.opendaylight.controller.clustering.services.CacheConfigException;
32 import org.opendaylight.controller.clustering.services.CacheExistException;
33 import org.opendaylight.controller.clustering.services.IClusterServices;
34 import org.opendaylight.controller.clustering.services.IClusterServicesCommon;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
38 public abstract class ClusterManagerCommon implements IClusterServicesCommon {
39 protected String containerName = "";
40 protected static final Logger logger = LoggerFactory
41 .getLogger(ClusterManagerCommon.class);
42 private InetAddress loopbackAddress;
43 private ConcurrentMap<String, ConcurrentMap<?, ?>> caches = new ConcurrentHashMap<String, ConcurrentMap<?, ?>>();
45 protected ClusterManagerCommon() throws UnknownHostException {
46 loopbackAddress = InetAddress.getByName("127.0.0.1");
50 * Function called by the dependency manager when all the required
51 * dependencies are satisfied
54 void init(Component c) {
55 Dictionary props = c.getServiceProperties();
57 this.containerName = (String) props.get("containerName");
58 logger.debug("Running containerName: {}", this.containerName);
60 // In the Global instance case the containerName is empty
61 this.containerName = "";
66 * Function called by the dependency manager when any of the required
67 * dependencies are going away
71 // Clear the caches, will restart on the new life
76 public ConcurrentMap<?, ?> createCache(String cacheName,
77 Set<IClusterServices.cacheMode> cMode) throws CacheExistException,
78 CacheConfigException {
79 ConcurrentMap<?, ?> res = this.caches.get(cacheName);
81 res = new ConcurrentHashMap<Object, Object>();
82 this.caches.put(cacheName, res);
85 throw new CacheExistException();
89 public ConcurrentMap<?, ?> getCache(String cacheName) {
90 return this.caches.get(cacheName);
94 public void destroyCache(String cacheName) {
95 this.caches.remove(cacheName);
99 public boolean existCache(String cacheName) {
100 return (this.caches.get(cacheName) != null);
104 public Set<String> getCacheList() {
105 return this.caches.keySet();
109 public Properties getCacheProperties(String cacheName) {
114 public void tbegin() throws NotSupportedException, SystemException {
118 public void tcommit() throws RollbackException, HeuristicMixedException,
119 HeuristicRollbackException, java.lang.SecurityException,
120 java.lang.IllegalStateException, SystemException {
124 public void tbegin(long timeout, TimeUnit unit) throws NotSupportedException, SystemException {
129 public void trollback() throws java.lang.IllegalStateException,
130 java.lang.SecurityException, SystemException {
134 public Transaction tgetTransaction() throws SystemException {
139 public List<InetAddress> getClusteredControllers() {
140 List<InetAddress> res = new ArrayList<InetAddress>();
141 res.add(loopbackAddress);
146 public InetAddress getMyAddress() {
147 return loopbackAddress;
151 public InetAddress getCoordinatorAddress() {
152 return loopbackAddress;
156 public boolean amICoordinator() {