Initial implementation of the ClusteredDataStore
[controller.git] / opendaylight / md-sal / clustered-data-store / implementation / src / main / java / org / opendaylight / controller / datastore / internal / ClusteredDataStoreManager.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
11
12 package org.opendaylight.controller.datastore.internal;
13
14 import com.google.common.base.Preconditions;
15 import org.apache.felix.dm.Component;
16 import org.opendaylight.controller.clustering.services.CacheConfigException;
17 import org.opendaylight.controller.clustering.services.CacheExistException;
18 import org.opendaylight.controller.clustering.services.IClusterGlobalServices;
19 import org.opendaylight.controller.datastore.ClusteredDataStore;
20 import org.opendaylight.controller.md.sal.common.api.data.DataModification;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22
23 public class ClusteredDataStoreManager implements ClusteredDataStore {
24
25     private ClusteredDataStoreImpl clusteredDataStore = null;
26     private IClusterGlobalServices clusterGlobalServices = null;
27
28     @Override
29     public DataCommitTransaction<InstanceIdentifier<? extends Object>, Object> requestCommit(DataModification<InstanceIdentifier<? extends Object>, Object> modification) {
30         Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null");
31         return clusteredDataStore.requestCommit(modification);
32     }
33
34     @Override
35     public Object readOperationalData(InstanceIdentifier<? extends Object> path) {
36         Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null");
37         return clusteredDataStore.readOperationalData(path);
38     }
39
40     @Override
41     public Object readConfigurationData(InstanceIdentifier<? extends Object> path) {
42         Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null");
43         return clusteredDataStore.readConfigurationData(path);
44     }
45
46
47     public void setClusterGlobalServices(IClusterGlobalServices clusterGlobalServices){
48         this.clusterGlobalServices = clusterGlobalServices;
49     }
50
51     public void unsetClusterGlobalServices(IClusterGlobalServices clusterGlobalServices){
52         this.clusterGlobalServices = null;
53         this.clusteredDataStore = null;
54     }
55
56
57     /**
58      * Function called by the dependency manager when all the required
59      * dependencies are satisfied
60      *
61      */
62     void init(Component c) {
63         try {
64             clusteredDataStore = new ClusteredDataStoreImpl(clusterGlobalServices);
65         } catch (CacheExistException e) {
66             throw new IllegalStateException("could not construct clusteredDataStore");
67         } catch (CacheConfigException e) {
68             throw new IllegalStateException("could not construct clusteredDataStore");
69         }
70     }
71 }