blob: c2fc6428c11631fddde111737d4b9cedf110fd20 [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 com.google.common.collect.ImmutableSet;
22import org.onosproject.cfg.ComponentConfigService;
23import org.osgi.service.component.ComponentContext;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070024import org.osgi.service.component.annotations.Activate;
25import org.osgi.service.component.annotations.Component;
26import org.osgi.service.component.annotations.Deactivate;
Thomas Vachuska821618f2019-03-30 10:43:28 -070027import org.osgi.service.component.annotations.Modified;
28import org.osgi.service.component.annotations.Reference;
29import org.osgi.service.component.annotations.ReferenceCardinality;
Thomas Vachuska7399e482014-12-01 21:27:42 -080030import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
Thomas Vachuska821618f2019-03-30 10:43:28 -070033import java.util.Dictionary;
34import java.util.Properties;
35
36import static org.onlab.util.Tools.get;
37
Thomas Vachuska7399e482014-12-01 21:27:42 -080038/**
39 * Skeletal ONOS application component.
40 */
Thomas Vachuska821618f2019-03-30 10:43:28 -070041@Component(immediate = true,
42 service = {SomeInterface.class},
43 property = {
44 "someProperty=Some Default String Value",
45 })
46public class AppComponent implements SomeInterface {
Thomas Vachuska7399e482014-12-01 21:27:42 -080047
Thomas Vachuskaa2ae4222015-04-29 18:42:09 -070048 private final Logger log = LoggerFactory.getLogger(getClass());
Thomas Vachuska7399e482014-12-01 21:27:42 -080049
Thomas Vachuska821618f2019-03-30 10:43:28 -070050 /** Some configurable property. */
51 private String someProperty;
52
53 @Reference(cardinality = ReferenceCardinality.MANDATORY)
54 protected ComponentConfigService cfgService;
55
Thomas Vachuska7399e482014-12-01 21:27:42 -080056 @Activate
57 protected void activate() {
Thomas Vachuska821618f2019-03-30 10:43:28 -070058 cfgService.registerProperties(getClass());
Thomas Vachuska7399e482014-12-01 21:27:42 -080059 log.info("Started");
60 }
61
62 @Deactivate
63 protected void deactivate() {
Thomas Vachuska821618f2019-03-30 10:43:28 -070064 cfgService.unregisterProperties(getClass(), false);
Thomas Vachuska7399e482014-12-01 21:27:42 -080065 log.info("Stopped");
66 }
67
Thomas Vachuska821618f2019-03-30 10:43:28 -070068 @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 Vachuska7399e482014-12-01 21:27:42 -080082}