blob: 68d35f1acc77f0e3c21ec4126bc88ee953034ed5 [file] [log] [blame]
Thomas Vachuskafc7f22d2014-12-04 11:07:01 -08001#set( $symbol_pound = '#' )
2#set( $symbol_dollar = '$' )
3#set( $symbol_escape = '\' )
Thomas Vachuska7399e482014-12-01 21:27:42 -08004/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07005 * Copyright ${year}-present Open Networking Foundation
Thomas Vachuska7399e482014-12-01 21:27:42 -08006 *
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 Vachuskafc7f22d2014-12-04 11:07:01 -080019package ${package};
Thomas Vachuska7399e482014-12-01 21:27:42 -080020
Thomas Vachuska821618f2019-03-30 10:43:28 -070021import org.onosproject.cfg.ComponentConfigService;
22import org.osgi.service.component.ComponentContext;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070023import org.osgi.service.component.annotations.Activate;
24import org.osgi.service.component.annotations.Component;
25import org.osgi.service.component.annotations.Deactivate;
Thomas Vachuska821618f2019-03-30 10:43:28 -070026import org.osgi.service.component.annotations.Modified;
27import org.osgi.service.component.annotations.Reference;
28import org.osgi.service.component.annotations.ReferenceCardinality;
Thomas Vachuska7399e482014-12-01 21:27:42 -080029import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
Thomas Vachuska821618f2019-03-30 10:43:28 -070032import java.util.Dictionary;
33import java.util.Properties;
34
35import static org.onlab.util.Tools.get;
36
Thomas Vachuska7399e482014-12-01 21:27:42 -080037/**
38 * Skeletal ONOS application component.
39 */
Thomas Vachuska821618f2019-03-30 10:43:28 -070040@Component(immediate = true,
41 service = {SomeInterface.class},
42 property = {
43 "someProperty=Some Default String Value",
44 })
45public class AppComponent implements SomeInterface {
Thomas Vachuska7399e482014-12-01 21:27:42 -080046
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070047 private final Logger log = LoggerFactory.getLogger(getClass());
Thomas Vachuska7399e482014-12-01 21:27:42 -080048
Thomas Vachuska821618f2019-03-30 10:43:28 -070049 /** Some configurable property. */
50 private String someProperty;
51
52 @Reference(cardinality = ReferenceCardinality.MANDATORY)
53 protected ComponentConfigService cfgService;
54
Thomas Vachuska7399e482014-12-01 21:27:42 -080055 @Activate
56 protected void activate() {
Thomas Vachuska821618f2019-03-30 10:43:28 -070057 cfgService.registerProperties(getClass());
Thomas Vachuska7399e482014-12-01 21:27:42 -080058 log.info("Started");
59 }
60
61 @Deactivate
62 protected void deactivate() {
Thomas Vachuska821618f2019-03-30 10:43:28 -070063 cfgService.unregisterProperties(getClass(), false);
Thomas Vachuska7399e482014-12-01 21:27:42 -080064 log.info("Stopped");
65 }
66
Thomas Vachuska821618f2019-03-30 10:43:28 -070067 @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 Vachuska7399e482014-12-01 21:27:42 -080081}