本文整理汇总了Java中org.jboss.gravia.runtime.Runtime.getModuleContext方法的典型用法代码示例。如果您正苦于以下问题:Java Runtime.getModuleContext方法的具体用法?Java Runtime.getModuleContext怎么用?Java Runtime.getModuleContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.gravia.runtime.Runtime
的用法示例。
在下文中一共展示了Runtime.getModuleContext方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testURLHandlerService
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testURLHandlerService() throws Exception {
try {
new URL("foo://hi");
Assert.fail("No handler registered. Should throw a MalformedURLException.");
} catch (MalformedURLException mue) {
// expected
}
Runtime runtime = RuntimeLocator.getRequiredRuntime();
ModuleContext syscontext = runtime.getModuleContext();
Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.URL_HANDLER_PROTOCOL, "foo");
ServiceRegistration<URLStreamHandler> sreg = syscontext.registerService(URLStreamHandler.class, new MyHandler(), props);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyStream(new URL("foo://somehost").openStream(), baos);
Assert.assertEquals("somehost", new String(baos.toByteArray()));
URL url = new URL("foo:///somepath");
Assert.assertEquals("", url.getHost());
} finally {
sreg.unregister();
}
try {
new URL("foo://hi").openConnection();
Assert.fail("No handler registered any more.");
} catch (IOException ex) {
// expected
}
}
示例2: registerServices
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
private void registerServices(ServletContext servletContext, Runtime runtime) {
RuntimeEnvironment environment = new RuntimeEnvironment(runtime).initDefaultContent();
TomcatResourceInstaller installer = new TomcatResourceInstaller(environment);
ModuleContext syscontext = runtime.getModuleContext();
syscontext.registerService(RuntimeEnvironment.class, environment, null);
syscontext.registerService(ResourceInstaller.class, installer, null);
}
示例3: start
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
LOGGER.info("Activating Fabric Subsystem");
Runtime runtime = injectedRuntime.getValue();
ModuleContext syscontext = runtime.getModuleContext();
// Install and start this as a {@link Module}
ModuleClassLoader classLoader = (ModuleClassLoader) getClass().getClassLoader();
try {
Dictionary<String, String> headers = getManifestHeaders(classLoader, "wildfly-extension");
module = runtime.installModule(classLoader, headers);
// Attach the {@link ModuleEntriesProvider} so
ModuleEntriesProvider entriesProvider = new ClassLoaderEntriesProvider(module);
Attachable attachable = AbstractModule.assertAbstractModule(module);
attachable.putAttachment(AbstractModule.MODULE_ENTRIES_PROVIDER_KEY, entriesProvider);
// Start the module
module.start();
} catch (RuntimeException rte) {
throw rte;
} catch (Exception ex) {
throw new StartException(ex);
}
// Open service trackers for {@link Resolver}, {@link Repository}, {@link Provisioner}
trackers = new HashSet<ServiceTracker<?, ?>>();
trackers.add(resolverTracker(syscontext, startContext.getChildTarget()));
trackers.add(repositoryTracker(syscontext, startContext.getChildTarget()));
trackers.add(provisionerTracker(syscontext, startContext.getChildTarget()));
trackers.add(completeTracker(syscontext, startContext.getChildTarget()));
}
示例4: start
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
contextFactory = new CamelContextFactoryImpl();
// Register the service with gravia
Runtime runtime = injectedRuntime.getValue();
ModuleContext syscontext = runtime.getModuleContext();
registration = syscontext.registerService(CamelContextFactory.class, contextFactory, null);
}
示例5: start
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
ContextCreateHandlerRegistry handlerRegistry = injectedHandlerRegistry.getValue();
ServiceRegistry serviceRegistry = startContext.getController().getServiceContainer();
contextRegistry = new CamelContextRegistryImpl(handlerRegistry, serviceRegistry, startContext.getChildTarget());
// Register the service with gravia
Runtime runtime = injectedRuntime.getValue();
ModuleContext syscontext = runtime.getModuleContext();
registration = syscontext.registerService(CamelContextRegistry.class, contextRegistry, null);
for (final String name : subsystemState.getContextDefinitionNames()) {
createCamelContext(name, subsystemState.getContextDefinition(name));
}
}
示例6: start
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
ServiceContainer serviceContainer = startContext.getController().getServiceContainer();
createHandlerRegistry = new ContextCreateHandlerRegistryImpl(serviceContainer, startContext.getChildTarget());
Runtime runtime = injectedRuntime.getValue();
ModuleContext syscontext = runtime.getModuleContext();
registration = syscontext.registerService(ContextCreateHandlerRegistry.class, createHandlerRegistry, null);
}
示例7: testURLHandlerService
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Test
public void testURLHandlerService() throws Exception {
try {
new URL("foo://hi");
Assert.fail("No handler registered. Should throw a MalformedURLException.");
} catch (MalformedURLException mue) {
// expected
}
Runtime runtime = RuntimeLocator.getRequiredRuntime();
ModuleContext syscontext = runtime.getModuleContext();
Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.URL_HANDLER_PROTOCOL, "foo");
ServiceRegistration<URLStreamHandler> sreg = syscontext.registerService(URLStreamHandler.class, new MyHandler(), props);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyStream(new URL("foo://somehost").openStream(), baos);
Assert.assertEquals("somehost", new String(baos.toByteArray()));
} finally {
sreg.unregister();
}
try {
new URL("foo://hi").openConnection();
Assert.fail("No handler registered any more.");
} catch (IOException ex) {
// expected
}
}
示例8: WildFlyURLStreamHandlerFactory
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
public WildFlyURLStreamHandlerFactory() {
// META-INF/service discovery happens on every call to the factory
// we need to delegate to the single instance
synchronized (WildFlyURLStreamHandlerFactory.class) {
if (tracker == null) {
Runtime runtime = RuntimeLocator.getRequiredRuntime();
tracker = new URLStreamHandlerTracker(runtime.getModuleContext());
tracker.open();
}
}
}
示例9: testUpdateBundle
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的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));
}
示例10: testModuleLifecycle
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的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));
}
示例11: testAttachedFragment
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的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());
}
}
示例12: testUnattachedFragment
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的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));
}
}
示例13: start
import org.jboss.gravia.runtime.Runtime; //导入方法依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
Runtime runtime = injectedRuntime.getValue();
syscontext = runtime.getModuleContext();
}