Package com.sun.enterprise.module

Examples of com.sun.enterprise.module.Module


        }
    }

    @Override
    public Module find(Class clazz) {
        Module m = super.find(clazz);
        // all modules can load all classes
        if (m == null)
            return modules.get(0);
        return m;
    }
View Full Code Here


     * @return
     * @throws BootException
     */
    public ModuleStartup findStartupService(ModulesRegistry registry, Habitat habitat, String mainModuleName, StartupContext context) throws BootException {
        ModuleStartup startupCode=null;
        final Module mainModule;

        if(mainModuleName!=null) {
            // instantiate the main module, this is the entry point of the application
            // code. it is supposed to have 1 ModuleStartup implementation.
            Collection<Module> modules = registry.getModules(mainModuleName);
            if (modules.size() != 1) {
                if(registry.getModules().isEmpty())
                    throw new BootException("Registry has no module at all");
                else
                    throw new BootException("Cannot find main module " + mainModuleName+" : no such module");
            }
            mainModule = modules.iterator().next();
            String targetClassName = findModuleStartupClassName(mainModule,context.getPlatformMainServiceName(), HABITAT_NAME);
            if (targetClassName==null) {
                throw new BootException("Cannot find a ModuleStartup implementation in the META-INF/services/com.sun.enterprise.v3.ModuleStartup file, aborting");
            }

            Class<? extends ModuleStartup> targetClass=null;
            final ClassLoader currentCL =
                AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
                    @Override
                    public ClassLoader run() {
                        ClassLoader cl = Thread.currentThread().getContextClassLoader();
                        Thread.currentThread().setContextClassLoader(mainModule.getClassLoader());
                        return cl;
                    }
                });
            try {
                ClassLoader moduleClassLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
                    @Override
                    public ClassLoader run() {
                        return mainModule.getClassLoader();
                    }
                });
                targetClass = moduleClassLoader.loadClass(targetClassName).asSubclass(ModuleStartup.class);
                startupCode = habitat.getComponent(targetClass);
            } catch (ClassNotFoundException e) {
                throw new BootException("Unable to load component of type " + targetClassName,e);
            } catch (ComponentException e) {
                throw new BootException("Unable to load component of type " + targetClassName,e);
            } finally {
                AccessController.doPrivileged(new PrivilegedAction<Object>() {
                    @Override
                    public Object run() {
                        Thread.currentThread().setContextClassLoader(currentCL);
                        return null;
                    }
                });
            }
        } else {
            Collection<Inhabitant<? extends ModuleStartup>> startups = habitat.getInhabitants(ModuleStartup.class);

            if(startups.isEmpty())
                throw new BootException("No module has a ModuleStartup implementation");
            if(startups.size()>1) {
                // maybe the user specified a main
                String mainServiceName = context.getPlatformMainServiceName();
                for (Inhabitant<? extends ModuleStartup> startup : startups) {
                    Collection<String> regNames = Inhabitants.getNamesFor(startup, ModuleStartup.class.getName());
                    if (regNames.isEmpty() && mainServiceName==null) {
                        startupCode = startup.get();
                    } else {
                        for (String regName : regNames) {
                            if (regName.equals(mainServiceName)) {
                                startupCode = startup.get();
                            }
                        }
                    }

                }
                if (startupCode==null) {
                    if (mainServiceName==null) {
                        Iterator<Inhabitant<? extends ModuleStartup>> itr = startups.iterator();
                        ModuleStartup a = itr.next().get();
                        ModuleStartup b = itr.next().get();
                        Module am = registry.find(a.getClass());
                        Module bm = registry.find(b.getClass());
                        throw new BootException(String.format("Multiple ModuleStartup found: %s from %s and %s from %s",a,am,b,bm));
                    } else {
                        throw new BootException(String.format("Cannot find %s ModuleStartup", mainServiceName));
                    }
                }
View Full Code Here

                        }
                    }
                    if (itr.hasNext()) {
                        Inhabitant reason = itr.next();
                        StackTraceElement caller = stack[j];
                        Module m = null;
                        try {
                            if (reason.isInstantiated()) {
                                m = registry.find(loader.loadClass(reason.typeName()));
                            }
                        } catch (ClassNotFoundException e) {
                            m = null;
                        }
                        if (m!=null && !m.getModuleDefinition().getName().equals(currentBundleName)) {
                            w.append("Looks like module " + currentBundleName + " was " + state + " because "+
                                    m.getName() + " was " + state + "\nSince " + m.getName() + " contains ");
                        } else {
                            w.append("Requested by ");
                        }
                        if (m!=null)
                            currentBundleName = m.getName();

                        w.append(reason + " called from " + caller.getClassName()
                                + "." + caller.getMethodName() + ":" + caller.getLineNumber()+" metadata \n" + reason.metadata()+"\n");
                        w.append("\n");
View Full Code Here

    public Module makeModuleFor(String name, String version) throws ResolveError {
        return makeModuleFor(name, version, true);
    }

    public Module makeModuleFor(String name, String version, boolean resolve) throws ResolveError {
        Module module;
        Logger.getAnonymousLogger().fine("this.makeModuleFor("+name+ ", " +
                version + ", " + resolve + ") called.");
        if(parent!=null) {
            module = parent.makeModuleFor(name,version, resolve);
            if(module!=null)        return module;
        }

        module = modules.get(AbstractFactory.getInstance().createModuleId(name, version));
        if (module==null) {
            module = loadFromRepository(name, version);
            if (module!=null) {
                add(module);
            }
        }
        if (module!=null && resolve) {
            try {
                module.resolve();
            } catch(Throwable e) {
                module.uninstall();
                throw new ResolveError(e);
            }
        }
        Logger.getAnonymousLogger().fine("this.makeModuleFor("+name+ ", " + version + ") returned " + module);
        return module;
View Full Code Here

     * name or null if not found.
     * @throws ResolveError if the module dependencies cannot be resolved
     */
    public Module makeModuleFor(String packageName) throws ResolveError {
        if(parent!=null) {
            Module m = parent.makeModuleFor(packageName);
            if(m!=null)     return m;
        }

        for (Module module : modules.values()) {
            String[] exportedPkgs = module.getModuleDefinition().getPublicInterfaces();
View Full Code Here

        sortedKeys.addAll(keys);
        for (Integer key : sortedKeys) {
            Repository repo = repos.get(key);
            for (ModuleDefinition moduleDef : repo.findAll()) {
                if (modules.get(AbstractFactory.getInstance().createModuleId(moduleDef))==null) {
                    Module newModule = newModule(moduleDef);
                    if (newModule!=null) {
                        // When some module can't get installed,
                        // don't halt proceeding, instead continue
                        add(newModule);
                        // don't resolve such modules, we just want to know about them
View Full Code Here

        System.out.println("I have received changed event from " + service);       
        // house keeping...
        remove(service);
        ModuleDefinition info = service.getModuleDefinition();
       
        Module newService = newModule(info);
       
        // store it
        add(newService);
    }  
View Full Code Here

        return add(info, true);
    }

    public Module add(ModuleDefinition info, boolean resolve) throws ResolveError {
        // it may have already been created
        Module service = makeModuleFor(info.getName(), info.getVersion(), resolve);
        if (service!=null) {
        //    Utils.getDefaultLogger().info("Service " + info.getName()
        //       + " already registered");
        } else {
            // create the service instance
View Full Code Here

            try {
                Utility.setContextClassLoader(GlassFishORBManager.class.getClassLoader());

                if( processType.isServer()) {

                    Module corbaOrbModule = null;

                    // start glassfish-corba-orb bundle
                    ModulesRegistry modulesRegistry = habitat.getComponent(ModulesRegistry.class);

                    for(Module m : modulesRegistry.getModules()) {
                        if( m.getName().equals("glassfish-corba-orb") ) {
                            corbaOrbModule = m;
                            break;
                        }
                    }

                    if( corbaOrbModule != null) {
                        useOSGI = true;
                        corbaOrbModule.start();
                    }
                }
            } finally {
                Utility.setContextClassLoader(prevCL);
            }
View Full Code Here

    {
        final ModulesRegistry registry = InjectedValues.getInstance().getModulesRegistry();
        final Collection<Module> modules = registry.getModules("com.sun.enterprise.osgi-adapter");
        if (modules.size() == 1)
        {
            final Module mgmtAgentModule = modules.iterator().next();
            mgmtAgentModule.stop();
        }
        else
        {
            AMXLoggerInfo.getLogger().warning(AMXLoggerInfo.cantFindOSGIAdapter);
        }
View Full Code Here

TOP

Related Classes of com.sun.enterprise.module.Module

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.