blob: a4ea42864ed7cb8ff98d723d47d1cdc1640d0129 [file] [log] [blame]
Sithara Punnassery9306e6b2017-02-06 15:38:19 -08001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.config.impl;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.apache.felix.scr.annotations.Service;
24import org.onosproject.config.DynamicConfigEvent;
25import org.onosproject.config.DynamicConfigListener;
26import org.onosproject.config.DynamicConfigService;
27import org.onosproject.config.DynamicConfigStore;
28import org.onosproject.config.DynamicConfigStoreDelegate;
29import org.onosproject.config.FailedException;
30import org.onosproject.config.Filter;
31import org.onosproject.config.RpcCaller;
32import org.onosproject.config.RpcCommand;
33import org.onosproject.config.RpcHandler;
34import org.onosproject.config.RpcInput;
35import org.onosproject.config.RpcOutput;
36import org.onosproject.config.model.DataNode;
37import org.onosproject.config.model.ResourceId;
38import org.onosproject.event.AbstractListenerManager;
39import org.onosproject.event.EventDeliveryService;
40import org.slf4j.Logger;
41
42import static org.slf4j.LoggerFactory.getLogger;
43
44/**
45 * Demo application to use the DynamicConfig Service and DynamicConfigStore.
46 *
47 */
48@Component(immediate = true)
49@Service
50public class DynamicConfigManager
51 extends AbstractListenerManager<DynamicConfigEvent, DynamicConfigListener>
52 implements DynamicConfigService {
53 private final Logger log = getLogger(getClass());
54 private final DynamicConfigStoreDelegate storeDelegate = new InternalStoreDelegate();
55 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
56 protected EventDeliveryService eventDispatcher;
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 protected DynamicConfigStore store;
59
60 @Activate
61 public void activate() {
62 store.setDelegate(storeDelegate);
63 log.info("DynamicConfigService Started");
64 }
65
66 @Deactivate
67 public void deactivate() {
68 store.unsetDelegate(storeDelegate);
69 log.info("DynamicConfigService Stopped");
70 }
71
72 @Override
73 public void createNode(ResourceId path, DataNode node) {
74 Boolean stat = false;
75 stat = this.store.addNode(path, node).join();
76 }
77
78 public void createNodeRecursive(ResourceId path, DataNode node) {
79 Boolean stat = false;
80 stat = this.store.addRecursive(path, node).join();
81 }
82
83 public DataNode readNode(ResourceId path, Filter filter) {
84 return store.readNode(path, filter).join();
85 }
86
87 public Integer getNumberOfChildren(ResourceId path, Filter filter) {
88 throw new FailedException("Not yet implemented");
89 }
90
91 public void updateNode(ResourceId path, DataNode node) {
92 throw new FailedException("Not yet implemented");
93 }
94
95 public void deleteNode(ResourceId path) {
96 throw new FailedException("Not yet implemented");
97 }
98
99 public void deleteNodeRecursive(ResourceId path) {
100 throw new FailedException("Not yet implemented");
101 }
102
103 public void updateNodeRecursive(ResourceId path, DataNode node) {
104 throw new FailedException("Not yet implemented");
105 }
106
107 public void replaceNode(ResourceId path, DataNode node) {
108 throw new FailedException("Not yet implemented");
109 }
110
111 public void addConfigListener(ResourceId path, DynamicConfigListener listener) {
112 throw new FailedException("Not yet implemented");
113 }
114
115 public void removeConfigListener(ResourceId path, DynamicConfigListener listener) {
116 throw new FailedException("Not yet implemented");
117 }
118
119 public void registerHandler(RpcHandler handler, RpcCommand command) {
120 throw new FailedException("Not yet implemented");
121 }
122
123 public void unRegisterHandler(RpcHandler handler, RpcCommand command) {
124 //check obj1.getClass().equals(obj2.getClass())
125 throw new FailedException("Not yet implemented");
126 }
127
128 public void invokeRpc(RpcCaller caller, Integer msgId, RpcCommand command, RpcInput input) {
129 throw new FailedException("Not yet implemented");
130 }
131
132 public void rpcResponse(Integer msgId, RpcOutput output) {
133 throw new FailedException("Not yet implemented");
134 }
135 /**
136 * Auxiliary store delegate to receive notification about changes in
137 * the prop configuration store state - by the store itself.
138 */
139 private class InternalStoreDelegate implements DynamicConfigStoreDelegate {
140 public void notify(DynamicConfigEvent event) {
141 // TODO
142 // post(event);
143 }
144 }
145}