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 com.google.common.collect.ImmutableSet; |
| 22 | import org.onosproject.cfg.ComponentConfigService; |
| 23 | import org.osgi.service.component.ComponentContext; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 24 | import org.osgi.service.component.annotations.Activate; |
| 25 | import org.osgi.service.component.annotations.Component; |
| 26 | import org.osgi.service.component.annotations.Deactivate; |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 27 | import org.osgi.service.component.annotations.Modified; |
| 28 | import org.osgi.service.component.annotations.Reference; |
| 29 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 33 | import java.util.Dictionary; |
| 34 | import java.util.Properties; |
| 35 | |
| 36 | import static org.onlab.util.Tools.get; |
| 37 | |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 38 | /** |
| 39 | * Skeletal ONOS application component. |
| 40 | */ |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 41 | @Component(immediate = true, |
| 42 | service = {SomeInterface.class}, |
| 43 | property = { |
| 44 | "someProperty=Some Default String Value", |
| 45 | }) |
| 46 | public class AppComponent implements SomeInterface { |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 47 | |
Thomas Vachuska | a2ae422 | 2015-04-29 18:42:09 -0700 | [diff] [blame] | 48 | private final Logger log = LoggerFactory.getLogger(getClass()); |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 49 | |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 50 | /** Some configurable property. */ |
| 51 | private String someProperty; |
| 52 | |
| 53 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
| 54 | protected ComponentConfigService cfgService; |
| 55 | |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 56 | @Activate |
| 57 | protected void activate() { |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 58 | cfgService.registerProperties(getClass()); |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 59 | log.info("Started"); |
| 60 | } |
| 61 | |
| 62 | @Deactivate |
| 63 | protected void deactivate() { |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 64 | cfgService.unregisterProperties(getClass(), false); |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 65 | log.info("Stopped"); |
| 66 | } |
| 67 | |
Thomas Vachuska | 821618f | 2019-03-30 10:43:28 -0700 | [diff] [blame] | 68 | @Modified |
| 69 | public void modified(ComponentContext context) { |
| 70 | Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); |
| 71 | if (context != null) { |
| 72 | someProperty = get(properties, "someProperty"); |
| 73 | } |
| 74 | log.info("Reconfigured"); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void someMethod() { |
| 79 | log.info("Invoked"); |
| 80 | } |
| 81 | |
Thomas Vachuska | 7399e48 | 2014-12-01 21:27:42 -0800 | [diff] [blame] | 82 | } |