List of usage examples for java.lang Module getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:bioLockJ.AppController.java
public static Module getModule(final String name) throws Exception { for (final Module m : Config.getModules()) { if (m.getClass().getName().equals(name)) { return m; }//from w ww . j a v a 2 s. c om } return null; }
From source file:geva.Main.AbstractRun.java
/** * helper method for getting the StatisticsCollectionOperation * @return Collector collector module//from ww w .jav a2s. c om **/ protected Collector getCollector() { if (((AbstractAlgorithm) this.getAlgorithm()).getLoopPipeline() != null) { Collection<Module> m = ((AbstractAlgorithm) this.getAlgorithm()).getLoopPipeline().getModules(); Iterator<Module> iM = m.iterator(); Module mo; while (iM.hasNext()) { mo = iM.next(); if (mo.getClass().getName().equals(Collector.class.getName())) { if (((Collector) mo).getOperation() instanceof StatisticsCollectionOperation) { return (Collector) mo; } } } } return null; }
From source file:org.obiba.onyx.engine.ModuleRegistrationListener.java
@SuppressWarnings("unchecked") public void startup(WebApplication application) { Map<String, Module> modules = applicationContext.getBeansOfType(Module.class); Stage conclusionStage = null;/*w w w . j av a2 s . c om*/ if (modules != null) { boolean finalStageFound = false; for (Module module : modules.values()) { // check there is one and only one conclusion stage defined for (Stage stage : module.getStages()) { if (stage.isInterviewConclusion()) { if (!finalStageFound) { stage.setStageDependencyCondition(new FinalDependencyCondition(registry)); finalStageFound = true; conclusionStage = stage; } else { throw new IllegalArgumentException( "Several interview conclusion stages is not allowed."); } } } try { log.info("Initializing module '{}' of type {}", module.getName(), module.getClass().getSimpleName()); module.initialize(application); } catch (RuntimeException e) { log.error("Could not initialize module '{}'", module.getName()); log.error("Module initialisation failed due to the following exception.", e); // Try to register the other modules anyway continue; } try { registry.registerModule(module); } catch (RuntimeException e) { try { module.shutdown(application); } catch (RuntimeException ignored) { } } } if (!finalStageFound) { throw new IllegalArgumentException( "An interview conclusion stage is required. Add <interviewConclusion>true</interviewConclusion> to the conclusion stage configuration file."); } if (existsDependenciesOnConclusion(modules, conclusionStage)) throw new IllegalArgumentException( "A StageDependencyCondition based on the conclusion was found on another stage. Please remove the StageDependencyCondition: no stage should depend on the conclusion"); } }
From source file:com.manydesigns.portofino.modules.ModuleRegistry.java
public void migrateAndInit(ServletContext servletContext) { for (Module module : modules) { int migrationVersion = module.getMigrationVersion(); String key = "module." + module.getId() + ".migration.version"; int installedVersion = configuration.getInt(key, -1); boolean migrationOk = true; Injections.inject(module, servletContext, null); if (installedVersion == -1) try { //Install logger.info("Installing module " + printModule(module) + "..."); installedVersion = module.install(); configuration.setProperty(key, installedVersion); configuration.save();/*from w ww . j a v a 2 s . com*/ logger.info("Installed module " + printModule(module)); } catch (Throwable e) { logger.error("Could not install module " + printModule(module), e); migrationOk = false; } try { //Migrate while (installedVersion < migrationVersion) { logger.info("Migrating module " + printModule(module) + " from version " + installedVersion + "..."); Method method = module.getClass().getMethod("migrateFrom" + installedVersion); if (!Integer.TYPE.equals(method.getReturnType())) { throw new RuntimeException("Migration method " + method + " does not return int"); } Integer result = (Integer) method.invoke(module); if (result > installedVersion) { installedVersion = result; configuration.setProperty(key, result); configuration.save(); logger.info("Migrated module " + printModule(module)); } else { throw new RuntimeException("Migration returned version " + result + " while the installed one is " + installedVersion); } } } catch (Throwable e) { logger.error( "Could not migrate module " + printModule(module) + " from version " + installedVersion, e); migrationOk = false; } if (migrationOk) { //Init (skip if installation or migration failed) try { logger.debug("Initializing module " + printModule(module) + "..."); module.init(); logger.info("Initialized module " + printModule(module)); } catch (Throwable e) { logger.error("Could not initialize module " + printModule(module), e); } } } }
From source file:org.pentaho.reporting.libraries.base.boot.PackageManager.java
/** * Tries to load a given module and all dependent modules. If the dependency check fails for that module (or for one * of the dependent modules), the loaded modules are discarded and no action is taken. * * @param moduleInfo the module info of the module that should be loaded. * @param incompleteModules a list of incompletly loaded modules. This are module specifications which depend on the * current module and wait for the module to be completly loaded. * @param modules the list of previously loaded modules for this module. * @param fatal a flag that states, whether the failure of loading a module should be considered an error. * Root-modules load errors are never fatal, as we try to load all known modules, regardless * whether they are active or not. * @return true, if the module was loaded successfully, false otherwise. *///from w w w . ja v a 2 s .c o m private boolean loadModule(final ModuleInfo moduleInfo, final ArrayList<Module> incompleteModules, final ArrayList<Module> modules, final boolean fatal) { try { final Module module = ObjectUtilities.loadAndInstantiate(moduleInfo.getModuleClass(), booter.getClass(), Module.class); if (module == null) { if (fatal) { LOGGER.warn("Unresolved dependency for package: " + moduleInfo.getModuleClass()); } LOGGER.debug("Module class referenced, but not in classpath: " + moduleInfo.getModuleClass()); return false; } if (acceptVersion(moduleInfo, module) == false) { // module conflict! LOGGER.warn("Module " + module.getName() + ": required version: " + moduleInfo + ", but found Version: \n" + module); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } final int moduleContained = containsModule(modules, module); if (moduleContained == RETURN_MODULE_ERROR) { // the module caused harm before ... LOGGER.debug("Indicated failure for module: " + module.getModuleClass()); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } else if (moduleContained == RETURN_MODULE_UNKNOWN) { if (incompleteModules.contains(module)) { // we assume that loading will continue ... LOGGER.error( "Circular module reference: This module definition is invalid: " + module.getClass()); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } incompleteModules.add(module); final ModuleInfo[] required = module.getRequiredModules(); for (int i = 0; i < required.length; i++) { if (loadModule(required[i], incompleteModules, modules, true) == false) { LOGGER.debug("Indicated failure for module: " + module.getModuleClass()); final PackageState state = new PackageState(module, PackageState.STATE_ERROR); dropFailedModule(state); return false; } } final ModuleInfo[] optional = module.getOptionalModules(); for (int i = 0; i < optional.length; i++) { if (loadModule(optional[i], incompleteModules, modules, true) == false) { LOGGER.debug("Optional module: " + optional[i].getModuleClass() + " was not loaded."); } } // maybe a dependent module defined the same base module ... if (containsModule(modules, module) == RETURN_MODULE_UNKNOWN) { modules.add(module); } incompleteModules.remove(module); } return true; } catch (Exception e) { LOGGER.warn("Exception while loading module: " + moduleInfo, e); return false; } }
From source file:org.wandora.modules.ModuleManager.java
/** * Finds a module that is of the specified class or one extending it. * Typically you look for modules with an interface and will then get a module * that implements the interface. This method takes the name of the module * requested. No other module will be returned except the module named such. * /*from w w w .j ava 2s . c o m*/ * @param context The module which is requesting the module. This may affect * what module is returned. * @param instanceName The instance name of the requested module. * @param cls The class or interface that the module has to implement or extend or * be a direct instance of. * @return The module found or null if no such module exists. * @return */ public synchronized <A extends Module> A findModule(Module context, String instanceName, Class<A> cls) { A ret = null; int best = -1; // do not select automatically anything with a lower priority than 0 if (instanceName != null) best = Integer.MIN_VALUE; // but with a specified name do for (Module m : modules) { if (context != null && m == context) continue; if (cls.isAssignableFrom(m.getClass())) { String name = getModuleName(m); if (instanceName == null || (name != null && instanceName.equals(name))) { ModuleSettings settings = getModuleSettings(m); if (settings.servicePriority > best) { best = settings.servicePriority; ret = (A) m; } } } } return ret; }
From source file:org.wandora.modules.ModuleManager.java
/** * Finds all modules that are of the specified class or one extending it. * @param cls The class or interface that the module has to implement or extend or * be a direct instance of./*from www .j a v a 2 s . c om*/ * @return The found modules or an empty list if no such modules exist. */ public synchronized <A extends Module> ArrayList<A> findModules(Class<A> cls) { ArrayList<A> ret = new ArrayList<A>(); for (Module m : modules) { if (cls.isAssignableFrom(m.getClass())) { ret.add((A) m); } } Collections.sort(ret, new Comparator<A>() { @Override public int compare(A o1, A o2) { ModuleSettings s1 = getModuleSettings(o1); ModuleSettings s2 = getModuleSettings(o2); return s2.servicePriority - s1.servicePriority; } }); return ret; }
From source file:org.wandora.modules.ModuleManager.java
/** * Creates a string representation of a module. Mostly intended for * debugging and logging./*w w w . j a v a 2 s . c o m*/ * * @param module The module. * @return */ public String moduleToString(Module module) { String name = getModuleName(module); return module.getClass().getSimpleName() + (name == null ? "" : "(" + name + ")"); }
From source file:org.wandora.modules.ModuleManager.java
/** * Starts a module. If any dependencies haven't yet been started, will throw * a MissingDependencyException. use startModuleWithDependencies to * automatically start all dependencies as well. * // w ww .j a v a2 s .c o m * @param module The module to be started. * @throws ModuleException */ public synchronized void startModule(Module module) throws ModuleException { if (!module.isInitialized()) module.init(this, moduleParams.get(module)); if (module.isRunning()) return; Collection<Module> deps = module.getDependencies(this); for (Module dep : deps) { if (!dep.isRunning()) throw new MissingDependencyException(dep.getClass(), getModuleName(dep)); } if (log != null) log.info("Starting module " + moduleToString(module)); moduleListeners.fireEvent("moduleStarting", module); module.start(this); if (module.isRunning()) { moduleListeners.fireEvent("moduleStarted", module); for (Module dep : deps) { ArrayList<Module> l = isRequiredBy.get(dep); if (l == null) { l = new ArrayList<Module>(); isRequiredBy.put(dep, l); } l.add(module); } } else { if (log != null) log.warn("Started module but isRunning is false " + moduleToString(module)); } }
From source file:uniol.apt.module.AptModuleRegistry.java
private AptModuleRegistry() { super();/* w w w . j a va 2 s .co m*/ for (Module module : ServiceLoader.load(Module.class, getClass().getClassLoader())) { String moduleName = module.getClass().getCanonicalName(); String name = module.getName(); if (name == null || name.equals("") || !name.equals(name.toLowerCase())) { throw new RuntimeException( String.format("Module %s reports an invalid name: %s", moduleName, name)); } Module oldModule = findModule(name); if (oldModule != null && !oldModule.getClass().equals(module.getClass())) { throw new RuntimeException(String.format("Different modules claim, to have name %s:" + " %s and %s", name, oldModule.getClass().getCanonicalName(), moduleName)); } registerModule(module); } }