Beispiel #1
0
  public PluginRef unregPlugin(Plugin plugin) {
    try {
      if (plugin.getStatus() == PluginStatus.START) {
        plugin.stop();
      }
      if (plugin.getStatus() == PluginStatus.STOP) {
        plugin.destroy();
      }
    } catch (PluginException e) {
      _LOG.error(e.getLocalizedMessage());
    }

    synchronized (_plugins) {
      PluginRef ref = _plugins.get(plugin.getID());
      if (ref != null) {
        if (!ref.isUpdating()) {
          _plugins.remove(plugin.getID());
          ref.dispose();
        }
        removeDispatchSource(ref); //
        ref.setPlugin(null);
      }
      return ref;
    }
  }
Beispiel #2
0
 public PluginRef regPlugin(Plugin plugin) {
   if (plugin == null) return null;
   plugin.setID(newPluginID());
   try {
     plugin.init(this);
   } catch (Exception e) {
     _LOG.error(e.getMessage());
     return null; // TODO
   }
   // reg ref before start
   PluginRef ref = null;
   synchronized (_plugins) {
     ref = containRef(plugin);
     if (ref == null) {
       ref = new DefPluginRef(this, plugin.getName());
       _plugins.put(plugin.getID(), ref);
     }
   }
   ref.setPlugin(plugin);
   // handleAnnation
   regDispatch(ref);
   // set updating false
   if (ref.isUpdating()) ref.setUpdating(false);
   // start plugin
   try {
     plugin.start();
   } catch (PluginException e) {
     unregPlugin(plugin);
     _LOG.error("Plugin start error: " + plugin.getName() + e.getLocalizedMessage());
     return null;
   }
   return ref;
 }
 private Plugin getPluginByID(String id) {
   for (Plugin plugin : allPlugins.keySet()) {
     if (plugin.getID().equals(id)) {
       return plugin;
     }
   }
   throw new RuntimeException("Plugin not found by ID: " + id);
 }
 private Set<Plugin> getDependants(Plugin plugin) {
   Set<Plugin> res = new HashSet<>();
   for (Plugin pAll : allPlugins.keySet()) {
     for (String depID : pAll.getDepends()) {
       if (depID.equals(plugin.getID())) {
         res.add(pAll);
       }
     }
   }
   return res;
 }