2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.sal.demo;
\r
10 import java.util.Collection;
\r
11 import java.util.HashSet;
\r
12 import java.util.Set;
\r
14 import org.opendaylight.controller.sal.core.api.Consumer;
\r
15 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
\r
16 import org.opendaylight.controller.sal.core.api.notify.NotificationListener;
\r
17 import org.opendaylight.controller.sal.core.api.notify.NotificationService;
\r
18 import org.opendaylight.controller.yang.common.QName;
\r
19 import org.opendaylight.controller.yang.data.api.CompositeNode;
\r
20 import org.slf4j.Logger;
\r
21 import org.slf4j.LoggerFactory;
\r
24 public class DemoConsumerImpl implements Consumer {
\r
26 private ConsumerSession session;
\r
27 private NotificationService notificationService;
\r
28 private final String name;
\r
29 private static Logger log = LoggerFactory.getLogger("AlertLogger");
\r
31 private boolean changeAware;
\r
33 public DemoConsumerImpl(String name) {
\r
37 private NotificationListener alertLogger = new NotificationListener() {
\r
40 public void onNotification(CompositeNode notification) {
\r
41 System.out.println(name
\r
42 + ": Received alert: "
\r
43 + notification.getFirstSimpleByName(
\r
44 DemoUtils.contentNodeName).getValue());
\r
45 log.info("AlertLogger: Received notification: " + notification);
\r
49 public Set<QName> getSupportedNotifications() {
\r
50 Set<QName> supported = new HashSet<QName>();
\r
51 supported.add(DemoUtils.alertNotification);
\r
56 private NotificationListener changeLogger = new NotificationListener() {
\r
59 public void onNotification(CompositeNode notification) {
\r
60 System.out.println(name
\r
61 + ": Received change: "
\r
62 + notification.getFirstSimpleByName(
\r
63 DemoUtils.contentNodeName).getValue());
\r
64 log.info("ChangeLogger: Received notification: " + notification);
\r
68 public Set<QName> getSupportedNotifications() {
\r
69 Set<QName> supported = new HashSet<QName>();
\r
70 supported.add(DemoUtils.alertNotification);
\r
76 public void onSessionInitiated(ConsumerSession session) {
\r
77 this.session = session;
\r
78 this.notificationService = session
\r
79 .getService(NotificationService.class);
\r
80 notificationService.addNotificationListener(
\r
81 DemoUtils.alertNotification, alertLogger);
\r
82 if (isChangeAware()) {
\r
83 notificationService.addNotificationListener(
\r
84 DemoUtils.changeNotification, changeLogger);
\r
89 public Collection<ConsumerFunctionality> getConsumerFunctionality() {
\r
90 Set<ConsumerFunctionality> func = new HashSet<ConsumerFunctionality>();
\r
91 func.add(alertLogger);
\r
95 public void closeSession() {
\r
99 public boolean isChangeAware() {
\r
100 return changeAware;
\r
103 public void setChangeAware(boolean changeAware) {
\r
104 this.changeAware = changeAware;
\r