Package org.jboss.gravia.runtime

Examples of org.jboss.gravia.runtime.ModuleContext


    @Test
    public void testServletAccess() throws Exception {
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());
        ModuleContext context = module.getModuleContext();
        ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
        HttpService httpService = context.getService(sref);
        String reqspec = "/service?test=param&param=Kermit";
        try {
            // Verify that the alias is not yet available
            assertNotAvailable(reqspec);

            // Register the test servlet and make a call
            httpService.registerServlet("/service", new HttpServiceServlet(module), null, null);
            Assert.assertEquals("Hello: Kermit", performCall(reqspec));

            // Unregister the servlet alias
            httpService.unregister("/service");
            assertNotAvailable(reqspec);

            // Verify that the alias is not available any more
            assertNotAvailable(reqspec);
        } finally {
            context.ungetService(sref);
        }
    }
View Full Code Here


    @Test
    public void testResourceAccess() throws Exception {
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        Module module = runtime.getModule(getClass().getClassLoader());
        ModuleContext context = module.getModuleContext();
        ServiceReference<HttpService> sref = context.getServiceReference(HttpService.class);
        HttpService httpService = context.getService(sref);
        String reqspec = "/resource/message.txt";
        try {
            // Verify that the alias is not yet available
            assertNotAvailable(reqspec);

            // Register the test resource and make a call
            httpService.registerResources("/resource", "/res", null);
            Assert.assertEquals("Hello from Resource", performCall(reqspec));

            // Unregister the servlet alias
            httpService.unregister("/resource");

            // Verify that the alias is not available any more
            assertNotAvailable(reqspec);
        } finally {
            context.ungetService(sref);
        }
    }
View Full Code Here

    public void testModuleLifecycle() throws Exception {

        Module modA = RuntimeLocator.getRuntime().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.RESOLVED, modA.getState());
View Full Code Here

            }
        }
    }

    private static ConfigurationAdmin getConfigurationAdmin() {
        ModuleContext syscontext = RuntimeLocator.getRequiredRuntime().getModuleContext();
        ServiceReference<ConfigurationAdmin> sref = syscontext.getServiceReference(ConfigurationAdmin.class);
        return sref != null ? syscontext.getService(sref) : null;
    }
View Full Code Here

    @Override
    public void init() {

        // Register the LogService
        ModuleContext syscontext = adapt(ModuleContext.class);
        syscontext.registerService(LogService.class.getName(), new EmbeddedLogServiceFactory(), null);

        // Register the MBeanServer service
        MBeanServer mbeanServer = findOrCreateMBeanServer();
        syscontext.registerService(MBeanServer.class, mbeanServer, null);

        // Install the plugin modules
        List<Module> pluginModules = new ArrayList<Module>();
        ClassLoader classLoader = getClass().getClassLoader();
        ServiceLoader<RuntimePlugin> services = ServiceLoader.load(RuntimePlugin.class, EmbeddedRuntime.class.getClassLoader());
View Full Code Here

        return Bundle.UNINSTALLED;
    }

    @Override
    public BundleContext getBundleContext() {
        ModuleContext context = module.getModuleContext();
        return context != null ? new BundleContextAdaptor(context) : null;
    }
View Full Code Here

public class GraviaServlet extends HttpServlet {

    @Override
    public void init() throws ServletException {
        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        ModuleContext moduleContext = runtime.getModuleContext();
        ServiceReference<HttpService> sref = moduleContext.getServiceReference(HttpService.class);
        HttpService httpService = moduleContext.getService(sref);

        // Register the test servlet and make a call
        try {
            httpService.registerServlet("/dummy", new HttpServiceServlet(runtime.getModule(0)), null, null);
        } catch (Exception e) {
View Full Code Here

    }

    private void registerServices(ServletContext servletContext, Runtime runtime) {
        RuntimeEnvironment environment = new RuntimeEnvironment(runtime).initDefaultContent();
        TomcatResourceInstaller installer = new TomcatResourceInstaller(environment);
        ModuleContext syscontext = runtime.getModuleContext();
        registrations.add(syscontext.registerService(RuntimeEnvironment.class, environment, null));
        registrations.add(syscontext.registerService(ResourceInstaller.class, installer, null));
    }
View Full Code Here

    @Override
    public void init() {
        assertNoShutdown();

        // Register the LogService
        ModuleContext syscontext = adapt(ModuleContext.class);
        systemServices.add(syscontext.registerService(LogService.class.getName(), new EmbeddedLogServiceFactory(), null));

        // Register the MBeanServer service
        MBeanServer mbeanServer = findOrCreateMBeanServer();
        systemServices.add(syscontext.registerService(MBeanServer.class, mbeanServer, null));

        // Install the plugin modules
        List<Module> pluginModules = new ArrayList<Module>();
        ClassLoader classLoader = getClass().getClassLoader();
        ServiceLoader<RuntimePlugin> services = ServiceLoader.load(RuntimePlugin.class, EmbeddedRuntime.class.getClassLoader());
View Full Code Here

        Runtime runtime = RuntimeLocator.getRequiredRuntime();
        ServletContext servletContext = event.getServletContext();
        Module module = runtime.getModule(servletContext.getClassLoader());

        // HttpService integration
        ModuleContext moduleContext = module.getModuleContext();
        BundleContext bundleContext = new BundleContextAdaptor(moduleContext);
        servletContext.setAttribute(BundleContext.class.getName(), bundleContext);
    }
View Full Code Here

TOP

Related Classes of org.jboss.gravia.runtime.ModuleContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.