OSGI: Service not available after Bundle update -


i have bundle p(rovider= implements interface defined in bundle i(interface) bundle u(ser) should use service. after started application works fine, service can used. when update bundle p, non of service can resolved.

the update method looks this:

this._bundle.stop(); this._bundle.update(new fileinputstream(updatefile)); this._bundle.start(); 

this bundleactivator of packages should handle serviceregistrations , servicereferences:

public abstract class bundleactivator implements org.osgi.framework.bundleactivator, bundlelistener, servicelistener { /**  * bundle context.  */ protected bundlecontext context;  /**  * services registered bundle.  */ protected hashset<serviceregistration> serviceregistrations = new hashset<serviceregistration>();  /**  * service references used bundle.  */ protected hashmap<string, servicereference> servicereferences = new hashmap<string, servicereference>();  /**  * perform method after bundle has started.  *  * @param bc bundlecontext.  */ protected abstract void afterstart(bundlecontext bc);  /**  * perform method before bundle going stoped.  *  * @param bc bundlecontext.  */ protected abstract void beforestop(bundlecontext bc);  /**  * perform method after bundle has changed.  *  * @param bundleevent  */ protected abstract void afterbundlechanged(bundleevent be);  /**  * returns bundle context bundle.  *  * @return bundle context  */ public bundlecontext getcontext() {     return this.context; }  /**  * registeres service.  *  * @param clazz      interface  * @param service    service  * @param properties properties  *  * @return service registration  */ public serviceregistration registerservice(class clazz, object service, dictionary<string, ?> properties) {     return this.registerservice(clazz.getcanonicalname(), service, properties); }  /**  * registeres service.  *  * @param clazz      interface  * @param service    service  * @param properties properties  *  * @return service registration  */ public serviceregistration registerservice(string clazz, object service, dictionary<string, ?> properties) {     serviceregistration retval = this.context.registerservice(clazz, service, properties);     system.out.println("registered service: " + retval.tostring() + " " + clazz);     this.serviceregistrations.add(retval);     return retval; }  /**  * returns registered service.  *  * @param clazz interface  *  * @return service instance  */ public object getservice(class clazz) {     if (clazz == null) {         return null;     }     return this.getservice(clazz.getcanonicalname()); }  /**  * returns registered service.  *  * @param clazz interface  *  * @return service instance  */ public object getservice(string clazz) {     if (clazz == null) {         return null;     }     system.out.println("class: " + clazz);     servicereference sr = this.context.getservicereference(clazz);     system.out.println("sr: " + sr);     if (sr == null) {         if (this.servicereferences.containskey(clazz)) {             system.out.println("unget service");             this.context.ungetservice(this.servicereferences.get(clazz));             this.servicereferences.remove(clazz);         }         sr = this.context.getservicereference(clazz);         system.out.println("sr: " + sr);         if (sr == null) {             return null;         }     }      try {         this.context.addservicelistener(this, "(objectclass=" + clazz + ")");     } catch (invalidsyntaxexception ex) {         logger.getlogger(bundleactivator.class.getname()).log(level.severe, null, ex);     }      this.servicereferences.put(clazz, sr);     return this.context.getservice(sr); }  @override public void start(bundlecontext bc) throws exception {     contextregistry.getinstance().add(bc);      this.context = bc;     this.context.addbundlelistener(this);     this.afterstart(bc);     system.out.println("balindoo bundle activated: " + this.getclass().getpackage().getname()); }  @override public void stop(bundlecontext bc) throws exception {     this.beforestop(bc);      (serviceregistration sr : this.serviceregistrations) {         this.context.ungetservice(sr.getreference());         sr.unregister();     }     this.serviceregistrations.clear();      (servicereference sr : this.servicereferences.values()) {         this.context.ungetservice(sr);     }     this.servicereferences.clear();      contextregistry.getinstance().remove(bc);     this.context.removebundlelistener(this);     this.context = null;     system.out.println("balindoo bundle deactivated: " + this.getclass().getpackage().getname()); }  @override public void bundlechanged(bundleevent be) {     string name = be.getbundle().getsymbolicname();     if (name.startswith("com.vaadin")) {         if (be.gettype() == bundleevent.started && !resourceprovider.getinstance().hasbundle(be.getbundle())) {             resourceprovider.getinstance().add(be.getbundle());         } else if (be.gettype() == bundleevent.stopped && resourceprovider.getinstance().hasbundle(be.getbundle())) {             resourceprovider.getinstance().remove(be.getbundle());         }     }      (servicereference sr : this.servicereferences.values()) {         this.context.ungetservice(sr);     }     this.servicereferences.clear();      hashset<bundle> thisbundle = new hashset<>();     thisbundle.add(this.context.getbundle());     thisbundle.add(be.getbundle());      frameworkwiring wiring = this.context.getbundle().adapt(frameworkwiring.class);     if (wiring != null) {         system.out.println("frameworkwiring:\n\tthis:\t" + this.context.getbundle().getsymbolicname() + "\n\tto  :\t" + be.getbundle().getsymbolicname());         wiring.refreshbundles(thisbundle);     }      this.afterbundlechanged(be); }  @override public void servicechanged(serviceevent event) {     switch (event.gettype()) {         case serviceevent.unregistering:             system.out.println("unregister service");             if (this.servicereferences.containsvalue(event.getservicereference())) {                 //remove             }             this.context.ungetservice(event.getservicereference());             break;     } } 

as can see, tried lot resolve problem, nothing worked. doing wrong?

here manifest bundle p (org.company.example.data). interface located in org.company.example.data.api in separate bundle.

manifest-version: 1.0 bnd-lastmodified: 1381157007428 build-jdk: 1.7.0_21 built-by: nspecht bundle-activator: org.company.example.data.impl.bundleactivator bundle-description: example bundle org.company.example.data 1.0.0 bundle-manifestversion: 2 bundle-name: org.company.example.data bundle-requiredexecutionenvironment: javase-1.7 bundle-symbolicname: org.company.org.company.example.data bundle-vendor: company inc. bundle-version: 1.0.0 created-by: apache maven bundle plugin eclipse-buddypolicy: registered eclipse-registerbuddy: org.company.wrapper.hibernate export-package: org.company.example.data.api;uses:="org.company.example.data.api.model";version="1.0.0",org.company.example.data.impl;uses:="org.company.example.data.api,org.company.utils.data.database,org.osgi.framework,org.company.example.data.api.model,org.company.utils.modulemanager.generic,org.hibernate,org.hibernate.criterion";version="1.0.0",org.company.example.data;version="1.0.0",org.company.example.data.api.impl;uses:="org.osgi.framework,org.company.utils.modulemanager.generic";version="1.0.0",org.company.example.data.api.model;uses:="org.company.utils.data.api";version="1.0.0",org.company.example.data.i18n;version="1.0.0" import-package: org.company.utils.data.api;version="[1.0,2)",org.company.utils.data.database;version="[1.0,2)",org.company.utils.modulemanager.generic;version="[1.0,2)",org.hibernate;version="4.2,5)",org.hibernate.criterion;version="4.2,5)",org.osgi.framework;version="[1.6,2)" tool: bnd-1.50.0 

the manifest interface bundle:

manifest-version: 1.0 bnd-lastmodified: 1381156992131 build-jdk: 1.7.0_21 built-by: nspecht bundle-activator: org.company.example.data.api.impl.bundleactivator bundle-description: example bundle org.company.example.data.api 1.0.0 bundle-manifestversion: 2 bundle-name: org.company.example.data.api bundle-requiredexecutionenvironment: javase-1.7 bundle-symbolicname: org.company.org.company.example.data.api bundle-vendor: company inc. bundle-version: 1.0.0 created-by: apache maven bundle plugin eclipse-buddypolicy: registered export-package: org.company.example.data.api;uses:="org.company.example.data.api.model";version="1.0.0",org.company.example.data.api.impl;uses:="org.osgi.framework,org.company.utils.modulemanager.generic";version="1.0.0",org.company.example.data.api.model;uses:="org.company.utils.data.api";version="1.0.0" import-package: org.company.utils.data.api;version="[1.0,2)",org.company.utils.modulemanager.generic;version="[1.0,2)",org.osgi.framework;version="[1.6,2)" tool: bnd-1.50.0 

at least interface bundle u:

manifest-version: 1.0 bnd-lastmodified: 1381157008373 build-jdk: 1.7.0_21 built-by: nspecht bundle-activator: org.company.example.webui.impl.bundleactivator bundle-description: example bundle org.company.example.webui 1.0.0 bundle-manifestversion: 2 bundle-name: org.company.example.webui bundle-requiredexecutionenvironment: javase-1.7 bundle-symbolicname: org.company.org.company.example.webui bundle-vendor: company inc. bundle-version: 1.0.0 created-by: apache maven bundle plugin eclipse-buddypolicy: registered export-package: org.company.example.webui.impl;uses:="org.company.utils.webui,org.company.example.data.api,org.company.example.webui.menu,org.osgi.framework,org.company.utils.webui.menu,org.company.example.webui.view,org.company.utils.modulemanager.generic,org.company.utils.modulemanager.exception";version="1.0.0",org.company.example.webui.menu;uses:="org.company.utils.webui,org.company.utils.webui.generics,org.company.utils.modulemanager.translation,org.company.example.webui.view,org.company.utils.webui.menu";version="1.0.0",org.company.example.webui.i18n;version="1.0.0",org.company.example.webui.view;uses:="org.company.example.data.api,com.vaadin.server,org.company.utils.modulemanager.translation,org.company.example.data.api.model,com.vaadin.ui,org.company.example.webui.impl,com.vaadin.event,org.company.utils.webui.exception,com.vaadin.data,com.vaadin.data.util,com.vaadin.navigator,org.company.utils.modulemanager.exception";version="1.0.0" import-package: com.vaadin.data;version="[7.1,8)",com.vaadin.data.util;version="[7.1,8)",com.vaadin.event;version="[7.1,8)",com.vaadin.navigator;version="[7.1,8)",com.vaadin.server;version="[7.1,8)",com.vaadin.ui;version="[7.1,8)",org.company.example.data.api;version="[1.0,2)",org.company.example.data.api.model;version="[1.0,2)",org.company.utils.modulemanager.exception;version="[1.0,2)",org.company.utils.modulemanager.generic;version="[1.0,2)",org.company.utils.modulemanager.translation;version="[1.0,2)",org.company.utils.webui;version="[1.0,2)",org.company.utils.webui.exception;version="[1.0,2)",org.company.utils.webui.generics;version="[1.0,2)",org.company.utils.webui.menu;version="[1.0,2)",org.osgi.framework;version="[1.6,2)" tool: bnd-1.50.0 

check exporting package containing service interface i. both p , u must wired same package. in order ensure u can use service object, framework verifies u wired same package p.

it appears after updating p, new p' wired different revision of package u. when p' registers service, comes different revision of package.

this can occur if package contained in p , exported p without having p import same package. service provider should both export , import service interface package. see http://blog.osgi.org/2007/04/importance-of-exporting-nd-importing.html


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

html - Repeat image to extend header to fill screen -

javascript - Backbone.js getting target attribute -