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; }
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; } }