Search in sources :

Example 1 with BundleStateMBean

use of org.osgi.jmx.framework.BundleStateMBean in project aries by apache.

the class BundleStateMBeanHandler method open.

/**
     * @see org.apache.aries.jmx.MBeanHandler#open()
     */
public void open() {
    packageAdminRef = bundleContext.getServiceReference(PackageAdmin.class.getName());
    PackageAdmin packageAdmin = (PackageAdmin) bundleContext.getService(packageAdminRef);
    startLevelRef = bundleContext.getServiceReference(StartLevel.class.getName());
    StartLevel startLevel = (StartLevel) bundleContext.getService(startLevelRef);
    bundleStateMBean = new BundleState(bundleContext, packageAdmin, startLevel, stateConfig, logger);
    try {
        mbean = new RegistrableStandardEmitterMBean(bundleStateMBean, BundleStateMBean.class);
    } catch (NotCompliantMBeanException e) {
        logger.log(LogService.LOG_ERROR, "Failed to instantiate MBean for " + BundleStateMBean.class.getName(), e);
    }
    agentContext.registerMBean(this);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) RegistrableStandardEmitterMBean(org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean) StartLevel(org.osgi.service.startlevel.StartLevel) BundleStateMBean(org.osgi.jmx.framework.BundleStateMBean)

Example 2 with BundleStateMBean

use of org.osgi.jmx.framework.BundleStateMBean in project aries by apache.

the class BundleStateMBeanTest method testBundleIDsAttribute.

@Test
public void testBundleIDsAttribute() throws Exception {
    Set<Long> expectedIDs = new HashSet<Long>();
    for (Bundle b : context().getBundles()) {
        expectedIDs.add(b.getBundleId());
    }
    BundleStateMBean mbean = getMBean(OBJECTNAME, BundleStateMBean.class);
    long[] actual = mbean.getBundleIds();
    Set<Long> actualIDs = new HashSet<Long>();
    for (long id : actual) {
        actualIDs.add(id);
    }
    assertEquals(expectedIDs, actualIDs);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleStateMBean(org.osgi.jmx.framework.BundleStateMBean) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Aggregations

BundleStateMBean (org.osgi.jmx.framework.BundleStateMBean)2 HashSet (java.util.HashSet)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)1 RegistrableStandardEmitterMBean (org.apache.aries.jmx.util.shared.RegistrableStandardEmitterMBean)1 Test (org.junit.Test)1 Bundle (org.osgi.framework.Bundle)1 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)1 StartLevel (org.osgi.service.startlevel.StartLevel)1