Package org.apache.geronimo.gbean.jmx

Examples of org.apache.geronimo.gbean.jmx.GBeanMBean


            throw new InvalidConfigException("Source must be within the config store: source=" + source + ", configStoreDir=" + rootDir);
        }

        URI configId;
        try {
            GBeanMBean config = loadConfig(source);
            configId = (URI) config.getAttribute("ID");
            index.setProperty(configId.toString(), source.getName());
        } catch (Exception e) {
            throw new InvalidConfigException("Unable to get ID from downloaded configuration", e);
        }
View Full Code Here


        }

        FileInputStream fis = new FileInputStream(file);
        try {
            ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(fis));
            GBeanMBean config;
            try {
                GBeanData gbeanData = new GBeanData();
                gbeanData.readExternal(ois);
                config = new GBeanMBean(gbeanData, Configuration.class.getClassLoader());
            } catch (ClassNotFoundException e) {
                //TODO more informative exceptions
                throw new InvalidConfigException("Unable to read attribute ", e);
            } catch (Exception e) {
                throw new InvalidConfigException("Unable to set attribute ", e);
            }

            config.setReferencePattern("ConfigurationStore", objectName);
            return config;
        } finally {
            fis.close();
        }
    }
View Full Code Here

        super.setUp();

        try {
            Map gbeans = new HashMap();
            ObjectName objectName = new ObjectName("test:name=MyGBean");
            gbeans.put(objectName, new GBeanMBean(MyGBean.GBEAN_INFO));
            GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO);
            config.setAttribute("ID", URI.create("org/apache/geronimo/run-test"));
            config.setReferencePatterns("Parent", null);
            config.setAttribute("classPath", Collections.EMPTY_LIST);
            config.setAttribute("gBeanState", Configuration.storeGBeans(gbeans));

            carFile = File.createTempFile("run", ".car");
            Manifest manifest = new Manifest();
            Attributes attrs = manifest.getMainAttributes();
            attrs.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
            attrs.putValue("Geronimo-GBean", objectName.toString());
            attrs.putValue(Attributes.Name.MAIN_CLASS.toString(), Run.class.getName());
            attrs.putValue(Attributes.Name.CLASS_PATH.toString(), "geronimo-kernel-DEV.jar commons-logging-1.0.3.jar cglib-full-2.0-RC2.jar");
            JarOutputStream jos = new JarOutputStream(new FileOutputStream(carFile), manifest);
            jos.putNextEntry(new ZipEntry("META-INF/config.ser"));
            ObjectOutputStream oos = new ObjectOutputStream(jos);
            config.getGBeanData().writeExternal(oos);
            oos.flush();
            jos.closeEntry();
            jos.putNextEntry(new ZipEntry("org/apache/geronimo/kernel/config/MyGBean.class"));
            byte[] buffer = new byte[4096];
            InputStream is = MyGBean.class.getClassLoader().getResourceAsStream("org/apache/geronimo/kernel/config/MyGBean.class");
View Full Code Here

    private void verifyDeployment(File unpackedDir, ClassLoader cl, J2eeContext j2eeContext, String resourceAdapterName) throws Exception {
        DataSource ds = null;
        Kernel kernel = null;
        try {
            GBeanMBean config = loadConfig(unpackedDir, cl);

            kernel = new Kernel("blah");
            kernel.boot();

            GBeanMBean serverInfoGBean = new GBeanMBean(ServerInfo.GBEAN_INFO);
            serverInfoGBean.setAttribute("baseDirectory", ".");
            ObjectName serverInfoObjectName = ObjectName.getInstance(j2eeContext.getJ2eeDomainName() + ":type=ServerInfo");
            kernel.loadGBean(serverInfoObjectName, serverInfoGBean);
            kernel.startGBean(serverInfoObjectName);
            assertRunning(kernel, serverInfoObjectName);

            GBeanMBean j2eeServerGBean = new GBeanMBean(J2EEServerImpl.GBEAN_INFO);
            j2eeServerGBean.setReferencePatterns("ServerInfo", Collections.singleton(serverInfoObjectName));
            ObjectName j2eeServerObjectName = NameFactory.getServerName(null, null, j2eeContext);
//                    ObjectName.getInstance(j2eeDomainName + ":j2eeType=J2EEServer,name=" + j2eeServerName);
            kernel.loadGBean(j2eeServerObjectName, j2eeServerGBean);
            kernel.startGBean(j2eeServerObjectName);
            assertRunning(kernel, j2eeServerObjectName);
View Full Code Here

        InputStream in = new FileInputStream(new File(unpackedCar, "META-INF/config.ser"));
        try {
            ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(in));
            GBeanData config = new GBeanData();
            config.readExternal(ois);
            return new GBeanMBean(config, classLoader);
        } finally {
            in.close();
        }
    }
View Full Code Here

            throw new DeploymentException("Could not construct module name", e);
        }

        // create a gbean for the app client module and add it to the ear
        ReadOnlyContext componentContext;
        GBeanMBean appClientModuleGBean = new GBeanMBean(J2EEAppClientModuleImpl.GBEAN_INFO, earClassLoader);
        try {
            appClientModuleGBean.setReferencePatterns("J2EEServer", Collections.singleton(earContext.getServerObjectName()));
            if (!earContext.getJ2EEApplicationName().equals("null")) {
                appClientModuleGBean.setReferencePatterns("J2EEApplication", Collections.singleton(earContext.getApplicationObjectName()));
            }
            appClientModuleGBean.setAttribute("deploymentDescriptor", null);

            componentContext = buildComponentContext(earContext, appClientModule, appClient, geronimoAppClient, earClassLoader);
            appClientModuleGBean.setAttribute("componentContext", componentContext);
        } catch (Exception e) {
            throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
        }
        earContext.addGBean(appClientModuleName, appClientModuleGBean);

        // create another child configuration within the config store for the client application
        EARContext appClientDeploymentContext = null;
        File appClientConfiguration = null;
        try {
            try {
                appClientConfiguration = store.createNewConfigurationDir();

                // construct the app client deployment context... this is the same class used by the ear context
                try {

                    URI clientConfigId = URI.create(geronimoAppClient.getClientConfigId());
                    URI clientParentId;
                    if (geronimoAppClient.isSetClientParentId()) {
                        clientParentId = URI.create(geronimoAppClient.getClientParentId());
                    } else {
                        clientParentId = defaultClientParentId;
                    }
                    appClientDeploymentContext = new EARContext(appClientConfiguration,
                            clientConfigId,
                            ConfigurationModuleType.APP_CLIENT,
                            clientParentId,
                            kernel,
                            clientDomainName,
                            clientServerName,
                            clientApplicationName,
                            transactionContextManagerObjectName,
                            connectionTrackerObjectName,
                            null,
                            null,
                            RefContext.derivedClientRefContext(earContext.getRefContext(), ejbReferenceBuilder, resourceReferenceBuilder));
                } catch (Exception e) {
                    throw new DeploymentException("Could not create a deployment context for the app client", e);
                }

                // extract the client Jar file into a standalone packed jar file and add the contents to the output
                URI moduleBase = new URI(appClientModule.getTargetPath());
                try {
                    appClientDeploymentContext.addIncludeAsPackedJar(moduleBase, moduleFile);
                } catch (IOException e) {
                    throw new DeploymentException("Unable to copy app client module jar into configuration: " + moduleFile.getName());
                }

                // add the includes
                GerDependencyType[] includes = geronimoAppClient.getIncludeArray();
                for (int i = 0; i < includes.length; i++) {
                    GerDependencyType include = includes[i];
                    URI uri = getDependencyURI(include);
                    String name = uri.toString();
                    int idx = name.lastIndexOf('/');
                    if (idx != -1) {
                        name = name.substring(idx + 1);
                    }
                    URI path;
                    try {
                        path = new URI(name);
                    } catch (URISyntaxException e) {
                        throw new DeploymentException("Unable to generate path for include: " + uri, e);
                    }
                    try {
                        URL url = repository.getURL(uri);
                        appClientDeploymentContext.addInclude(path, url);
                    } catch (IOException e) {
                        throw new DeploymentException("Unable to add include: " + uri, e);
                    }
                }

                // add the dependencies
                GerDependencyType[] dependencies = geronimoAppClient.getDependencyArray();
                for (int i = 0; i < dependencies.length; i++) {
                    appClientDeploymentContext.addDependency(getDependencyURI(dependencies[i]));
                }

                // add manifest class path entries to the app client context
                addManifestClassPath(appClientDeploymentContext, appClientModule.getEarFile(), moduleFile, moduleBase);

                // get the classloader
                ClassLoader appClientClassLoader = appClientDeploymentContext.getClassLoader(repository);

                // pop in all the gbeans declared in the geronimo app client file
                if (geronimoAppClient != null) {
                    GerGbeanType[] gbeans = geronimoAppClient.getGbeanArray();
                    for (int i = 0; i < gbeans.length; i++) {
                        GBeanHelper.addGbean(new AppClientGBeanAdapter(gbeans[i]), appClientClassLoader, appClientDeploymentContext);
                    }
                    //deploy the resource adapters specified in the geronimo-application.xml
                    Collection resourceModules = new ArrayList();
                    try {
                        GerResourceType[] resources = geronimoAppClient.getResourceArray();
                        for (int i = 0; i < resources.length; i++) {
                            GerResourceType resource = resources[i];
                            String path;
                            JarFile connectorFile;
                            if (resource.isSetExternalRar()) {
                                path = resource.getExternalRar();
                                URI pathURI = new URI(path);
                                if (!repository.hasURI(pathURI)) {
                                    throw new DeploymentException("Missing rar in repository: " + path);
                                }
                                URL pathURL = repository.getURL(pathURI);
                                connectorFile = new JarFile(pathURL.getFile());
                            } else {
                                path = resource.getInternalRar();
                                connectorFile = new NestedJarFile(appClientModule.getEarFile(), path);
                            }
                            XmlObject connectorPlan = resource.getConnector();
                            Module connectorModule = connectorModuleBuilder.createModule(connectorPlan, connectorFile, path, null, null);
                            resourceModules.add(connectorModule);
                            connectorModuleBuilder.installModule(connectorFile, appClientDeploymentContext, connectorModule);
                        }
                        ClassLoader cl = appClientDeploymentContext.getClassLoader(repository);
                        for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) {
                            Module connectorModule = (Module) iterator.next();
                            connectorModuleBuilder.initContext(appClientDeploymentContext, connectorModule, cl);
                        }

                        for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) {
                            Module connectorModule = (Module) iterator.next();
                            connectorModuleBuilder.addGBeans(appClientDeploymentContext, connectorModule, cl);
                        }
                    } finally {
                        for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) {
                            Module connectorModule = (Module) iterator.next();
                            connectorModule.close();
                        }
                    }
                }

                // add the app client static jndi provider
                ObjectName jndiContextName = ObjectName.getInstance("geronimo.client:type=StaticJndiContext");
                GBeanMBean jndiContextGBean = new GBeanMBean("org.apache.geronimo.client.StaticJndiContextPlugin", appClientClassLoader);
                try {

                    componentContext = buildComponentContext(appClientDeploymentContext, appClientModule, appClient, geronimoAppClient, earClassLoader);
                    jndiContextGBean.setAttribute("context", componentContext);
                } catch (Exception e) {
                    throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
                }
                appClientDeploymentContext.addGBean(jndiContextName, jndiContextGBean);

                // finally add the app client container
                ObjectName appClienContainerName = ObjectName.getInstance("geronimo.client:type=ClientContainer");
                GBeanMBean appClienContainerGBean = new GBeanMBean("org.apache.geronimo.client.AppClientContainer", appClientClassLoader);
                try {
                    appClienContainerGBean.setAttribute("mainClassName", mainClasss);
                    appClienContainerGBean.setAttribute("appClientModuleName", appClientModuleName);
                    appClienContainerGBean.setReferencePattern("JNDIContext", new ObjectName("geronimo.client:type=StaticJndiContext"));
                    appClienContainerGBean.setReferencePattern("TransactionContextManager", new ObjectName("geronimo.client:type=TransactionContextManager"));
                } catch (Exception e) {
                    throw new DeploymentException("Unable to initialize AppClientModule GBean", e);
                }
                appClientDeploymentContext.addGBean(appClienContainerName, appClienContainerGBean);
            } finally {
View Full Code Here

    private Kernel kernel;

    public void testLoad() throws Exception {
        ClassLoader cl = getClass().getClassLoader();
        ClassLoader myCl = new URLClassLoader(new URL[0], cl);
        GBeanMBean gbean = new GBeanMBean(MockGBean.getGBeanInfo(), myCl);
        gbean.setAttribute("name", "Test");
        gbean.setAttribute("finalInt", new Integer(123));
        kernel.loadGBean(name, gbean);
        kernel.startGBean(name);
        assertEquals(new Integer(State.RUNNING_INDEX), kernel.getMBeanServer().getAttribute(name, "state"));
        assertEquals("Hello", kernel.getMBeanServer().invoke(name, "doSomething", new Object[]{"Hello"}, new String[]{String.class.getName()}));
View Full Code Here

        kernel.stopGBean(name);
        kernel.unloadGBean(name);
    }

    public void testEndpoint() throws Exception {
        GBeanMBean gbean1 = new GBeanMBean(MockGBean.getGBeanInfo());
        gbean1.setAttribute("finalInt", new Integer(123));
        kernel.loadGBean(name, gbean1);
        kernel.startGBean(name);

        GBeanMBean gbean2 = new GBeanMBean(MockGBean.getGBeanInfo());
        gbean2.setAttribute("finalInt", new Integer(123));
        gbean2.setReferencePatterns("MockEndpoint", Collections.singleton(name));
        kernel.loadGBean(name2, gbean2);
        kernel.startGBean(name2);

        assertEquals("endpointCheck", kernel.getMBeanServer().invoke(name2, "checkEndpoint", null, null));
    }
View Full Code Here

    private MBeanServer mbServer;
    private byte[] state;
    private ObjectName gbeanName2;

    public void testOfflineConfig() throws Exception {
        GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO);
        config.setAttribute("ID", new URI("test"));
        config.setReferencePatterns("Parent", null);
    }
View Full Code Here

        config.setAttribute("ID", new URI("test"));
        config.setReferencePatterns("Parent", null);
    }

    public void testOnlineConfig() throws Exception {
        GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO);
        config.setAttribute("ID", new URI("test"));
        config.setReferencePatterns("Parent", null);
        config.setAttribute("classPath", Collections.EMPTY_LIST);
        config.setAttribute("gBeanState", state);
        config.setAttribute("dependencies", Collections.EMPTY_LIST);
        ConfigurationManager configurationManager = kernel.getConfigurationManager();
        ObjectName configName = configurationManager.load(config, null);
        mbServer.invoke(configName, "startRecursive", null, null);

        assertEquals(new Integer(State.RUNNING_INDEX), mbServer.getAttribute(configName, "state"));
View Full Code Here

TOP

Related Classes of org.apache.geronimo.gbean.jmx.GBeanMBean

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.