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


Java ModuleContext.getService方法代码示例

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


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

示例1: 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());
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:21,代码来源:WebappBundleModuleLifecycleTest.java

示例2: 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());
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:20,代码来源:WebappModuleLifecycleTest.java

示例3: 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"));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:17,代码来源:ServiceComponentTestCase.java

示例4: 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());
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:17,代码来源:EmbeddedServicesTestCase.java

示例5: 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"));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:18,代码来源:ServiceComponentTest.java

示例6: testBasicModule

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

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module module = runtime.getModule(getClass().getClassLoader());

    ModuleContext ctxA = module.getModuleContext();
    ServiceReference<ServiceD> srefD = ctxA.getServiceReference(ServiceD.class);
    Assert.assertNotNull("ServiceReference not null", srefD);

    ServiceD srvD = ctxA.getService(srefD);
    Assert.assertEquals("ServiceD#1:ServiceD1#1:null:Hello", srvD.doStuff("Hello"));

    ConfigurationAdmin configAdmin = getConfigurationAdmin(module);
    Configuration config = configAdmin.getConfiguration(ServiceD1.class.getName());
    Assert.assertNotNull("Config not null", config);
    Assert.assertNull("Config is empty, but was: " + config.getProperties(), config.getProperties());

    Dictionary<String, String> configProps = new Hashtable<String, String>();
    configProps.put("foo", "bar");
    config.update(configProps);

    ServiceD1 srvD1 = srvD.getServiceD1();
    Assert.assertTrue(srvD1.awaitModified(4000, TimeUnit.MILLISECONDS));

    Assert.assertEquals("ServiceD#1:ServiceD1#1:bar:Hello", srvD.doStuff("Hello"));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:28,代码来源:ConfigurationAdminTest.java

示例7: 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());

    String symbolicName = modA.getHeaders().get("Bundle-SymbolicName");
    Assert.assertEquals("simple-bundle", symbolicName);

    ModuleContext context = modA.getModuleContext();
    Module sysmodule = runtime.getModule(0);
    symbolicName = sysmodule.getHeaders().get("Bundle-SymbolicName");
    Assert.assertNotNull("System bundle symbolic name not null", symbolicName);

    ServiceReference<String> sref = context.getServiceReference(String.class);
    String service = context.getService(sref);
    Assert.assertEquals("Hello", service);

    modA.stop();
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    modA.uninstall();
    Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());

    try {
        modA.start();
        Assert.fail("IllegalStateException expected");
    } catch (IllegalStateException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:33,代码来源:BundleLifecycleTest.java

示例8: testModuleLifecycle

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

    // Verify that the Runtime service is registered
    Runtime runtime = ServiceLocator.getRequiredService(Runtime.class);

    Module modA = runtime.getModule(getClass().getClassLoader());
    Assert.assertEquals(Module.State.ACTIVE, modA.getState());

    String symbolicName = modA.getHeaders().get("Bundle-SymbolicName");
    Assert.assertEquals("simple-module", symbolicName);

    ModuleContext context = modA.getModuleContext();
    Module sysmodule = runtime.getModule(0);
    symbolicName = sysmodule.getHeaders().get("Bundle-SymbolicName");
    Assert.assertNotNull("System bundle symbolic name not null", symbolicName);

    ServiceReference<String> sref = context.getServiceReference(String.class);
    String service = context.getService(sref);
    Assert.assertEquals("Hello", service);

    modA.stop();
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    modA.uninstall();
    Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());

    try {
        modA.start();
        Assert.fail("IllegalStateException expected");
    } catch (IllegalStateException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:35,代码来源:ModuleLifecycleTest.java

示例9: testServiceAvailability

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

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module modA = runtime.getModule(getClass().getClassLoader());

    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"));

    assertDisableComponent(ctxA, srvA);
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:16,代码来源:ServiceComponentTest.java

示例10: testServiceAccess

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

    Module modA = getRuntime().installModule(getClass().getClassLoader(), getModuleHeadersA());
    modA.start();

    ModuleContext contextA = modA.getModuleContext();
    String filter = "(component.factory=" + ServiceFactoryB.FACTORY_ID + ")";
    Collection<ServiceReference<ComponentFactory>> srefs = contextA.getServiceReferences(ComponentFactory.class, filter);
    Assert.assertEquals("ServiceReference not null", 1, srefs.size());

    ComponentFactory factory = contextA.getService(srefs.iterator().next());
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("key", "val1");
    factory.newInstance(props);

    Collection<ServiceReference<ServiceB>> srefsB = contextA.getServiceReferences(ServiceB.class, "(key=val1)");
    Assert.assertEquals("ServiceReference not null", 1, srefsB.size());
    ServiceB srvB = contextA.getService(srefsB.iterator().next());
    Assert.assertEquals("ServiceFactoryB#1:val1", srvB.doStuff());

    props.put("key", "val2");
    factory.newInstance(props);

    srefsB = contextA.getServiceReferences(ServiceB.class, "(key=val2)");
    Assert.assertEquals("ServiceReference not null", 1, srefsB.size());
    srvB = contextA.getService(srefsB.iterator().next());
    Assert.assertEquals("ServiceFactoryB#2:val2", srvB.doStuff());
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:30,代码来源:ComponentFactoryTestCase.java

示例11: testBasicModule

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

    Manifest manifest = new ManifestBuilder().addIdentityCapability("moduleA", "1.0.0").getManifest();
    ManifestHeadersProvider headersProvider = new ManifestHeadersProvider(manifest);

    Module modA = getRuntime().installModule(SimpleModuleActivator.class.getClassLoader(), headersProvider.getHeaders());
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    modA.start();
    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());

    try {
        modA.start();
        Assert.fail("IllegalStateException expected");
    } catch (IllegalStateException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:33,代码来源:ModuleLifecycleTestCase.java

示例12: testModuleActivator

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

    ManifestBuilder builder = new ManifestBuilder().addIdentityCapability("moduleA", "1.0.0");
    builder.addModuleActivator(SimpleModuleActivator.class);
    ManifestHeadersProvider headersProvider = new ManifestHeadersProvider(builder.getManifest());

    Module modA = getRuntime().installModule(SimpleModuleActivator.class.getClassLoader(), headersProvider.getHeaders());
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    ModuleContext ctxA = modA.getModuleContext();
    Assert.assertNull("Null moduleContext", ctxA);

    modA.start();
    Assert.assertEquals(Module.State.ACTIVE, modA.getState());

    ctxA = modA.getModuleContext();
    ServiceReference<String> srefA = ctxA.getServiceReference(String.class);
    Assert.assertNotNull("Null sref", srefA);

    String srvA = ctxA.getService(srefA);
    Assert.assertEquals("Hello", srvA);

    modA.stop();
    Assert.assertEquals(Module.State.INSTALLED, modA.getState());

    modA.uninstall();
    Assert.assertEquals(Module.State.UNINSTALLED, modA.getState());

    try {
        modA.start();
        Assert.fail("IllegalStateException expected");
    } catch (IllegalStateException ex) {
        // expected
    }
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:37,代码来源:ModuleLifecycleTestCase.java

示例13: testServiceAccess

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

    Module modD = getRuntime().installModule(getClass().getClassLoader(), getModuleHeadersD());
    modD.start();

    Module modD1 = getRuntime().installModule(getClass().getClassLoader(), getModuleHeadersD1());
    modD1.start();

    ModuleContext contextD = modD.getModuleContext();
    ServiceReference<ServiceD> srefD = contextD.getServiceReference(ServiceD.class);
    Assert.assertNotNull("ServiceReference not null", srefD);

    ServiceD srvD = contextD.getService(srefD);
    Assert.assertEquals("ServiceD#1:ServiceD1#1:null:Hello", srvD.doStuff("Hello"));

    ConfigurationAdmin configAdmin = ServiceLocator.getRequiredService(modD1.getModuleContext(), ConfigurationAdmin.class);
    Configuration config = configAdmin.getConfiguration(ServiceD1.class.getName());
    Assert.assertNotNull("Config not null", config);
    Assert.assertNull("Config is empty, but was: " + config.getProperties(), config.getProperties());

    Dictionary<String, String> configProps = new Hashtable<String, String>();
    configProps.put("foo", "bar");
    config.update(configProps);

    ServiceD1 srvD1 = srvD.getServiceD1();
    Assert.assertTrue(srvD1.awaitModified(4000, TimeUnit.MILLISECONDS));

    Assert.assertEquals("ServiceD#1:ServiceD1#1:bar:Hello", srvD.doStuff("Hello"));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:31,代码来源:ConfigurationAdminTestCase.java

示例14: testBasicModule

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

    Bundle bundleD = bundleContext.installBundle(BUNDLE_D, deployer.getDeployment(BUNDLE_D));
    Bundle bundleD1 = bundleContext.installBundle(BUNDLE_D1, deployer.getDeployment(BUNDLE_D1));

    bundleD.start();
    bundleD1.start();

    Runtime runtime = RuntimeLocator.getRequiredRuntime();
    Module modD = runtime.getModule(bundleD.getBundleId());
    Module modD1 = runtime.getModule(bundleD1.getBundleId());

    ModuleContext ctxD = modD.getModuleContext();
    ServiceReference<ServiceD> srefA = ctxD.getServiceReference(ServiceD.class);
    Assert.assertNotNull("ServiceReference not null", srefA);

    ServiceD srvD = ctxD.getService(srefA);
    Assert.assertEquals("ServiceD#1:ServiceD1#1:null:Hello", srvD.doStuff("Hello"));

    ConfigurationAdmin configAdmin = getConfigurationAdmin(modD1);
    Configuration config = configAdmin.getConfiguration(ServiceD1.class.getName());
    Assert.assertNotNull("Config not null", config);
    Assert.assertNull("Config is empty, but was: " + config.getProperties(), config.getProperties());

    Dictionary<String, String> configProps = new Hashtable<String, String>();
    configProps.put("foo", "bar");
    config.update(configProps);

    ServiceD1 srvD1 = srvD.getServiceD1();
    Assert.assertTrue(srvD1.awaitModified(4000, TimeUnit.MILLISECONDS));

    Assert.assertEquals("ServiceD#1:ServiceD1#1:bar:Hello", srvD.doStuff("Hello"));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:35,代码来源:ConfigurationAdminTest.java

示例15: getConfigurationAdmin

import org.jboss.gravia.runtime.ModuleContext; //导入方法依赖的package包/类
protected ConfigurationAdmin getConfigurationAdmin(Module module) {
    ModuleContext context = module.getModuleContext();
    return context.getService(context.getServiceReference(ConfigurationAdmin.class));
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:5,代码来源:ConfigurationAdminTest.java


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