本文整理汇总了Java中org.jboss.gravia.runtime.ModuleContext类的典型用法代码示例。如果您正苦于以下问题:Java ModuleContext类的具体用法?Java ModuleContext怎么用?Java ModuleContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModuleContext类属于org.jboss.gravia.runtime包,在下文中一共展示了ModuleContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: activateInternal
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
private void activateInternal() throws IOException {
// Register the URLStreamHandler services
Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.URL_HANDLER_PROTOCOL, ProfileURLStreamHandler.PROTOCOL_NAME);
ModuleContext syscontext = RuntimeLocator.getRequiredRuntime().getModuleContext();
registrations.add(syscontext.registerService(URLStreamHandler.class, new ProfileURLStreamHandler(), props));
props.put(Constants.URL_HANDLER_PROTOCOL, ContainerURLStreamHandler.PROTOCOL_NAME);
registrations.add(syscontext.registerService(URLStreamHandler.class, new ContainerURLStreamHandler(), props));
// Apply default {@link ConfigurationProfileItem}s
Profile profile = profileService.get().getDefaultProfile();
for (ConfigurationItem item : profile.getProfileItems(ConfigurationItem.class)) {
Map<String, Object> config = item.getDefaultAttributes();
configurationManager.get().applyConfiguration(item.getIdentity(), config);
}
}
示例2: start
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Override
public void start(final ModuleContext context) throws Exception {
camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").transform(body().prepend("Hello "));
}
});
camelctx.start();
// [FELIX-4415] Cannot associate HttpService instance with ServletContext
tracker = new ServiceTracker<HttpService, HttpService>(context, HttpService.class, null) {
@Override
public HttpService addingService(ServiceReference<HttpService> sref) {
if (httpService == null) {
httpService = super.addingService(sref);
registerHttpServiceServlet(httpService);
}
return httpService;
}
};
tracker.open();
}
示例3: start
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Override
public void start(final ModuleContext context) throws Exception {
MBeanServer server = ServiceLocator.getRequiredService(context, MBeanServer.class);
ModuleStateA moduleState = new ModuleStateA() {
@Override
public String getResourceIdentity() {
return context.getModule().getIdentity().getCanonicalForm();
}
@Override
public String getModuleState() {
return context.getModule().getState().toString();
}
};
StandardMBean mbean = new StandardMBean(moduleState, ModuleStateA.class);
server.registerMBean(mbean, getObjectName(context.getModule()));
}
示例4: completeTracker
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
private ServiceTracker<?, ?> completeTracker(final ModuleContext syscontext, final ServiceTarget serviceTarget) {
ServiceTracker<?, ?> tracker = new ServiceTracker<BootstrapComplete, BootstrapComplete>(syscontext, BootstrapComplete.class, null) {
@Override
public BootstrapComplete addingService(ServiceReference<BootstrapComplete> reference) {
BootstrapComplete service = super.addingService(reference);
// FuseFabric banner message
Properties brandingProperties = new Properties();
String resname = "/META-INF/branding.properties";
try {
URL brandingURL = getClass().getResource(resname);
brandingProperties.load(brandingURL.openStream());
} catch (IOException e) {
throw new IllegalStateException("Cannot read branding properties from: " + resname);
}
System.out.println(brandingProperties.getProperty("welcome"));
return service;
}
};
tracker.open();
return tracker;
}
示例5: activateInternal
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
private void activateInternal() {
ModuleContext syscontext = RuntimeLocator.getRequiredRuntime().getModuleContext();
httpTracker = new ServiceTracker<HttpService, HttpService>(syscontext, HttpService.class.getName(), null) {
public HttpService addingService(ServiceReference<HttpService> sref) {
HttpService service = super.addingService(sref);
try {
service.registerServlet("/agent", new AgentServlet(agent.get()), null, null);
// [TODO] #37 Compute actual endpoint url for HttpEndpointService
LOGGER.info("Agent HttpEndpoint registered: http://localhost:8080/agent");
} catch (Exception ex) {
LOGGER.error("Cannot register agent servlet", ex);
}
return service;
}
public void removedService(ServiceReference<HttpService> sref, HttpService service) {
service.unregister("/agent");
LOGGER.info("Agent HttpEndpoint unregistered");
}
};
httpTracker.open();
}
示例6: testModuleLifecycle
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Test
public void testModuleLifecycle() throws Exception {
Runtime runtime = RuntimeLocator.getRequiredRuntime();
Module modA = runtime.getModule(getClass().getClassLoader());
Assert.assertEquals(Module.State.ACTIVE, modA.getState());
ModuleContext context = modA.getModuleContext();
ServiceRegistration<String> sreg = context.registerService(String.class, new String("Hello"), null);
Assert.assertNotNull("Null sreg", sreg);
String service = context.getService(sreg.getReference());
Assert.assertEquals("Hello", service);
modA.stop();
Assert.assertEquals(Module.State.INSTALLED, modA.getState());
modA.uninstall();
Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());
}
示例7: testModuleLifecycle
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Test
public void testModuleLifecycle() throws Exception {
Module modA = RuntimeLocator.getRequiredRuntime().getModule(getClass().getClassLoader());
Assert.assertEquals(Module.State.ACTIVE, modA.getState());
ModuleContext context = modA.getModuleContext();
ServiceRegistration<String> sreg = context.registerService(String.class, new String("Hello"), null);
Assert.assertNotNull("Null sreg", sreg);
String service = context.getService(sreg.getReference());
Assert.assertEquals("Hello", service);
modA.stop();
Assert.assertEquals(Module.State.INSTALLED, modA.getState());
modA.uninstall();
Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());
}
示例8: getService
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
/**
* Returns the service object referenced by the specified <code>ServiceReference</code> object.
*
* @return A service object for the service associated with <code>reference</code> or <code>null</code>
*/
<S> S getService(ModuleContext context, ServiceState<S> serviceState) {
// If the service has been unregistered, null is returned.
if (serviceState.isUnregistered())
return null;
// Add the given service ref to the list of used services
serviceState.addUsingModule((AbstractModule) context.getModule());
S value = serviceState.getScopedValue(context.getModule());
// If the factory returned an invalid value
// restore the service usage counts
if (value == null) {
serviceState.removeUsingModule((AbstractModule) context.getModule());
}
return value;
}
示例9: init
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Override
public void init() {
assertNoShutdown();
// Register the Runtime
ModuleContext syscontext = adapt(ModuleContext.class);
systemServices.add(registerRuntimeService(syscontext));
// Register the LogService
systemServices.add(registerLogService(syscontext));
// Register the MBeanServer service
systemServices.add(registerMBeanServer(syscontext));
// Install the plugin modules
List<Module> pluginModules = installPluginModules();
// Start the plugin modules
startPluginModules(pluginModules);
// Load initial configurations
loadInitialConfigurations(syscontext);
}
示例10: testBasicModule
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Test
public void testBasicModule() throws Exception {
Module modA = getRuntime().installModule(getClass().getClassLoader(), getModuleHeadersA());
Module modA1 = getRuntime().installModule(getClass().getClassLoader(), getModuleHeadersA1());
modA.start();
modA1.start();
ModuleContext ctxA = modA.getModuleContext();
ServiceReference<ServiceA> srefA = ctxA.getServiceReference(ServiceA.class);
Assert.assertNotNull("ServiceReference not null", srefA);
ServiceA srvA = ctxA.getService(srefA);
Assert.assertEquals("ServiceA#1:ServiceA1#1:Hello", srvA.doStuff("Hello"));
}
示例11: testBasicModule
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Test
public void testBasicModule() throws Exception {
Module modA = getRuntime().installModule(getClass().getClassLoader(), getModuleHeadersA());
modA.start();
ModuleContext ctxA = modA.getModuleContext();
ServiceReference<EmbeddedServices> srefA = ctxA.getServiceReference(EmbeddedServices.class);
Assert.assertNotNull("ServiceReference not null", srefA);
EmbeddedServices srvA = ctxA.getService(srefA);
Assert.assertNotNull(srvA.getConfigurationAdmin());
Assert.assertNotNull(srvA.getLogService());
Assert.assertNotNull(srvA.getMBeanServer());
}
示例12: adapt
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <A> A adapt(Class<A> type) {
A result = null;
if (type.isAssignableFrom(Bundle.class)) {
result = (A) getBundleAdaptor(this);
} else if (type.isAssignableFrom(Runtime.class)) {
result = (A) runtime;
} else if (type.isAssignableFrom(AbstractRuntime.class)) {
result = (A) runtime;
} else if (type.isAssignableFrom(ClassLoader.class)) {
result = (A) classLoader;
} else if (type.isAssignableFrom(Resource.class)) {
result = (A) resource;
} else if (type.isAssignableFrom(Module.class)) {
result = (A) this;
} else if (type.isAssignableFrom(ModuleContext.class)) {
result = (A) getModuleContext();
} else if (type.isAssignableFrom(ModuleEntriesProvider.class)) {
result = (A) getAttachment(MODULE_ENTRIES_PROVIDER_KEY);
}
return result;
}
示例13: testModuleLifecycle
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Test
public void testModuleLifecycle(@ArquillianResource Bundle bundle) throws Exception {
Module module = RuntimeLocator.getRequiredRuntime().getModule(bundle.getBundleId());
Assert.assertEquals(bundle.getBundleId(), module.getModuleId());
Assert.assertEquals("example-bundle:0.0.0", module.getIdentity().toString());
module.start();
Assert.assertEquals(State.ACTIVE, module.getState());
module.stop();
Assert.assertEquals(State.INSTALLED, module.getState());
Assert.assertNull("ModuleContext null", module.getModuleContext());
module.start();
Assert.assertEquals(State.ACTIVE, module.getState());
ModuleContext context = module.getModuleContext();
ServiceReference<String> sref = context.getServiceReference(String.class);
Assert.assertNotNull("ServiceReference not null", sref);
Assert.assertEquals("Hello", context.getService(sref));
}
示例14: testBasicModule
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Test
public void testBasicModule() throws Exception {
Bundle bundleA = bundleContext.installBundle(BUNDLE_A, deployer.getDeployment(BUNDLE_A));
Bundle bundleA1 = bundleContext.installBundle(BUNDLE_A1, deployer.getDeployment(BUNDLE_A1));
bundleA.start();
bundleA1.start();
Module modA = OSGiRuntimeLocator.getRuntime().getModule(bundleA.getBundleId());
ModuleContext ctxA = modA.getModuleContext();
ServiceReference<ServiceA> srefA = ctxA.getServiceReference(ServiceA.class);
Assert.assertNotNull("ServiceReference not null", srefA);
ServiceA srvA = ctxA.getService(srefA);
Assert.assertEquals("ServiceA#1:ServiceA1#1:Hello", srvA.doStuff("Hello"));
}
示例15: testURLHandlerService
import org.jboss.gravia.runtime.ModuleContext; //导入依赖的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
}
}