2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.sal.dom.broker.impl
10 import org.opendaylight.controller.md.sal.common.api.data.DataModification
11 import org.opendaylight.controller.md.sal.common.api.data.DataCommitHandler.DataCommitTransaction
12 import org.opendaylight.yangtools.yang.common.RpcResult
14 import java.util.concurrent.ConcurrentHashMap
15 import org.opendaylight.controller.sal.common.util.Rpcs
16 import java.util.Collections
17 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
18 import org.opendaylight.yangtools.yang.data.api.CompositeNode
19 import org.opendaylight.controller.sal.core.api.data.DataStore
20 import java.util.HashSet
22 class HashMapDataStore implements DataStore, AutoCloseable {
25 val Map<InstanceIdentifier, CompositeNode> configuration = new ConcurrentHashMap();
26 val Map<InstanceIdentifier, CompositeNode> operational = new ConcurrentHashMap();
30 override containsConfigurationPath(InstanceIdentifier path) {
31 throw new UnsupportedOperationException("TODO: auto-generated method stub")
35 override containsOperationalPath(InstanceIdentifier path) {
36 throw new UnsupportedOperationException("TODO: auto-generated method stub")
39 override getStoredConfigurationPaths() {
43 override getStoredOperationalPaths() {
47 override readConfigurationData(InstanceIdentifier path) {
48 configuration.get(path);
51 override readOperationalData(InstanceIdentifier path) {
52 operational.get(path);
57 override requestCommit(DataModification<InstanceIdentifier, CompositeNode> modification) {
58 return new HashMapDataStoreTransaction(modification, this);
61 def RpcResult<Void> rollback(HashMapDataStoreTransaction transaction) {
62 return Rpcs.getRpcResult(true, null, Collections.emptySet);
65 def RpcResult<Void> finish(HashMapDataStoreTransaction transaction) {
66 val modification = transaction.modification;
67 for (removal : modification.removedConfigurationData) {
68 remove(configuration,removal);
70 for (removal : modification.removedOperationalData) {
71 remove(operational,removal);
73 configuration.putAll(modification.updatedConfigurationData);
74 operational.putAll(modification.updatedOperationalData);
76 return Rpcs.getRpcResult(true, null, Collections.emptySet);
79 def remove(Map<InstanceIdentifier, CompositeNode> map, InstanceIdentifier identifier) {
80 val affected = new HashSet<InstanceIdentifier>();
81 for(path : map.keySet) {
82 if(identifier.contains(path)) {
86 for(pathToRemove : affected) {
87 map.remove(pathToRemove);
99 class HashMapDataStoreTransaction implements //
100 DataCommitTransaction<InstanceIdentifier, CompositeNode> {
102 val DataModification<InstanceIdentifier, CompositeNode> modification
105 val HashMapDataStore datastore;
108 DataModification<InstanceIdentifier, CompositeNode> modify,
109 HashMapDataStore store
111 _modification = modify;
115 override finish() throws IllegalStateException {
116 datastore.finish(this);
120 override getModification() {
124 override rollback() throws IllegalStateException {
125 datastore.rollback(this);