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


Java ModuleContext类代码示例

本文整理汇总了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);
        }
    }
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:18,代码来源:BootstrapService.java

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

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

示例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;
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:23,代码来源:FabricBootstrapService.java

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

    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

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

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

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

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

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

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

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

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

示例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
    }
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:36,代码来源:URLStreamHandlerTestBase.java


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