Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / yang-prototype / sal / sal-core-demo / src / main / java / org / opendaylight / controller / sal / demo / DemoProviderImpl.java
1 /*\r
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
3  *\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
7  */\r
8 package org.opendaylight.controller.sal.demo;\r
9 \r
10 import java.util.ArrayList;\r
11 import java.util.Collection;\r
12 import java.util.Collections;\r
13 import java.util.List;\r
14 \r
15 import org.opendaylight.controller.data.util.Nodes;\r
16 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;\r
17 import org.opendaylight.controller.sal.core.api.notify.NotificationProviderService;\r
18 import org.opendaylight.controller.yang.data.api.Node;\r
19 \r
20 \r
21 public class DemoProviderImpl implements\r
22         org.opendaylight.controller.sal.core.api.Provider {\r
23 \r
24     private ProviderSession session;\r
25     private NotificationProviderService notifier;\r
26 \r
27     @Override\r
28     public void onSessionInitiated(ProviderSession session) {\r
29         this.session = session;\r
30         notifier = session.getService(NotificationProviderService.class);\r
31     }\r
32 \r
33     @Override\r
34     public Collection<ProviderFunctionality> getProviderFunctionality() {\r
35         return Collections.emptySet();\r
36     }\r
37 \r
38     public void sendAlertNotification(String content) {\r
39         List<Node<?>> nodes = new ArrayList<Node<?>>();\r
40         nodes.add(DemoUtils.contentNode(content));\r
41 \r
42         if (notifier == null) {\r
43             System.out.println("Provider: Error: Session not available");\r
44             System.out\r
45                     .println("                 Notification Service not available");\r
46             return;\r
47         }\r
48         notifier.sendNotification(Nodes.containerNode(\r
49                 DemoUtils.alertNotification, nodes));\r
50     }\r
51 \r
52     public void sendChangeNotification(String content) {\r
53         List<Node<?>> nodes = new ArrayList<Node<?>>();\r
54         nodes.add(DemoUtils.contentNode(content));\r
55 \r
56         if (notifier == null) {\r
57             System.out.println("Provider: Error: Session not available");\r
58             System.out\r
59                     .println("                 Notification Service not available");\r
60             return;\r
61         }\r
62         notifier.sendNotification(Nodes.containerNode(\r
63                 DemoUtils.changeNotification, nodes));\r
64     }\r
65 \r
66     public void closeSession() {\r
67         session.close();\r
68     }\r
69 }\r