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.io.BufferedReader;
\r
11 import java.io.IOException;
\r
12 import java.io.InputStreamReader;
\r
14 import org.opendaylight.controller.sal.core.impl.BrokerImpl;
\r
15 import org.opendaylight.controller.sal.core.impl.notify.NotificationModule;
\r
18 public class SALDemo {
\r
20 static BrokerImpl broker;
\r
21 static DemoProviderImpl provider;
\r
22 static DemoConsumerImpl consumer1;
\r
23 static DemoConsumerImpl consumer2;
\r
25 public static void main(String[] args) {
\r
28 initializeProvider();
\r
31 BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
\r
36 System.out.print("\nEnter your choice (0 - list): ");
\r
38 int choice = Integer.parseInt(s.trim());
\r
48 registerConsumer1();
\r
51 registerConsumer2();
\r
60 unregisterConsumer1();
\r
63 unregisterConsumer2();
\r
66 unregisterProvider();
\r
71 System.out.println("Please enter valid input.");
\r
74 } catch (Exception e) {
\r
76 .println("Operation failed. Reason exception raised: "
\r
77 + e.getClass().getSimpleName());
\r
78 System.out.println(" Message: " + e.getMessage());
\r
82 } catch (IOException e) {
\r
84 e.printStackTrace();
\r
88 private static void registerConsumer1() {
\r
89 broker.registerConsumer(consumer1);
\r
92 private static void registerConsumer2() {
\r
93 broker.registerConsumer(consumer2);
\r
96 private static void sendAlert(BufferedReader in) throws IOException {
\r
97 System.out.print("Please enter notification content:");
\r
98 String content = in.readLine();
\r
99 provider.sendAlertNotification(content);
\r
102 private static void sendChange(BufferedReader in) throws IOException {
\r
103 System.out.print("Please enter notification content:");
\r
104 String content = in.readLine();
\r
105 provider.sendChangeNotification(content);
\r
108 private static void unregisterConsumer1() {
\r
109 consumer1.closeSession();
\r
112 private static void unregisterConsumer2() {
\r
113 consumer2.closeSession();
\r
116 private static void unregisterProvider() {
\r
117 provider.closeSession();
\r
120 private static void displayHelp() {
\r
121 System.out.println("Usage: ");
\r
122 System.out.println(" 0) Display Help");
\r
123 System.out.println(" 1) Register Provider");
\r
124 System.out.println(" 2) Register Consumer 1 (listening on alert)");
\r
126 .println(" 3) Register Consumer 2 (listening on alert,change)");
\r
127 System.out.println(" 4) Send Alert Notification");
\r
128 System.out.println(" 5) Send Change Notification");
\r
129 System.out.println(" 6) Unregister Consumer 1");
\r
130 System.out.println(" 7) Unregister Consumer 2");
\r
131 System.out.println(" 8) Unregister Provider");
\r
132 System.out.println(" 9) Exit");
\r
136 private static void initializeProvider() {
\r
137 provider = new DemoProviderImpl();
\r
140 private static void initialize() {
\r
141 System.out.println("Initializing broker");
\r
142 broker = new BrokerImpl();
\r
143 NotificationModule notifyModule = new NotificationModule();
\r
144 broker.addModule(notifyModule);
\r
146 consumer1 = new DemoConsumerImpl("Consumer 1");
\r
147 consumer2 = new DemoConsumerImpl("Consumer 2");
\r
148 consumer2.setChangeAware(true);
\r
151 private static void registerProvider() {
\r
152 broker.registerProvider(provider);
\r