Added dumpMsgCount osgi command
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / cmd / MessageCountCommandProvider.java
1 /**
2  * Copyright (c) 2014 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
9 package org.opendaylight.openflowplugin.openflow.md.core.cmd;
10
11 import org.eclipse.osgi.framework.console.CommandInterpreter;
12 import org.eclipse.osgi.framework.console.CommandProvider;
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.openflowplugin.openflow.md.queue.MessageCountDumper;
15 import org.osgi.framework.BundleContext;
16
17 /**
18  * 
19  */
20 public class MessageCountCommandProvider implements CommandProvider {
21     
22     private boolean sessionInitiated;
23     private BundleContext ctx;
24     private MessageCountDumper provider;
25     
26     /**
27      * @param ctx
28      * @param provider
29      */
30     public MessageCountCommandProvider(BundleContext ctx, MessageCountDumper provider) {
31         this.ctx = ctx;
32         this.provider = provider;
33     }
34
35     @Override
36     public String getHelp() {
37         String helpString = "----------------- dumpMsgCount--------------\n"
38                 + " dumps message counters \n";
39         return helpString;
40     }
41     
42     /**
43      * @param session
44      */
45     public void onSessionInitiated(ProviderContext session) {
46         ctx.registerService(CommandProvider.class.getName(), this, null);
47         this.sessionInitiated = true;
48     }
49     
50     /**
51      * @param ci
52      */
53     public void _dumpMsgCount(CommandInterpreter ci) {
54         if(sessionInitiated) {
55             ci.println("dumping msg counts");
56             for (String countItem : provider.dumpMessageCounts()) {
57                 ci.println(countItem);
58             }
59         } else {
60             ci.println("Session not initiated, try again in a few seconds");
61         }
62     }
63
64 }