8a393be43db3d6394701f137a73c50c65b675f9c
[controller.git] / opendaylight / md-sal / sal-dom-demo / src / main / java / org / opendaylight / controller / sal / demo / DemoProviderImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.sal.demo;
9
10 import java.util.ArrayList;
11 import java.util.Collection;
12 import java.util.Collections;
13 import java.util.List;
14
15 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
16 import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService;
17 import org.opendaylight.controller.yang.data.api.Node;
18 import org.opendaylight.controller.yang.data.util.Nodes;
19
20
21 public class DemoProviderImpl implements
22         org.opendaylight.controller.sal.core.api.Provider {
23
24     private ProviderSession session;
25     private NotificationProviderService notifier;
26
27     @Override
28     public void onSessionInitiated(ProviderSession session) {
29         this.session = session;
30         notifier = session.getService(NotificationProviderService.class);
31     }
32
33     @Override
34     public Collection<ProviderFunctionality> getProviderFunctionality() {
35         return Collections.emptySet();
36     }
37
38     public void sendAlertNotification(String content) {
39         List<Node<?>> nodes = new ArrayList<Node<?>>();
40         nodes.add(DemoUtils.contentNode(content));
41
42         if (notifier == null) {
43             System.out.println("Provider: Error: Session not available");
44             System.out
45                     .println("                 Notification Service not available");
46             return;
47         }
48         notifier.sendNotification(Nodes.containerNode(
49                 DemoUtils.alertNotification, nodes));
50     }
51
52     public void sendChangeNotification(String content) {
53         List<Node<?>> nodes = new ArrayList<Node<?>>();
54         nodes.add(DemoUtils.contentNode(content));
55
56         if (notifier == null) {
57             System.out.println("Provider: Error: Session not available");
58             System.out
59                     .println("                 Notification Service not available");
60             return;
61         }
62         notifier.sendNotification(Nodes.containerNode(
63                 DemoUtils.changeNotification, nodes));
64     }
65
66     public void closeSession() {
67         session.close();
68     }
69 }