Package org.osgi.jmx.framework

Examples of org.osgi.jmx.framework.ServiceStateMBean


    }   
   
    @Test
    public void testMBeanInterface() throws Exception {
       
        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
        assertNotNull(mbean);
       
        //get bundles
       
        Bundle a = context().getBundleByName("org.apache.aries.jmx.test.bundlea");
        assertNotNull(a);
       
        Bundle b = context().getBundleByName("org.apache.aries.jmx.test.bundleb");
        assertNotNull(b);
       
        // get services
       
        ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
        assertNotNull(refA);
        long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceAId > -1);
       
        ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
        assertNotNull(refB);
        long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceBId > -1);
       
        ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
        assertNotNull(refs);
        assertEquals(1, refs.length);
        ServiceReference msf = refs[0];

       
        // getBundleIdentifier
       
        assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
       
        //getObjectClass
       
        String[] objectClass = mbean.getObjectClass(serviceAId);
        assertEquals(2, objectClass.length);
        List<String> classNames = Arrays.asList(objectClass);
        assertTrue(classNames.contains(InterfaceA.class.getName()));
        assertTrue(classNames.contains(ManagedService.class.getName()));
       
        // getProperties
       
        TabularData serviceProperties = mbean.getProperties(serviceBId);
        assertNotNull(serviceProperties);
        assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
        assertTrue(serviceProperties.values().size() > 1);
        assertEquals("org.apache.aries.jmx.test.ServiceB",
                PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
       
        // getUsingBundles
       
        long[] usingBundles = mbean.getUsingBundles(serviceBId);
        assertEquals(1, usingBundles.length);
        assertEquals(a.getBundleId(), usingBundles[0]);
       
        // listServices
       
        TabularData allServices = mbean.listServices();
        assertNotNull(allServices);
        assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
       
        // notifications
       
View Full Code Here


    }   
   
    @Test
    public void testMBeanInterface() throws Exception {
       
        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
        assertNotNull(mbean);
       
        //get bundles
       
        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
        assertNotNull(a);
       
        Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
        assertNotNull(b);
       
        // get services
       
        ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
        assertNotNull(refA);
        long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceAId > -1);
       
        ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
        assertNotNull(refB);
        long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceBId > -1);
       
        ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
        assertNotNull(refs);
        assertEquals(1, refs.length);
        ServiceReference msf = refs[0];

       
        // getBundleIdentifier
       
        assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
       
        //getObjectClass
       
        String[] objectClass = mbean.getObjectClass(serviceAId);
        assertEquals(2, objectClass.length);
        List<String> classNames = Arrays.asList(objectClass);
        assertTrue(classNames.contains(InterfaceA.class.getName()));
        assertTrue(classNames.contains(ManagedService.class.getName()));
       
        // getProperties
       
        TabularData serviceProperties = mbean.getProperties(serviceBId);
        assertNotNull(serviceProperties);
        assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
        assertTrue(serviceProperties.values().size() > 1);
        assertEquals("org.apache.aries.jmx.test.ServiceB",
                PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
       
        // getUsingBundles
       
        long[] usingBundles = mbean.getUsingBundles(serviceBId);
        assertEquals(1, usingBundles.length);
        assertEquals(a.getBundleId(), usingBundles[0]);
       
        // listServices
       
        TabularData allServices = mbean.listServices();
        assertNotNull(allServices);
        assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
       
        // notifications
       
View Full Code Here

    }   
   
    @Test
    public void testMBeanInterface() throws Exception {
       
        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
        assertNotNull(mbean);
       
        //get bundles
       
        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
        assertNotNull(a);
       
        Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
        assertNotNull(b);
       
        // get services
       
        ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
        assertNotNull(refA);
        long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceAId > -1);
       
        ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
        assertNotNull(refB);
        long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceBId > -1);
       
        ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
        assertNotNull(refs);
        assertEquals(1, refs.length);
        ServiceReference msf = refs[0];

       
        // getBundleIdentifier
       
        assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
       
        //getObjectClass
       
        String[] objectClass = mbean.getObjectClass(serviceAId);
        assertEquals(2, objectClass.length);
        List<String> classNames = Arrays.asList(objectClass);
        assertTrue(classNames.contains(InterfaceA.class.getName()));
        assertTrue(classNames.contains(ManagedService.class.getName()));
       
        // getProperties
       
        TabularData serviceProperties = mbean.getProperties(serviceBId);
        assertNotNull(serviceProperties);
        assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
        assertTrue(serviceProperties.values().size() > 1);
        assertEquals("org.apache.aries.jmx.test.ServiceB",
                PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
       
        // getUsingBundles
       
        long[] usingBundles = mbean.getUsingBundles(serviceBId);
        assertEquals(1, usingBundles.length);
        assertEquals(a.getBundleId(), usingBundles[0]);
       
        // listServices
       
        TabularData allServices = mbean.listServices();
        assertNotNull(allServices);
        assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
       
        // notifications
       
View Full Code Here

   
   
    @Test
    public void testMBeanInterface() throws Exception {
       
        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
        assertNotNull(mbean);
       
        //get bundles
       
        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
        assertNotNull(a);
       
        Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
        assertNotNull(b);
       
        // get services
       
        ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
        assertNotNull(refA);
        long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceAId > -1);
       
        ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
        assertNotNull(refB);
        long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceBId > -1);
       
        ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
        assertNotNull(refs);
        assertEquals(1, refs.length);
        ServiceReference msf = refs[0];

       
        // getBundleIdentifier
       
        assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
       
        //getObjectClass
       
        String[] objectClass = mbean.getObjectClass(serviceAId);
        assertEquals(2, objectClass.length);
        List<String> classNames = Arrays.asList(objectClass);
        assertTrue(classNames.contains(InterfaceA.class.getName()));
        assertTrue(classNames.contains(ManagedService.class.getName()));
       
        // getProperties
       
        TabularData serviceProperties = mbean.getProperties(serviceBId);
        assertNotNull(serviceProperties);
        assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
        assertTrue(serviceProperties.values().size() > 1);
        assertEquals("org.apache.aries.jmx.test.ServiceB",
                PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
       
        // getUsingBundles
       
        long[] usingBundles = mbean.getUsingBundles(serviceBId);
        assertEquals(1, usingBundles.length);
        assertEquals(a.getBundleId(), usingBundles[0]);
       
        // listServices
       
        TabularData allServices = mbean.listServices();
        assertNotNull(allServices);
        assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
       
        // notifications
       
View Full Code Here

            KarafJMXPlugin.getLogger().warning(ex);
          return null;
        }
        final Set<ObjectName> queryNames = connection.queryNames(serviceStateQueryObjectName, null);
        for (ObjectName ServiceStateObjectName : queryNames) {
          ServiceStateMBean serviceStateMBean = MBeanServerInvocationHandler.newProxyInstance(connection, ServiceStateObjectName, ServiceStateMBean.class, true);
          return callback.doWithServiceStateMBean(serviceStateMBean);
        }
        return null;
      }
    });
View Full Code Here

   
   
    @Test
    public void testMBeanInterface() throws Exception {
       
        ServiceStateMBean mbean = getMBean(ServiceStateMBean.OBJECTNAME, ServiceStateMBean.class);
        assertNotNull(mbean);
       
        //get bundles
       
        Bundle a = getBundle("org.apache.aries.jmx.test.bundlea");
        assertNotNull(a);
       
        Bundle b = getBundle("org.apache.aries.jmx.test.bundleb");
        assertNotNull(b);
       
        // get services
       
        ServiceReference refA = bundleContext.getServiceReference(InterfaceA.class.getName());
        assertNotNull(refA);
        long serviceAId = (Long) refA.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceAId > -1);
       
        ServiceReference refB = bundleContext.getServiceReference(InterfaceB.class.getName());
        assertNotNull(refB);
        long serviceBId = (Long) refB.getProperty(Constants.SERVICE_ID);
        assertTrue(serviceBId > -1);
       
        ServiceReference[] refs = bundleContext.getServiceReferences(ManagedServiceFactory.class.getName(), "(" + Constants.SERVICE_PID + "=jmx.test.B.factory)");
        assertNotNull(refs);
        assertEquals(1, refs.length);
        ServiceReference msf = refs[0];

       
        // getBundleIdentifier
       
        assertEquals(a.getBundleId(), mbean.getBundleIdentifier(serviceAId));
       
        //getObjectClass
       
        String[] objectClass = mbean.getObjectClass(serviceAId);
        assertEquals(2, objectClass.length);
        List<String> classNames = Arrays.asList(objectClass);
        assertTrue(classNames.contains(InterfaceA.class.getName()));
        assertTrue(classNames.contains(ManagedService.class.getName()));
       
        // getProperties
       
        TabularData serviceProperties = mbean.getProperties(serviceBId);
        assertNotNull(serviceProperties);
        assertEquals(JmxConstants.PROPERTIES_TYPE, serviceProperties.getTabularType());
        assertTrue(serviceProperties.values().size() > 1);
        assertEquals("org.apache.aries.jmx.test.ServiceB",
                PropertyData.from(serviceProperties.get(new Object[] { Constants.SERVICE_PID })).getValue());
       
        // getUsingBundles
       
        long[] usingBundles = mbean.getUsingBundles(serviceBId);
        assertEquals(1, usingBundles.length);
        assertEquals(a.getBundleId(), usingBundles[0]);
       
        // listServices
       
        TabularData allServices = mbean.listServices();
        assertNotNull(allServices);
        assertEquals(bundleContext.getAllServiceReferences(null, null).length, allServices.values().size());
       
        // notifications
       
View Full Code Here

        }
        return packageState;
    }

    public ServiceStateMBean getServiceStateMBean() throws IOException {
        ServiceStateMBean serviceState = null;
        ObjectName objectName = createObjectName(ServiceStateMBean.OBJECTNAME);
        if (isRegisteredWithTimeout(objectName)) {
            serviceState = getMBeanProxy(objectName, ServiceStateMBean.class);
            return serviceState;
        }
View Full Code Here

TOP

Related Classes of org.osgi.jmx.framework.ServiceStateMBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.