Thomas Vachuska | fc7f22d | 2014-12-04 11:07:01 -0800 | [diff] [blame] | 1 | #set( $symbol_pound = '#' ) |
| 2 | #set( $symbol_dollar = '$' ) |
| 3 | #set( $symbol_escape = '\' ) |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 4 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 5 | * Copyright ${year}-present Open Networking Foundation |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
Thomas Vachuska | fc7f22d | 2014-12-04 11:07:01 -0800 | [diff] [blame] | 19 | package ${package}; |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 20 | |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 21 | import org.onosproject.cfg.ComponentConfigService; |
| 22 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 23 | import org.osgi.service.component.annotations.Activate; |
| 24 | import org.osgi.service.component.annotations.Component; |
| 25 | import org.osgi.service.component.annotations.Deactivate; |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 26 | import org.osgi.service.component.annotations.Modified; |
| 27 | import org.osgi.service.component.annotations.Reference; |
| 28 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 29 | import org.slf4j.Logger; |
| 30 | import org.slf4j.LoggerFactory; |
| 31 | |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 32 | import java.util.Dictionary; |
| 33 | import java.util.Properties; |
| 34 | |
| 35 | import static org.onlab.util.Tools.get; |
| 36 | |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 37 | /** |
| 38 | * Skeletal ONOS application component. |
| 39 | */ |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 40 | @Component(immediate = true, |
| 41 | service = {SomeInterface.class}, |
| 42 | property = { |
| 43 | "someProperty=Some Default String Value", |
| 44 | }) |
| 45 | public class AppComponent implements SomeInterface { |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 46 | |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 47 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 48 | |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 49 | /** Some configurable property. */ |
| 50 | private String someProperty; |
| 51 | |
| 52 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 53 | protected ComponentConfigService cfgService; |
| 54 | |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 55 | @Activate |
| 56 | protected void activate() { |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 57 | cfgService.registerProperties(getClass()); |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 58 | log.info("Started"); |
| 59 | } |
| 60 | |
| 61 | @Deactivate |
| 62 | protected void deactivate() { |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 63 | cfgService.unregisterProperties(getClass(), false); |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 64 | log.info("Stopped"); |
| 65 | } |
| 66 | |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 67 | @Modified |
| 68 | public void modified(ComponentContext context) { |
| 69 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 70 | if (context != null) { |
| 71 | someProperty = get(properties, "someProperty"); |
| 72 | } |
| 73 | log.info("Reconfigured"); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void someMethod() { |
| 78 | log.info("Invoked"); |
| 79 | } |
| 80 | |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 81 | } |