我有一些應用程序,什麼叫一些jar庫,什麼叫Felix框架,並添加了一些捆綁軟件包的目錄。Felix - 如何正確地重新註冊捆綁更新服務?
「顯示幫助」 按鈕的代碼:
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
for (Bundle qqq : context.getBundles()) {
if ("ihtika2.I_AboutForm".equals(qqq.getSymbolicName())) {
System.out.println("I_AboutForm state: "+qqq.getState());
}
}
try {
ServiceReference[] refs = context.getServiceReferences(
AboutFormInterface.class.getName(), "(Funct=*)");
if (refs == null) {
System.out.println("Not Found AboutForm on show");
} else {
AboutFormInterface AboutForm = (AboutFormInterface) context.getService(refs[0]);
AboutForm.showWindow(context);
}
} catch (Exception ex) {
Ini.logger.fatal("Error on showing AboutForm", ex);
}
}
In first click (before update) service founded correctly.
The code of the "Update" button:
try {
ServiceReference[] refs = context.getServiceReferences(
UpdaterInt.class.getName(), "(Funct=*)");
if (refs == null) {
System.out.println("Not Found UpdaterInt on demand");
} else {
UpdaterInt UpdaterLocal = (UpdaterInt) context.getService(refs[0]);
UpdaterLocal.update();
}
} catch (Exception ex) {
Ini.logger.fatal("Error on showing AboutForm", ex);
}
更新程序的捆綁的代碼:
public void update() {
System.out.println("Stage 1");
int x = 0;
Map<String, Bundle> bundlesList = new HashMap<String, Bundle>();
for (Bundle singleBundle : context.getBundles()) {
bundlesList.put(singleBundle.getLocation(), singleBundle);
System.out.println(singleBundle.getLocation());
}
System.out.println("+++++++++++++++++++++++++++++");
Map<String, Bundle> treeMap = new TreeMap<String, Bundle>(bundlesList);
for (String str : treeMap.keySet()) {
Bundle singleBundle = treeMap.get(str);
System.out.println(str + " " + singleBundle.getSymbolicName());
if (!"khartn.Updater".equals(singleBundle.getSymbolicName())
&& !"org.apache.felix.framework".equals(singleBundle.getSymbolicName())) {
try {
System.out.println("state0 " + singleBundle.getState());
singleBundle.stop();
System.out.println("state1 " + singleBundle.getState());
singleBundle.update();
System.out.println("state1.1 " + singleBundle.getState());
singleBundle.start();
synchronized (this) {
try {
this.wait(250);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
System.out.println("state2 " + singleBundle.getState());
} catch (BundleException ex) {
ex.printStackTrace();
}
System.out.println("***");
}
}
}
在更新主JFrame的更新正確的 - 它牆根和所示。 但第二次單擊「顯示幫助」時,Felix找不到「顯示幫助」的服務。 「顯示幫助」服務的註冊代碼:
package ihtika2.i_aboutform;
import ihtika2.i_aboutform.service.AboutForm;
import ihtika2.i_aboutform.service.AboutFormInterface;
import java.util.Hashtable;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
public class Activator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
Hashtable<String, String> props = new Hashtable<String, String>();
props.put("Funct", "AboutForm");
System.out.println("Registering I_AboutForm");
context.registerService(AboutFormInterface.class.getName(), new AboutForm(), props);
}
@Override
public void stop(BundleContext context) throws Exception {
}
}
串上更新「註冊I_AboutForm」顯示。
爲什麼Felix找不到重新註冊的服務?