Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.config.impl; |
| 17 | |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 18 | import com.google.common.annotations.Beta; |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 19 | import org.apache.felix.scr.annotations.Activate; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Deactivate; |
| 22 | import org.apache.felix.scr.annotations.Reference; |
| 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
| 24 | import org.apache.felix.scr.annotations.Service; |
| 25 | import org.onosproject.config.DynamicConfigEvent; |
| 26 | import org.onosproject.config.DynamicConfigListener; |
| 27 | import org.onosproject.config.DynamicConfigService; |
| 28 | import org.onosproject.config.DynamicConfigStore; |
| 29 | import org.onosproject.config.DynamicConfigStoreDelegate; |
| 30 | import org.onosproject.config.FailedException; |
| 31 | import org.onosproject.config.Filter; |
| 32 | import org.onosproject.config.RpcCaller; |
| 33 | import org.onosproject.config.RpcCommand; |
| 34 | import org.onosproject.config.RpcHandler; |
| 35 | import org.onosproject.config.RpcInput; |
| 36 | import org.onosproject.config.RpcOutput; |
| 37 | import org.onosproject.config.model.DataNode; |
| 38 | import org.onosproject.config.model.ResourceId; |
| 39 | import org.onosproject.event.AbstractListenerManager; |
| 40 | import org.onosproject.event.EventDeliveryService; |
| 41 | import org.slf4j.Logger; |
| 42 | |
| 43 | import static org.slf4j.LoggerFactory.getLogger; |
| 44 | |
| 45 | /** |
| 46 | * Demo application to use the DynamicConfig Service and DynamicConfigStore. |
| 47 | * |
| 48 | */ |
Sithara Punnassery | 0620879 | 2017-02-10 16:25:29 -0800 | [diff] [blame] | 49 | @Beta |
Sithara Punnassery | 9306e6b | 2017-02-06 15:38:19 -0800 | [diff] [blame] | 50 | @Component(immediate = true) |
| 51 | @Service |
| 52 | public class DynamicConfigManager |
| 53 | extends AbstractListenerManager<DynamicConfigEvent, DynamicConfigListener> |
| 54 | implements DynamicConfigService { |
| 55 | private final Logger log = getLogger(getClass()); |
| 56 | private final DynamicConfigStoreDelegate storeDelegate = new InternalStoreDelegate(); |
| 57 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 58 | protected EventDeliveryService eventDispatcher; |
| 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 60 | protected DynamicConfigStore store; |
| 61 | |
| 62 | @Activate |
| 63 | public void activate() { |
| 64 | store.setDelegate(storeDelegate); |
| 65 | log.info("DynamicConfigService Started"); |
| 66 | } |
| 67 | |
| 68 | @Deactivate |
| 69 | public void deactivate() { |
| 70 | store.unsetDelegate(storeDelegate); |
| 71 | log.info("DynamicConfigService Stopped"); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void createNode(ResourceId path, DataNode node) { |
| 76 | Boolean stat = false; |
| 77 | stat = this.store.addNode(path, node).join(); |
| 78 | } |
| 79 | |
| 80 | public void createNodeRecursive(ResourceId path, DataNode node) { |
| 81 | Boolean stat = false; |
| 82 | stat = this.store.addRecursive(path, node).join(); |
| 83 | } |
| 84 | |
| 85 | public DataNode readNode(ResourceId path, Filter filter) { |
| 86 | return store.readNode(path, filter).join(); |
| 87 | } |
| 88 | |
| 89 | public Integer getNumberOfChildren(ResourceId path, Filter filter) { |
| 90 | throw new FailedException("Not yet implemented"); |
| 91 | } |
| 92 | |
| 93 | public void updateNode(ResourceId path, DataNode node) { |
| 94 | throw new FailedException("Not yet implemented"); |
| 95 | } |
| 96 | |
| 97 | public void deleteNode(ResourceId path) { |
| 98 | throw new FailedException("Not yet implemented"); |
| 99 | } |
| 100 | |
| 101 | public void deleteNodeRecursive(ResourceId path) { |
| 102 | throw new FailedException("Not yet implemented"); |
| 103 | } |
| 104 | |
| 105 | public void updateNodeRecursive(ResourceId path, DataNode node) { |
| 106 | throw new FailedException("Not yet implemented"); |
| 107 | } |
| 108 | |
| 109 | public void replaceNode(ResourceId path, DataNode node) { |
| 110 | throw new FailedException("Not yet implemented"); |
| 111 | } |
| 112 | |
| 113 | public void addConfigListener(ResourceId path, DynamicConfigListener listener) { |
| 114 | throw new FailedException("Not yet implemented"); |
| 115 | } |
| 116 | |
| 117 | public void removeConfigListener(ResourceId path, DynamicConfigListener listener) { |
| 118 | throw new FailedException("Not yet implemented"); |
| 119 | } |
| 120 | |
| 121 | public void registerHandler(RpcHandler handler, RpcCommand command) { |
| 122 | throw new FailedException("Not yet implemented"); |
| 123 | } |
| 124 | |
| 125 | public void unRegisterHandler(RpcHandler handler, RpcCommand command) { |
| 126 | //check obj1.getClass().equals(obj2.getClass()) |
| 127 | throw new FailedException("Not yet implemented"); |
| 128 | } |
| 129 | |
| 130 | public void invokeRpc(RpcCaller caller, Integer msgId, RpcCommand command, RpcInput input) { |
| 131 | throw new FailedException("Not yet implemented"); |
| 132 | } |
| 133 | |
| 134 | public void rpcResponse(Integer msgId, RpcOutput output) { |
| 135 | throw new FailedException("Not yet implemented"); |
| 136 | } |
| 137 | /** |
| 138 | * Auxiliary store delegate to receive notification about changes in |
| 139 | * the prop configuration store state - by the store itself. |
| 140 | */ |
| 141 | private class InternalStoreDelegate implements DynamicConfigStoreDelegate { |
| 142 | public void notify(DynamicConfigEvent event) { |
| 143 | // TODO |
| 144 | // post(event); |
| 145 | } |
| 146 | } |
| 147 | } |