當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。