blob: f7f64780f2a927a7e81bb88fe44091bd7b6c6b7e [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
tom0755a362014-09-24 11:54:43 -070016package org.onlab.onos.foo;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.onlab.onos.cluster.ClusterEvent;
24import org.onlab.onos.cluster.ClusterEventListener;
25import org.onlab.onos.cluster.ClusterService;
tom0768a022014-09-24 16:16:16 -070026import org.onlab.onos.net.device.DeviceEvent;
27import org.onlab.onos.net.device.DeviceListener;
28import org.onlab.onos.net.device.DeviceService;
tom4e969042014-10-07 00:47:30 -070029import org.onlab.onos.net.intent.IntentEvent;
30import org.onlab.onos.net.intent.IntentListener;
31import org.onlab.onos.net.intent.IntentService;
tom0755a362014-09-24 11:54:43 -070032import org.slf4j.Logger;
33
34import static org.slf4j.LoggerFactory.getLogger;
35
36/**
37 * Playground app component.
38 */
39@Component(immediate = true)
40public class FooComponent {
41
42 private final Logger log = getLogger(getClass());
43
44 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
45 protected ClusterService clusterService;
46
tom0768a022014-09-24 16:16:16 -070047 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 protected DeviceService deviceService;
49
tom4e969042014-10-07 00:47:30 -070050 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 protected IntentService intentService;
52
tom0768a022014-09-24 16:16:16 -070053 private final ClusterEventListener clusterListener = new InnerClusterListener();
54 private final DeviceListener deviceListener = new InnerDeviceListener();
tom4e969042014-10-07 00:47:30 -070055 private final IntentListener intentListener = new InnerIntentListener();
tom0755a362014-09-24 11:54:43 -070056
57 @Activate
58 public void activate() {
59 clusterService.addListener(clusterListener);
tom0768a022014-09-24 16:16:16 -070060 deviceService.addListener(deviceListener);
tom4e969042014-10-07 00:47:30 -070061 intentService.addListener(intentListener);
tom0755a362014-09-24 11:54:43 -070062 log.info("Started");
63 }
64
65 @Deactivate
66 public void deactivate() {
67 clusterService.removeListener(clusterListener);
tom0768a022014-09-24 16:16:16 -070068 deviceService.removeListener(deviceListener);
tom4e969042014-10-07 00:47:30 -070069 intentService.removeListener(intentListener);
tom0755a362014-09-24 11:54:43 -070070 log.info("Stopped");
71 }
72
73 private class InnerClusterListener implements ClusterEventListener {
74 @Override
75 public void event(ClusterEvent event) {
76 log.info("WOOOOT! {}", event);
77 }
78 }
tom0768a022014-09-24 16:16:16 -070079
80 private class InnerDeviceListener implements DeviceListener {
81 @Override
82 public void event(DeviceEvent event) {
83 log.info("YEEEEHAAAAW! {}", event);
84 }
85 }
tom4e969042014-10-07 00:47:30 -070086
87 private class InnerIntentListener implements IntentListener {
88 @Override
89 public void event(IntentEvent event) {
90 String message;
91 if (event.type() == IntentEvent.Type.SUBMITTED) {
92 message = "WOW! It looks like someone has some intentions: {}";
93 } else if (event.type() == IntentEvent.Type.INSTALLED) {
94 message = "AWESOME! So far things are going great: {}";
95 } else if (event.type() == IntentEvent.Type.WITHDRAWN) {
96 message = "HMMM! Ambitions are fading apparently: {}";
97 } else {
98 message = "CRAP!!! Things are not turning out as intended: {}";
99 }
100 log.info(message, event.subject());
101 }
102 }
tom0755a362014-09-24 11:54:43 -0700103}
104
105