• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ModuleContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



ModuleContext类属于org.jboss.gravia.runtime包,在下文中一共展示了ModuleContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: start

import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Override
public void start(final ModuleContext context) throws Exception {
    MBeanServer server = ServiceLocator.getRequiredService(context, MBeanServer.class);
    ModuleStateB moduleState = new ModuleStateB() {
        @Override
        public String getModuleState() {
            return context.getModule().getState().toString();
        }
    };
    StandardMBean mbean = new StandardMBean(moduleState, ModuleStateB.class);
    server.registerMBean(mbean, getObjectName(context.getModule()));
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:13,代码来源:ModuleActivatorB.java


示例17: stop

import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Override
public void stop(ModuleContext context) throws Exception {
    camelctx.stop();
    if (tracker != null) {
        tracker.close();
    }
    if (httpService != null) {
        httpService.unregister("/service");
    }
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:11,代码来源:CamelTransformHttpActivator.java


示例18: registerServices

import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
private void registerServices(ServletContext servletContext, Runtime runtime) {
    RuntimeEnvironment environment = new RuntimeEnvironment(runtime).initDefaultContent();
    TomcatResourceInstaller installer = new TomcatResourceInstaller(environment);
    ModuleContext syscontext = runtime.getModuleContext();
    syscontext.registerService(RuntimeEnvironment.class, environment, null);
    syscontext.registerService(ResourceInstaller.class, installer, null);
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:8,代码来源:FabricTomcatActivator.java


示例19: install

import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
public ServiceController<Void> install(ServiceTarget serviceTarget, ServiceVerificationHandler verificationHandler) {
    ServiceBuilder<Void> builder = serviceTarget.addService(FabricConstants.FABRIC_SUBSYSTEM_SERVICE_NAME, this);
    builder.addDependency(GraviaConstants.MODULE_CONTEXT_SERVICE_NAME, ModuleContext.class, injectedModuleContext);
    builder.addDependency(GraviaConstants.RUNTIME_SERVICE_NAME, Runtime.class, injectedRuntime);
    builder.addListener(verificationHandler);
    return builder.install();
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:8,代码来源:FabricBootstrapService.java


示例20: start

import org.jboss.gravia.runtime.ModuleContext; //导入依赖的package包/类
@Override
public void start(StartContext startContext) throws StartException {
    LOGGER.info("Activating Fabric Subsystem");

    Runtime runtime = injectedRuntime.getValue();
    ModuleContext syscontext = runtime.getModuleContext();

    // Install and start this as a {@link Module}
    ModuleClassLoader classLoader = (ModuleClassLoader) getClass().getClassLoader();
    try {
        Dictionary<String, String> headers = getManifestHeaders(classLoader, "wildfly-extension");
        module = runtime.installModule(classLoader, headers);

        // Attach the {@link ModuleEntriesProvider} so
        ModuleEntriesProvider entriesProvider = new ClassLoaderEntriesProvider(module);
        Attachable attachable = AbstractModule.assertAbstractModule(module);
        attachable.putAttachment(AbstractModule.MODULE_ENTRIES_PROVIDER_KEY, entriesProvider);

        // Start the module
        module.start();

    } catch (RuntimeException rte) {
        throw rte;
    } catch (Exception ex) {
        throw new StartException(ex);
    }

    // Open service trackers for {@link Resolver}, {@link Repository}, {@link Provisioner}
    trackers = new HashSet<ServiceTracker<?, ?>>();
    trackers.add(resolverTracker(syscontext, startContext.getChildTarget()));
    trackers.add(repositoryTracker(syscontext, startContext.getChildTarget()));
    trackers.add(provisionerTracker(syscontext, startContext.getChildTarget()));
    trackers.add(completeTracker(syscontext, startContext.getChildTarget()));
}
 
开发者ID:tdiesler,项目名称:fabric8poc,代码行数:35,代码来源:FabricBootstrapService.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Prior类代码示例发布时间:2022-05-16
下一篇:
Java PsiPackageReference类代码示例发布时间:2022-05-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap