我現在正在研究Opendaylight項目(一個由思科領導的開源SDN控制器項目),並發現該項目使用apache.felix.dm包中的資源動態管理equinox(OSGi框架)上的服務依賴項,在運行期間。apache.felix.dm包中的init()和start()方法有什麼區別?
爲了理解dm的機制,我已經跟蹤了apache.felix.dm包下的ComponentImpl.java中的代碼。我現在理解的是:
- DependencyManager將在滿足所有服務依賴關係後調用init()方法。
- start()方法將在init()方法後但在該類提供的服務正在OSGi框架中註冊之前調用。
寫入代碼調用機構(它們都位於ComponentImpl.java)提供如下:
的方法調用的init():
private void activateService(State state) {
String init;
synchronized (this) {
init = m_callbackInit;
}
// service activation logic, first we initialize the service instance itself
// meaning it is created if necessary and the bundle context is set
initService();
// now is the time to configure the service, meaning all required
// dependencies will be set and any callbacks called
configureService(state);
// flag that our instance has been created
m_isInstantiated = true;
// then we invoke the init callback so the service can further initialize
// itself
invoke(init);
// see if any of this caused further state changes
calculateStateChanges();
}
的方法來調用啓動():
private void bindService(State state) {
String start;
synchronized (this) {
start = m_callbackStart;
}
// configure service with extra-dependencies which might have been added from init() method.
configureServiceWithExtraDependencies(state);
// inform the state listeners we're starting
stateListenersStarting();
// invoke the start callback, since we're now ready to be used
invoke(start);
// start tracking optional services
startTrackingOptional(state);
// register the service in the framework's service registry
registerService();
// inform the state listeners we've started
stateListenersStarted();
}
現在我的問題是:什麼是()初始化之間的差異,start()方法?既然在服務註冊到OSGi框架之前它們都被調用,爲什麼它們需要分離? Thx對於任何想法,請告訴我,如果我的理解是不正確的。
此致
周杰倫
按照init的概念將它加載到類中,在調用完成後準備就緒,開始撥打電話 –
請原諒我,您能否更詳細地解釋您提到的「調用」?這就像「回撥」功能嗎? –