blob: 832d4c61fd0214d2b947b856d2d99fce4a1936a4 [file] [log] [blame]
Thomas Vachuska781d18b2014-10-27 10:31:25 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom0755a362014-09-24 11:54:43 -070019package org.onlab.onos.foo;
20
21import org.apache.felix.scr.annotations.Activate;
22import org.apache.felix.scr.annotations.Component;
23import org.apache.felix.scr.annotations.Deactivate;
24import org.apache.felix.scr.annotations.Reference;
25import org.apache.felix.scr.annotations.ReferenceCardinality;
26import org.onlab.onos.cluster.ClusterEvent;
27import org.onlab.onos.cluster.ClusterEventListener;
28import org.onlab.onos.cluster.ClusterService;
tom0768a022014-09-24 16:16:16 -070029import org.onlab.onos.net.device.DeviceEvent;
30import org.onlab.onos.net.device.DeviceListener;
31import org.onlab.onos.net.device.DeviceService;
tom4e969042014-10-07 00:47:30 -070032import org.onlab.onos.net.intent.IntentEvent;
33import org.onlab.onos.net.intent.IntentListener;
34import org.onlab.onos.net.intent.IntentService;
tom0755a362014-09-24 11:54:43 -070035import org.slf4j.Logger;
36
37import static org.slf4j.LoggerFactory.getLogger;
38
39/**
40 * Playground app component.
41 */
42@Component(immediate = true)
43public class FooComponent {
44
45 private final Logger log = getLogger(getClass());
46
47 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
48 protected ClusterService clusterService;
49
tom0768a022014-09-24 16:16:16 -070050 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
51 protected DeviceService deviceService;
52
tom4e969042014-10-07 00:47:30 -070053 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 protected IntentService intentService;
55
tom0768a022014-09-24 16:16:16 -070056 private final ClusterEventListener clusterListener = new InnerClusterListener();
57 private final DeviceListener deviceListener = new InnerDeviceListener();
tom4e969042014-10-07 00:47:30 -070058 private final IntentListener intentListener = new InnerIntentListener();
tom0755a362014-09-24 11:54:43 -070059
60 @Activate
61 public void activate() {
62 clusterService.addListener(clusterListener);
tom0768a022014-09-24 16:16:16 -070063 deviceService.addListener(deviceListener);
tom4e969042014-10-07 00:47:30 -070064 intentService.addListener(intentListener);
tom0755a362014-09-24 11:54:43 -070065 log.info("Started");
66 }
67
68 @Deactivate
69 public void deactivate() {
70 clusterService.removeListener(clusterListener);
tom0768a022014-09-24 16:16:16 -070071 deviceService.removeListener(deviceListener);
tom4e969042014-10-07 00:47:30 -070072 intentService.removeListener(intentListener);
tom0755a362014-09-24 11:54:43 -070073 log.info("Stopped");
74 }
75
76 private class InnerClusterListener implements ClusterEventListener {
77 @Override
78 public void event(ClusterEvent event) {
79 log.info("WOOOOT! {}", event);
80 }
81 }
tom0768a022014-09-24 16:16:16 -070082
83 private class InnerDeviceListener implements DeviceListener {
84 @Override
85 public void event(DeviceEvent event) {
86 log.info("YEEEEHAAAAW! {}", event);
87 }
88 }
tom4e969042014-10-07 00:47:30 -070089
90 private class InnerIntentListener implements IntentListener {
91 @Override
92 public void event(IntentEvent event) {
93 String message;
94 if (event.type() == IntentEvent.Type.SUBMITTED) {
95 message = "WOW! It looks like someone has some intentions: {}";
96 } else if (event.type() == IntentEvent.Type.INSTALLED) {
97 message = "AWESOME! So far things are going great: {}";
98 } else if (event.type() == IntentEvent.Type.WITHDRAWN) {
99 message = "HMMM! Ambitions are fading apparently: {}";
100 } else {
101 message = "CRAP!!! Things are not turning out as intended: {}";
102 }
103 log.info(message, event.subject());
104 }
105 }
tom0755a362014-09-24 11:54:43 -0700106}
107
108