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