2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.vpnservice.fcapsmanager.countermanager;
10 import java.lang.management.ManagementFactory;
11 import org.osgi.framework.BundleContext;
12 import org.osgi.framework.ServiceReference;
13 import org.slf4j.LoggerFactory;
14 import java.util.HashMap;
16 import java.util.concurrent.Executors;
17 import java.util.concurrent.ScheduledExecutorService;
18 import java.util.concurrent.TimeUnit;
19 import javax.management.MBeanServer;
20 import javax.management.ObjectName;
21 import org.opendaylight.vpnservice.fcapsmanager.PMServiceFacade;
24 private final static org.slf4j.Logger LOG = LoggerFactory.getLogger(Poller.class);
25 private static BundleContext context = null;
28 public Poller(BundleContext bundleContext) {
29 context = bundleContext;
31 //This method do the Polling every 5 second and retrieves the the counter details
33 public void polling() {
34 LOG.debug("Poller Polling Mbean List and the content is " + PMRegistrationListener.beanNames);
35 ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
36 service.scheduleAtFixedRate(new Pollerthread(), 0, 5, TimeUnit.SECONDS);
40 * Platform dependent bundle injects its handle and it is retrieved in the method
42 protected PMServiceFacade getPMServiceSPI (){
43 PMServiceFacade service =null;
46 ServiceReference<?> serviceReference = context.
47 getServiceReference(PMServiceFacade.class.getName());
48 service = (PMServiceFacade) context.
49 getService(serviceReference);
50 }catch(NullPointerException ex){
53 LOG.error("Exception {} occurred in getting PMServiceSPI",e);
60 class Pollerthread implements Runnable {
61 private final static org.slf4j.Logger LOG = LoggerFactory.getLogger(Pollerthread.class);
62 MBeanServer mbs = null;
63 Map<String,String> getCounter = new HashMap<String,String>();
64 Poller poller = new Poller();
67 * Retrieve countermap from each counter mbean and send to platform
69 @SuppressWarnings("unchecked")
73 mbs = ManagementFactory.getPlatformMBeanServer();
74 for (ObjectName objectName : PMRegistrationListener.beanNames) {
75 getCounter=(Map<String, String>) mbs.invoke(objectName, "retrieveCounterMap",null,null);
76 if(poller.getPMServiceSPI() != null)
77 poller.getPMServiceSPI().connectToPMFactory(getCounter);
79 LOG.debug("PM service not available");
81 } catch (Exception e) {
82 LOG.error("Exception caught {} ", e);