当前位置: 首页>>代码示例>>Java>>正文


Java ModuleContext.addModuleListener方法代码示例

本文整理汇总了Java中org.jboss.gravia.runtime.ModuleContext.addModuleListener方法的典型用法代码示例。如果您正苦于以下问题:Java ModuleContext.addModuleListener方法的具体用法?Java ModuleContext.addModuleListener怎么用?Java ModuleContext.addModuleListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.gravia.runtime.ModuleContext的用法示例。


在下文中一共展示了ModuleContext.addModuleListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testUpdateBundle

import org.jboss.gravia.runtime.ModuleContext; //导入方法依赖的package包/类
@Test
public void testUpdateBundle() throws Exception {
    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    ModuleContext rtcontext = runtime.getModuleContext();

    final List<String> events = new ArrayList<String>();
    ModuleListener listener = new SynchronousModuleListener() {
        @Override
        public void moduleChanged(ModuleEvent event) {
            Module module = event.getModule();
            String modid = module.getIdentity().toString();
            String evtid = ConstantsHelper.moduleEvent(event.getType());
            String message = modid + ":" + evtid;
            events.add(message);
        }
    };
    rtcontext.addModuleListener(listener);

    InputStream input = deployer.getDeployment(BUNDLE_REV0);
    Bundle bundle = bundleContext.installBundle(BUNDLE_REV0, input);
    try {
        Assert.assertTrue(events.isEmpty());

        bundle.start();
        OSGiTestHelper.assertLoadClass(bundle, "org.jboss.test.gravia.runtime.osgi.sub.b1.B1");
        OSGiTestHelper.assertLoadClassFail(bundle, "org.jboss.test.gravia.runtime.osgi.sub.b2.B2");

        Assert.assertEquals(3, events.size());
        Assert.assertEquals("update-test:1.0.0:INSTALLED", events.remove(0));
        Assert.assertEquals("update-test:1.0.0:STARTING", events.remove(0));
        Assert.assertEquals("update-test:1.0.0:STARTED", events.remove(0));

        InputStream is = deployer.getDeployment(BUNDLE_REV1);
        bundle.update(is);
        OSGiTestHelper.assertLoadClass(bundle, "org.jboss.test.gravia.runtime.osgi.sub.b2.B2");
        OSGiTestHelper.assertLoadClassFail(bundle, "org.jboss.test.gravia.runtime.osgi.sub.b1.B1");

        Assert.assertEquals(6, events.size());
        Assert.assertEquals("update-test:1.0.0:STOPPING", events.remove(0));
        Assert.assertEquals("update-test:1.0.0:STOPPED", events.remove(0));
        Assert.assertEquals("update-test:1.0.0:UNINSTALLED", events.remove(0));
        Assert.assertEquals("update-test:2.0.0:INSTALLED", events.remove(0));
        Assert.assertEquals("update-test:2.0.0:STARTING", events.remove(0));
        Assert.assertEquals("update-test:2.0.0:STARTED", events.remove(0));
    } finally {
        bundle.uninstall();
    }

    Assert.assertEquals(3, events.size());
    Assert.assertEquals("update-test:2.0.0:STOPPING", events.remove(0));
    Assert.assertEquals("update-test:2.0.0:STOPPED", events.remove(0));
    Assert.assertEquals("update-test:2.0.0:UNINSTALLED", events.remove(0));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:54,代码来源:BundleUpdateTest.java

示例2: testModuleLifecycle

import org.jboss.gravia.runtime.ModuleContext; //导入方法依赖的package包/类
@Test
public void testModuleLifecycle() throws Exception {
    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    ModuleContext rtcontext = runtime.getModuleContext();

    ServiceReference<String> sref = rtcontext.getServiceReference(String.class);
    Assert.assertNull("ServiceReference null", sref);

    final List<String> events = new ArrayList<String>();
    ModuleListener listener = new SynchronousModuleListener() {
        @Override
        public void moduleChanged(ModuleEvent event) {
            Module module = event.getModule();
            String modid = module.getIdentity().toString();
            String evtid = ConstantsHelper.moduleEvent(event.getType());
            events.add(modid + ":" + evtid);
        }
    };
    rtcontext.addModuleListener(listener);

    // Install the Bundle
    InputStream input = deployer.getDeployment(BUNDLE_B);
    Bundle bundleB = bundleContext.installBundle(BUNDLE_B, input);
    Assert.assertTrue("No module events", events.isEmpty());
    Module moduleB = runtime.getModule(bundleB.getBundleId());
    Assert.assertNull("Module null", moduleB);

    // Resolve the Bundle
    URL resURL = bundleB.getResource(JarFile.MANIFEST_NAME);
    Assert.assertNotNull("Manifest not null", resURL);
    Assert.assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundleB.getState());

    // Verify that the Module is available
    moduleB = runtime.getModule(bundleB.getBundleId());
    Assert.assertNotNull("Module not null", moduleB);
    Assert.assertEquals(Module.State.INSTALLED, moduleB.getState());
    ModuleContext contextB = moduleB.getModuleContext();
    Assert.assertNull("ModuleContext null", contextB);

    // Verify Module events
    Assert.assertEquals("Module events", 1, events.size());
    Assert.assertEquals("bundleB:1.0.0:INSTALLED", events.get(0));

    // Start the Bundle
    bundleB.start();
    Assert.assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundleB.getState());
    Assert.assertEquals(Module.State.ACTIVE, moduleB.getState());
    contextB = moduleB.getModuleContext();
    Assert.assertNotNull("ModuleContext not null", contextB);
    sref = contextB.getServiceReference(String.class);
    Assert.assertNotNull("ServiceReference not null", sref);
    Assert.assertEquals("bundleB:1.0.0", contextB.getService(sref));

    // Verify Module events
    Assert.assertEquals("Module events", 3, events.size());
    Assert.assertEquals("bundleB:1.0.0:STARTING", events.get(1));
    Assert.assertEquals("bundleB:1.0.0:STARTED", events.get(2));

    // Stop the Bundle
    bundleB.stop();
    Assert.assertEquals("Bundle RESOLVED", Bundle.RESOLVED, bundleB.getState());
    Assert.assertEquals(Module.State.INSTALLED, moduleB.getState());
    contextB = moduleB.getModuleContext();
    Assert.assertNull("ModuleContext null", contextB);
    sref = rtcontext.getServiceReference(String.class);
    Assert.assertNull("ServiceReference null", sref);

    // Verify Module events
    Assert.assertEquals("Module events", 5, events.size());
    Assert.assertEquals("bundleB:1.0.0:STOPPING", events.get(3));
    Assert.assertEquals("bundleB:1.0.0:STOPPED", events.get(4));

    // Uninstall the Bundle
    bundleB.uninstall();
    Assert.assertEquals("Bundle UNINSTALLED", Bundle.UNINSTALLED, bundleB.getState());
    Assert.assertEquals(Module.State.UNINSTALLED, moduleB.getState());

    // Verify Module events
    Assert.assertEquals("Module events", 6, events.size());
    Assert.assertEquals("bundleB:1.0.0:UNINSTALLED", events.get(5));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:82,代码来源:BundleIntegrationTest.java

示例3: testAttachedFragment

import org.jboss.gravia.runtime.ModuleContext; //导入方法依赖的package包/类
@Test
public void testAttachedFragment() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    ModuleContext rtcontext = runtime.getModuleContext();

    final List<String> events = new ArrayList<String>();
    ModuleListener listener = new SynchronousModuleListener() {
        @Override
        public void moduleChanged(ModuleEvent event) {
            Module module = event.getModule();
            String modid = module.getIdentity().toString();
            String evtid = ConstantsHelper.moduleEvent(event.getType());
            String message = modid + ":" + evtid;
            events.add(message);
        }
    };
    rtcontext.addModuleListener(listener);

    // Deploy the fragment
    InputStream input = deployer.getDeployment(GOOD_FRAGMENT);
    Bundle fragment = bundleContext.installBundle(GOOD_FRAGMENT, input);
    try {
        Assert.assertTrue(events.isEmpty());
        
        // Deploy the bundle
        input = deployer.getDeployment(GOOD_BUNDLE);
        Bundle host = bundleContext.installBundle("bundle-host-attached", input);
        try {
            Class<?> clazz = OSGiTestHelper.assertLoadClass(host, "org.jboss.test.gravia.runtime.osgi.sub.a.AttachedType");
            Assert.assertSame(host, ((BundleReference) clazz.getClassLoader()).getBundle());
            Assert.assertEquals(1, events.size());
            Assert.assertEquals("good-bundle:0.0.0:INSTALLED", events.remove(0));
        } finally {
            host.uninstall();
            Assert.assertEquals(1, events.size());
            Assert.assertEquals("good-bundle:0.0.0:UNINSTALLED", events.remove(0));
        }
    } finally {
        fragment.uninstall();
        Assert.assertTrue(events.isEmpty());
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:44,代码来源:FragmentTest.java

示例4: testUnattachedFragment

import org.jboss.gravia.runtime.ModuleContext; //导入方法依赖的package包/类
@Test
public void testUnattachedFragment() throws Exception {

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    ModuleContext rtcontext = runtime.getModuleContext();

    final List<String> events = new ArrayList<String>();
    ModuleListener listener = new SynchronousModuleListener() {
        @Override
        public void moduleChanged(ModuleEvent event) {
            Module module = event.getModule();
            String modid = module.getIdentity().toString();
            String evtid = ConstantsHelper.moduleEvent(event.getType());
            String message = modid + ":" + evtid;
            events.add(message);
        }
    };
    rtcontext.addModuleListener(listener);

    // Deploy the bundle
    InputStream input = deployer.getDeployment(GOOD_BUNDLE);
    Bundle host = bundleContext.installBundle("bundle-host", input);
    try {
        Assert.assertTrue(events.isEmpty());
        OSGiTestHelper.assertLoadClassFail(host, "org.jboss.test.gravia.runtime.osgi.sub.a.AttachedType");
        Assert.assertEquals(1, events.size());
        Assert.assertEquals("good-bundle:0.0.0:INSTALLED", events.remove(0));
        
        // Deploy the fragment
        input = deployer.getDeployment(GOOD_FRAGMENT);
        Bundle fragment = bundleContext.installBundle(GOOD_FRAGMENT, input);
        try {
            OSGiTestHelper.assertLoadClassFail(host, "org.jboss.test.gravia.runtime.osgi.sub.a.AttachedType");
            Assert.assertTrue(events.isEmpty());
        } finally {
            fragment.uninstall();
            Assert.assertTrue(events.isEmpty());
        }
    } finally {
        host.uninstall();
        Assert.assertEquals(1, events.size());
        Assert.assertEquals("good-bundle:0.0.0:UNINSTALLED", events.remove(0));
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:45,代码来源:FragmentTest.java


注:本文中的org.jboss.gravia.runtime.ModuleContext.addModuleListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。