Clean all unused and redundant imports in controller.
[controller.git] / opendaylight / clustering / stub / src / main / java / org / opendaylight / controller / clustering / stub / internal / ClusterManagerCommon.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.clustering.stub.internal;
11
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;
18 import java.util.Set;
19 import java.util.concurrent.ConcurrentMap;
20
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
28 import org.opendaylight.controller.clustering.services.CacheConfigException;
29 import org.opendaylight.controller.clustering.services.CacheExistException;
30 import org.opendaylight.controller.clustering.services.IClusterServices;
31 import org.opendaylight.controller.clustering.services.IClusterServicesCommon;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 import java.util.Dictionary;
36 import org.apache.felix.dm.Component;
37
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<?, ?>>();
44
45     protected ClusterManagerCommon() throws UnknownHostException {
46         loopbackAddress = InetAddress.getByName("127.0.0.1");
47     }
48
49     /**
50      * Function called by the dependency manager when all the required
51      * dependencies are satisfied
52      *
53      */
54     void init(Component c) {
55         Dictionary props = c.getServiceProperties();
56         if (props != null) {
57             this.containerName = (String) props.get("containerName");
58             logger.debug("Running containerName: {}", this.containerName);
59         } else {
60             // In the Global instance case the containerName is empty
61             this.containerName = "";
62         }
63     }
64
65     /**
66      * Function called by the dependency manager when any of the required
67      * dependencies are going away
68      *
69      */
70     void destroy() {
71         // Clear the caches, will restart on the new life
72         this.caches.clear();
73     }
74
75     @Override
76     public ConcurrentMap<?, ?> createCache(String cacheName,
77             Set<IClusterServices.cacheMode> cMode) throws CacheExistException,
78             CacheConfigException {
79         ConcurrentMap<?, ?> res = this.caches.get(cacheName);
80         if (res == null) {
81             res = new ConcurrentHashMap<Object, Object>();
82             this.caches.put(cacheName, res);
83             return res;
84         }
85         throw new CacheExistException();
86     }
87
88     @Override
89     public ConcurrentMap<?, ?> getCache(String cacheName) {
90         return this.caches.get(cacheName);
91     }
92
93     @Override
94     public void destroyCache(String cacheName) {
95         this.caches.remove(cacheName);
96     }
97
98     @Override
99     public boolean existCache(String cacheName) {
100         return (this.caches.get(cacheName) != null);
101     }
102
103     @Override
104     public Set<String> getCacheList() {
105         return this.caches.keySet();
106     }
107
108     @Override
109     public Properties getCacheProperties(String cacheName) {
110         return null;
111     }
112
113     @Override
114     public void tbegin() throws NotSupportedException, SystemException {
115     }
116
117     @Override
118     public void tcommit() throws RollbackException, HeuristicMixedException,
119             HeuristicRollbackException, java.lang.SecurityException,
120             java.lang.IllegalStateException, SystemException {
121     }
122
123     @Override
124     public void trollback() throws java.lang.IllegalStateException,
125             java.lang.SecurityException, SystemException {
126     }
127
128     @Override
129     public Transaction tgetTransaction() throws SystemException {
130         return null;
131     }
132
133     @Override
134     public List<InetAddress> getClusteredControllers() {
135         List<InetAddress> res = new ArrayList<InetAddress>();
136         res.add(loopbackAddress);
137         return res;
138     }
139
140     @Override
141     public InetAddress getMyAddress() {
142         return loopbackAddress;
143     }
144
145     @Override
146     public InetAddress getCoordinatorAddress() {
147         return loopbackAddress;
148     }
149
150     @Override
151     public boolean amICoordinator() {
152         return true;
153     }
154 }