public synchronized <T> Iterable<T> getPlugins(Class<T> wantedType) { // Iterable<CRaSHPlugin<?>> plugins = getPlugins(); // List<T> tmp = Collections.emptyList(); // for (CRaSHPlugin<?> plugin : plugins) { Class<?> pluginType = plugin.getType(); if (wantedType.isAssignableFrom(pluginType)) { switch (plugin.status) { default: case CRaSHPlugin.FAILED: case CRaSHPlugin.INITIALIZED: // Do nothing break; case CRaSHPlugin.CONSTRUCTED: int status = CRaSHPlugin.FAILED; try { plugin.status = CRaSHPlugin.INITIALIZING; plugin.init(); log.info("Initialized plugin " + plugin); status = CRaSHPlugin.INITIALIZED; } catch (Exception e) { log.error("Could not initialize plugin " + plugin, e); } finally { plugin.status = status; } break; case CRaSHPlugin.INITIALIZING: throw new RuntimeException("Circular dependency"); } // if (plugin.status == CRaSHPlugin.INITIALIZED) { if (tmp.isEmpty()) { tmp = new ArrayList<T>(); } T t = wantedType.cast(plugin); tmp.add(t); } } } // return tmp; }
public synchronized Iterable<CRaSHPlugin<?>> getPlugins() { if (plugins == null) { List<CRaSHPlugin<?>> plugins = Utils.list(discovery.getPlugins()); for (CRaSHPlugin<?> plugin : plugins) { plugin.context = context; plugin.status = CRaSHPlugin.CONSTRUCTED; } this.plugins = plugins; } return plugins; }