本文整理汇总了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));
}
示例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));
}
示例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());
}
}
示例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));
}
}