示例#1
0
 void shutdown() {
   if (plugins != null) {
     for (CRaSHPlugin<?> plugin : plugins) {
       plugin.destroy();
     }
   }
 }
示例#2
0
 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;
 }
示例#3
0
  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;
  }
    protected boolean isEnabled(CRaSHPlugin<?> plugin) {
      Assert.notNull(plugin, "Plugin must not be null");

      if (ObjectUtils.isEmpty(this.disabledPlugins)) {
        return true;
      }

      Set<Class<?>> pluginClasses = ClassUtils.getAllInterfacesAsSet(plugin);
      pluginClasses.add(plugin.getClass());

      for (Class<?> pluginClass : pluginClasses) {
        if (isEnabled(pluginClass)) {
          return true;
        }
      }
      return false;
    }