blob: 473ea6ea4435824ca98e092b0430635be7d585e5 [file] [log] [blame]
tom0755a362014-09-24 11:54:43 -07001package org.onlab.onos.foo;
2
3import org.apache.felix.scr.annotations.Activate;
4import org.apache.felix.scr.annotations.Component;
5import org.apache.felix.scr.annotations.Deactivate;
6import org.apache.felix.scr.annotations.Reference;
7import org.apache.felix.scr.annotations.ReferenceCardinality;
8import org.onlab.onos.cluster.ClusterEvent;
9import org.onlab.onos.cluster.ClusterEventListener;
10import org.onlab.onos.cluster.ClusterService;
tom0768a022014-09-24 16:16:16 -070011import org.onlab.onos.net.device.DeviceEvent;
12import org.onlab.onos.net.device.DeviceListener;
13import org.onlab.onos.net.device.DeviceService;
tom4e969042014-10-07 00:47:30 -070014import org.onlab.onos.net.intent.IntentEvent;
15import org.onlab.onos.net.intent.IntentListener;
16import org.onlab.onos.net.intent.IntentService;
tom0755a362014-09-24 11:54:43 -070017import org.slf4j.Logger;
18
19import static org.slf4j.LoggerFactory.getLogger;
20
21/**
22 * Playground app component.
23 */
24@Component(immediate = true)
25public class FooComponent {
26
27 private final Logger log = getLogger(getClass());
28
29 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
30 protected ClusterService clusterService;
31
tom0768a022014-09-24 16:16:16 -070032 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
33 protected DeviceService deviceService;
34
tom4e969042014-10-07 00:47:30 -070035 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
36 protected IntentService intentService;
37
tom0768a022014-09-24 16:16:16 -070038 private final ClusterEventListener clusterListener = new InnerClusterListener();
39 private final DeviceListener deviceListener = new InnerDeviceListener();
tom4e969042014-10-07 00:47:30 -070040 private final IntentListener intentListener = new InnerIntentListener();
tom0755a362014-09-24 11:54:43 -070041
42 @Activate
43 public void activate() {
44 clusterService.addListener(clusterListener);
tom0768a022014-09-24 16:16:16 -070045 deviceService.addListener(deviceListener);
tom4e969042014-10-07 00:47:30 -070046 intentService.addListener(intentListener);
tom0755a362014-09-24 11:54:43 -070047 log.info("Started");
48 }
49
50 @Deactivate
51 public void deactivate() {
52 clusterService.removeListener(clusterListener);
tom0768a022014-09-24 16:16:16 -070053 deviceService.removeListener(deviceListener);
tom4e969042014-10-07 00:47:30 -070054 intentService.removeListener(intentListener);
tom0755a362014-09-24 11:54:43 -070055 log.info("Stopped");
56 }
57
58 private class InnerClusterListener implements ClusterEventListener {
59 @Override
60 public void event(ClusterEvent event) {
61 log.info("WOOOOT! {}", event);
62 }
63 }
tom0768a022014-09-24 16:16:16 -070064
65 private class InnerDeviceListener implements DeviceListener {
66 @Override
67 public void event(DeviceEvent event) {
68 log.info("YEEEEHAAAAW! {}", event);
69 }
70 }
tom4e969042014-10-07 00:47:30 -070071
72 private class InnerIntentListener implements IntentListener {
73 @Override
74 public void event(IntentEvent event) {
75 String message;
76 if (event.type() == IntentEvent.Type.SUBMITTED) {
77 message = "WOW! It looks like someone has some intentions: {}";
78 } else if (event.type() == IntentEvent.Type.INSTALLED) {
79 message = "AWESOME! So far things are going great: {}";
80 } else if (event.type() == IntentEvent.Type.WITHDRAWN) {
81 message = "HMMM! Ambitions are fading apparently: {}";
82 } else {
83 message = "CRAP!!! Things are not turning out as intended: {}";
84 }
85 log.info(message, event.subject());
86 }
87 }
tom0755a362014-09-24 11:54:43 -070088}
89
90