Search in sources :

Example 1 with PackageStateMBean

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

the class PackageStateMBeanHandler method open.

/**
 * @see org.apache.aries.jmx.MBeanHandler#open()
 */
public void open() {
    ServiceReference adminRef = context.getServiceReference(PackageAdmin.class.getCanonicalName());
    PackageAdmin packageAdmin = (PackageAdmin) context.getService(adminRef);
    PackageStateMBean packageState = new PackageState(context, packageAdmin);
    try {
        mbean = new StandardMBean(packageState, PackageStateMBean.class);
    } catch (NotCompliantMBeanException e) {
        logger.log(LogService.LOG_ERROR, "Not compliant MBean", e);
    }
    agentContext.registerMBean(this);
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) StandardMBean(javax.management.StandardMBean) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) PackageStateMBean(org.osgi.jmx.framework.PackageStateMBean) ServiceReference(org.osgi.framework.ServiceReference)

Example 2 with PackageStateMBean

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

the class PackageStateMBeanTest method testMBeanInterface.

@Test
public void testMBeanInterface() throws IOException {
    PackageStateMBean packagaState = getMBean(PackageStateMBean.OBJECTNAME, PackageStateMBean.class);
    assertNotNull(packagaState);
    long[] exportingBundles = packagaState.getExportingBundles("org.osgi.jmx.framework", "1.7.0");
    assertNotNull(exportingBundles);
    assertTrue("Should find a bundle exporting org.osgi.jmx.framework", exportingBundles.length > 0);
    long[] exportingBundles2 = packagaState.getExportingBundles("test", "1.0.0");
    assertNull("Shouldn't find a bundle exporting test package", exportingBundles2);
    long[] importingBundlesId = packagaState.getImportingBundles("org.osgi.jmx.framework", "1.7.0", exportingBundles[0]);
    assertTrue("Should find bundles importing org.osgi.jmx.framework", importingBundlesId.length > 0);
    TabularData table = packagaState.listPackages();
    assertNotNull("TabularData containing CompositeData with packages info shouldn't be null", table);
    assertEquals("TabularData should be a type PACKAGES", PackageStateMBean.PACKAGES_TYPE, table.getTabularType());
    Collection<?> colData = table.values();
    assertNotNull("Collection of CompositeData shouldn't be null", colData);
    assertFalse("Collection of CompositeData should contain elements", colData.isEmpty());
    boolean isRemovalPending = packagaState.isRemovalPending("org.osgi.jmx.framework", "1.7.0", exportingBundles[0]);
    assertFalse("Should removal pending on org.osgi.jmx.framework be false", isRemovalPending);
}
Also used : PackageStateMBean(org.osgi.jmx.framework.PackageStateMBean) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.jmx.AbstractIntegrationTest)

Aggregations

PackageStateMBean (org.osgi.jmx.framework.PackageStateMBean)2 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 StandardMBean (javax.management.StandardMBean)1 TabularData (javax.management.openmbean.TabularData)1 AbstractIntegrationTest (org.apache.aries.jmx.AbstractIntegrationTest)1 Test (org.junit.Test)1 ServiceReference (org.osgi.framework.ServiceReference)1 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)1