Class方法:如果类型所在插件还没启动,启动它;如果正在启动, 则设置5000ms的超时,限时不能完成启动,则报错返回!
(附加说明:头一段时间在另外一篇随笔中,写了一些编写插件启动类应该注意的点,其中有一条就 是避免在插件启动方法中干耗时的事情。这里真正告诉我们了原因:如果超过5000ms不能完成启动--注 意这其中还不包含所依赖插件的启动时间,那么肯定会出现类加载超时的错误了:
While loading class "{1}", thread "{0}" timed out waiting ({4}ms) for thread "{2}" to finish starting bundle "{3}". To avoid deadlock, thread "{0}" is proceeding but "{1}" may not be fully initialized.
)
【EclipseLazyStarter是如何完成注册过程的?】
过程简要解释如下:
1、启动osgi framework,两种启动方式:如果想利用Eclipse的一些特性,则就以EclipseStarter为 入口点启动;否则,可以用命令行的方式,以Laucher.main为入口点启动
2、初始化FrameworkAdaptor(对应eclipse实现是BaseAdaptor)看一下接口说明:
/**
* FrameworkAdaptor interface to the osgi framework. This class is used to provide
* platform specific support for the osgi framework.
*
* <p>The OSGi framework will call this class to perform platform specific functions.
*
* Classes that implement FrameworkAdaptor MUST provide a constructor that takes as a
* parameter an array of Strings. This array will contain arguments to be
* handled by the FrameworkAdaptor. The FrameworkAdaptor implementation may define the format
* and content of its arguments.
*
* The constructor should parse the arguments passed to it and remember them.
* The initialize method should perform the actual processing of the adaptor
* arguments.
* <p>
* Clients may implement this interface.
* </p>
* @since 3.1
*/
Eclipse插件Lazy Start实现原理分析(4)
时间:2011-08-13 朱兴
显而易见,FrameworkAdaptor其实是osgi framework的****,提供平台附加支持。
看一下BaseAdaptor的构造函数:
1 /**
2 * Constructs a BaseAdaptor.
3 * @param args arguments passed to the adaptor by the framework.
4 */
5 public BaseAdaptor(String[] args) {
6 if (LocationManager.getConfigurationLocation() == null)
7 LocationManager.initializeLocations();
8 hookRegistry = new HookRegistry(this);
9 FrameworkLogEntry[] errors = hookRegistry.initialize();
10 if (errors.length > 0)
11 for (int i = 0; i < errors.length; i++)
12 getFrameworkLog().log(errors[i]);
13 // get the storage after the registry has been initialized
14 storage = getStorage();
15 // TODO consider passing args to BaseAdaptorHooks
16 }
我们看到,调用了HookRegistry.initialize进行初始化
3、初始化HookRegistry,我们直接看一下HookRegistry.initialize方法实现
1 /**
2 * Initializes the hook configurators. The following steps are used to initialize the hook configurators. <p>
3 * 1. Get a list of hook configurators from all hook configurators properties files on the classpath,
4 * add this list to the overall list of hook
|