Spark研究笔记8:重要的工厂类PluginManager(原创)
PluginManager 负责装载所有的插件和Workspaces。
私有域:
private final List<Plugin> plugins = new ArrayList<Plugin>();//Plugin接口 //PublicPlugin是注册的插件,字面含义是公开 private final List<PublicPlugin> publicPlugins = new CopyOnWriteArrayList<PublicPlugin>(); //单例管理器 private static PluginManager singleton; private static final Object LOCK = new Object(); //Plugins 目录下的文件 public static File PLUGINS_DIRECTORY = new File(Spark.getBinDirectory().getParent(), "plugins").getAbsoluteFile(); private Plugin pluginClass; private PluginClassLoader classLoader; //黑名单插件,也就是被禁用的插件 private Collection<String> _blacklistPlugins;
构造函数:
private PluginManager() { try { //定义PLUGINS_DIRECTORY PLUGINS_DIRECTORY = new File(Spark.getBinDirectory().getParentFile(), "plugins").getCanonicalFile(); } catch (IOException e) { Log.error(e); } // Do not use deployable plugins if not installed. if (System.getProperty("plugin") == null) { movePlugins(); } // Create the extension directory if one does not exist. if (!PLUGINS_DIRECTORY.exists()) { PLUGINS_DIRECTORY.mkdirs(); } _blacklistPlugins = Default.getPluginBlacklist(); //Default.getPluginBlacklist定义了插件黑名单,在default.properties里设置,用于禁用插件,第132行: # Put plugins here that you dont want enabled # comma separated, case insensitive # names of plugins can be found in the plugin.xml # example: Fastpath,Jingle Client,Phone Client,Window Flashing Plugin # default is empty PLUGIN_BLACKLIST = # Disable Plugins by entrypoint Class # Comma seperated, case sensitive # example org.jivesoftware.fastpath.FastpathPlugin # default is empty PLUGIN_BLACKLIST_CLASS = }
几个重要的方法
/** * 载入所有的插件(通过plugins.xml、lib) */ public void loadPlugins() { /** 载入已注册插件*/ private Plugin loadPublicPlugin(File pluginDir) { /** * 插件初始化*/ public void initializePlugins() { /** * 安装新插件*/ public void addPlugin(PublicPlugin plugin) throws Exception {
posted on 2013-04-27 17:52 CVT-wangxin 阅读(314) 评论(0) 编辑 收藏 举报