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


Java ModuleContext.getServiceReference方法代码示例

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


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

示例1: 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

示例2: 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

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

示例4: 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

示例5: 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

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

    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

示例7: 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

示例8: 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

示例9: assertDisableComponent

import org.jboss.gravia.runtime.ModuleContext; //导入方法依赖的package包/类
private void assertDisableComponent(final ModuleContext ctxA, ServiceA srvA) throws InterruptedException {

        final CountDownLatch latch = new CountDownLatch(1);
        ServiceListener listener = new ServiceListener() {
            @Override
            public void serviceChanged(ServiceEvent event) {
                int type = event.getType();
                ServiceReference<?> sref = event.getServiceReference();
                List<String> clazzes = Arrays.asList(((String[]) sref.getProperty(Constants.OBJECTCLASS)));
                if (type == ServiceEvent.UNREGISTERING && clazzes.contains(ServiceA1.class.getName())) {
                    ctxA.removeServiceListener(this);
                    latch.countDown();
                }
            }
        };
        ctxA.addServiceListener(listener);

        ComponentContext ccA1 = srvA.getServiceA1().getComponentContext();
        ccA1.disableComponent(ServiceA1.class.getName());

        Assert.assertTrue(latch.await(2, TimeUnit.SECONDS));

        ServiceReference<ServiceA> srefA = ctxA.getServiceReference(ServiceA.class);
        Assert.assertNull("ServiceReference null", srefA);
        ServiceReference<ServiceA1> srefA1 = ctxA.getServiceReference(ServiceA1.class);
        Assert.assertNull("ServiceReference null", srefA1);
    }
 
开发者ID:tdiesler,项目名称:gravia,代码行数:28,代码来源:ServiceComponentTest.java

示例10: 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

示例11: 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

示例12: 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

示例13: getLogService

import org.jboss.gravia.runtime.ModuleContext; //导入方法依赖的package包/类
private LogService getLogService(ModuleContext context) {
    ServiceReference<LogService> sref = context.getServiceReference(LogService.class);
    Assert.assertNotNull("LogService not null", sref);
    return context.getService(sref);
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:6,代码来源:LogServiceTest.java

示例14: testServiceAccess

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

    final AtomicReference<CountDownLatch> latchref = new AtomicReference<CountDownLatch>(new CountDownLatch(1));
    ModuleContext syscontext = getRuntime().getModuleContext();
    ServiceTracker<?, ?> tracker = new ServiceTracker<ServiceC, ServiceC>(syscontext, ServiceC.class, null) {
        @Override
        public void modifiedService(ServiceReference<ServiceC> reference, ServiceC service) {
            latchref.get().countDown();
        }
    };
    tracker.open();

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

    ModuleContext contextC = modC.getModuleContext();
    ServiceReference<ServiceC> srefC = contextC.getServiceReference(ServiceC.class);
    Assert.assertNotNull("ServiceReference not null", srefC);

    ServiceC srvC = contextC.getService(srefC);
    Assert.assertEquals("ServiceC#1:null", srvC.doStuff());

    ConfigurationAdmin configAdmin = ServiceLocator.getRequiredService(contextC, ConfigurationAdmin.class);
    Configuration config = configAdmin.getConfiguration(ServiceC.PID, null);
    Dictionary<String, Object> props = config.getProperties();
    Assert.assertNull("Config is empty, but was: " + props, props);
    props = new Hashtable<String, Object>();
    props.put("key", "val1");
    config.update(props);

    Assert.assertTrue("Service modified", latchref.get().await(500, TimeUnit.MILLISECONDS));

    srefC = contextC.getServiceReference(ServiceC.class);
    Assert.assertNotNull("ServiceReference not null", srefC);
    srvC = contextC.getService(srefC);
    Assert.assertEquals("ServiceC#1:val1", srvC.doStuff());

    latchref.set(new CountDownLatch(1));

    props = config.getProperties();
    Assert.assertNotNull("Config not empty, but was: " + props, props);
    props.put("key", "val2");
    config.update(props);

    Assert.assertTrue("Service modified", latchref.get().await(500, TimeUnit.MILLISECONDS));

    srefC = contextC.getServiceReference(ServiceC.class);
    Assert.assertNotNull("ServiceReference not null", srefC);
    srvC = contextC.getService(srefC);
    Assert.assertEquals("ServiceC#1:val2", srvC.doStuff());
}
 
开发者ID:tdiesler,项目名称:gravia,代码行数:53,代码来源:ConfigurationModifiedTestCase.java

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


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