|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
Usage of Architecture service and access of propertiesHi!
Given that I have a sample class: @Component(architecture=true, immediate = true, propagation = true, managedservice = "org.client.ClientServiceImpl") @Provides public class ClientServiceImpl implements ClientService { @ServiceProperty(name="system.property", value="value1") private String systemProperty; @Property(name="application.property", value="value2") private String applicationProperty; @Requires private Architecture architecture; @Validate public void start() { } @Invalidate public void stop() { } } How can I access the values of systemProperty and applicationProperty inside start() method? Thanks! Vlatko |
|
|
Two bundles with the same package.Hello,
I have found that having the same package in two bundles, where one depends on the other causes a problem. This is ok if the bundles are independent, but if the same package appears in more than one bundle, only one bundle will work. When I attempt to load the second bundle I get the following error. However if the second bundle uses a different package, there is no problem. I don't know if this should be an error or not but it could be handled better, either by reporting the true error or not reporting an error and working. One think I found confusing was the message "Cannot create a POJO instance, the POJO constructor invocation has thrown an exception : null" which indicates that the constructor was called but threw an unknown exception. Neither the constructor nor the static block for the class is called. See attached for an example. 10:08:26,384 | ERROR | Thread-29 | SamePackage Two | ? ? | [ERROR] SampleImplementation : [SampleImplementationA] Class not found during the loading phase : samepackage.SampleImplementation 10:08:26,385 | ERROR | Thread-29 | SamePackage Two | ? ? | [ERROR] SampleImplementation : [SampleImplementationA] createInstance -> The POJO constructor invocation failed : null 10:08:26,387 | ERROR | Thread-29 | SamePackage Two | ? ? | [ERROR] SampleImplementation : Cannot create a POJO instance, the POJO constructor invocation has thrown an exception : null java.lang.RuntimeException: Cannot create a POJO instance, the POJO constructor invocation has thrown an exception : null at org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java :639) at org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.jav a:776) at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand ler.__stateChanged(LifecycleCallbackHandler.java:156) at org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand ler.stateChanged(LifecycleCallbackHandler.java) at org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:440 ) at org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:321) at org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory. java:155) at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory .java:298) at org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory .java:235) at org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCr eator.java:360) at org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java: 89) at org.apache.felix.ipojo.Extender.parse(Extender.java:269) at org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:208) at org.apache.felix.ipojo.Extender.access$600(Extender.java:52) at org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:669) at java.lang.Thread.run(Thread.java:619) 10:08:26,387 | ERROR | Thread-29 | SamePackage Two | ? ? | [ERROR] SampleImplementation : Cannot create a POJO instance, the POJO constructor invocation has thrown an exception : null 10:08:26,388 | ERROR | Thread-29 | ipojo | ? ? | [ERROR] iPOJO Instance Creator : A matching factory was found for {component=SampleImplementation, instance.name=SampleImplementationA}, but the instantiation failed : The configuration is not correct for the type SampleImplementation : Cannot create a POJO instance, the POJO constructor invocation has thrown an exception : null --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Usage of Architecture service and access of propertiesHi,
On 03.11.2009, at 21:11, Vlatko Davidovski wrote: > Hi! > > Given that I have a sample class: > > @Component(architecture=true, immediate = true, propagation = true, > managedservice = "org.client.ClientServiceImpl") > @Provides > public class ClientServiceImpl implements ClientService { > > @ServiceProperty(name="system.property", value="value1") > private String systemProperty; > > @Property(name="application.property", value="value2") > private String applicationProperty; > > @Requires > private Architecture architecture; > > > @Validate > public void start() { > > } > > @Invalidate > public void stop() { > > } > > } You can access the properties just by using the fields (systemProperty and applicationProperty). About architecture, this code does not inject your Architecture service, but get one from the service registry (should be the one with the lower service id). If you want your architecture you have to filter the requirement with an LDAP filter like: filter = "(architecture.instance =org.apache.felix.ipojo.sample.MyComponentImpl-0)" Regards, Clement > > How can I access the values of systemProperty and > applicationProperty inside start() method? > > Thanks! > Vlatko |
|
|
Re: Two bundles with the same package.On 11/4/09 4:18, peter lawrey wrote: > Hello, > I have found that having the same package in two bundles, where one > depends on the other causes a problem. This is ok if the bundles are > independent, but if the same package appears in more than one bundle, > only one bundle will work. > You are creating a split package (i.e., a package spanning multiple bundles) then exporting/importing this package from both bundles. This sort of thing is specifically not allowed by OSGi, so this is just an error in your bundles. If you import a package from another bundle, it will completely shadow an internal package of the same name. See the OSGi spec on class search order. Imports are searched before the bundle class path and they are terminal. By both importing and exporting the package, you are giving the OSGi framework the choice to treat the bundle as an importer or an exporter (in this case the "or" is "xor"). So, in your scenario, most likely one of your bundles is being selected as an exporter and the other is being selected as an importer. Moral to the story, don't use split packages. -> richard > When I attempt to load the second bundle I get the following error. > However if the second bundle uses a different package, there is no > problem. > I don't know if this should be an error or not but it could be handled > better, either by reporting the true error or not reporting an error and > working. > One think I found confusing was the message "Cannot create a POJO > instance, the POJO constructor invocation has thrown an exception : > null" which indicates that the constructor was called but threw an > unknown exception. Neither the constructor nor the static block for the > class is called. > > See attached for an example. > > 10:08:26,384 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > [SampleImplementationA] Class not found during the loading phase : > samepackage.SampleImplementation > 10:08:26,385 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > [SampleImplementationA] createInstance -> The POJO constructor > invocation failed : null > 10:08:26,387 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > Cannot create a POJO instance, the POJO constructor invocation has > thrown an exception : null > java.lang.RuntimeException: Cannot create a POJO instance, the POJO > constructor invocation has thrown an exception : null > at > org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java > :639) > at > org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.jav > a:776) > at > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > ler.__stateChanged(LifecycleCallbackHandler.java:156) > at > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > ler.stateChanged(LifecycleCallbackHandler.java) > at > org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:440 > ) > at > org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:321) > at > org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory. > java:155) > at > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > .java:298) > at > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > .java:235) > at > org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCr > eator.java:360) > at > org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java: > 89) > at org.apache.felix.ipojo.Extender.parse(Extender.java:269) > at > org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:208) > at org.apache.felix.ipojo.Extender.access$600(Extender.java:52) > at > org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:669) > at java.lang.Thread.run(Thread.java:619) > 10:08:26,387 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > Cannot create a POJO instance, the POJO constructor invocation has > thrown an exception : null > 10:08:26,388 | ERROR | Thread-29 | ipojo > | ? ? | [ERROR] iPOJO Instance Creator > : A matching factory was found for {component=SampleImplementation, > instance.name=SampleImplementationA}, but the instantiation failed : The > configuration is not correct for the type SampleImplementation : Cannot > create a POJO instance, the POJO constructor invocation has thrown an > exception : null > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Usage of Architecture service and access of propertiesThanks for your response Clement.
Basically what I would like to do, is to have a possibility to programmatically get all @ServiceProperty by their name (name="system.property") and in such a way have a method for example: public String getProperty(String name) that will return me the value for this property. Of course I can manually access each field. But I would like to automate this, as I might have a lot of these fields. On the other side I can use reflection, but then it is more complicated to get the actual name of the property rather than the field name. Vlatko On Nov 4, 2009, at 11:27 AM, Clement Escoffier wrote: > Hi, > > On 03.11.2009, at 21:11, Vlatko Davidovski wrote: > >> Hi! >> >> Given that I have a sample class: >> >> @Component(architecture=true, immediate = true, propagation = true, >> managedservice = "org.client.ClientServiceImpl") >> @Provides >> public class ClientServiceImpl implements ClientService { >> >> @ServiceProperty(name="system.property", value="value1") >> private String systemProperty; >> >> @Property(name="application.property", value="value2") >> private String applicationProperty; >> >> @Requires >> private Architecture architecture; >> >> >> @Validate >> public void start() { >> >> } >> >> @Invalidate >> public void stop() { >> >> } >> >> } > > You can access the properties just by using the fields > (systemProperty and applicationProperty). > > > About architecture, this code does not inject your Architecture > service, but get one from the service registry (should be the one > with the lower service id). If you want your architecture you have > to filter the requirement with an LDAP filter like: > filter > = > "(architecture > .instance=org.apache.felix.ipojo.sample.MyComponentImpl-0)" > > Regards, > > Clement > >> >> How can I access the values of systemProperty and >> applicationProperty inside start() method? >> >> Thanks! >> Vlatko > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: Two bundles with the same package.Hello Richard,
Thank you for clarifying this. Perhaps the error message can be improved, in situations which work under Java but not OSGi. esp. if you are migrating an existing application which works. ;) Kind Regards, Peter. -----Original Message----- From: Richard S. Hall [mailto:heavy@...] Sent: 04 November 2009 15:24 To: users@... Subject: Re: Two bundles with the same package. On 11/4/09 4:18, peter lawrey wrote: > Hello, > I have found that having the same package in two bundles, where one > depends on the other causes a problem. This is ok if the bundles are > independent, but if the same package appears in more than one bundle, > only one bundle will work. > You are creating a split package (i.e., a package spanning multiple bundles) then exporting/importing this package from both bundles. This sort of thing is specifically not allowed by OSGi, so this is just an error in your bundles. If you import a package from another bundle, it will completely shadow an internal package of the same name. See the OSGi spec on class search order. Imports are searched before the bundle class path and they are terminal. By both importing and exporting the package, you are giving the OSGi framework the choice to treat the bundle as an importer or an exporter (in this case the "or" is "xor"). So, in your scenario, most likely one of your bundles is being selected as an exporter and the other is being selected as an importer. Moral to the story, don't use split packages. -> richard > When I attempt to load the second bundle I get the following error. > However if the second bundle uses a different package, there is no > problem. > I don't know if this should be an error or not but it could be handled > better, either by reporting the true error or not reporting an error and > working. > One think I found confusing was the message "Cannot create a POJO > instance, the POJO constructor invocation has thrown an exception : > null" which indicates that the constructor was called but threw an > unknown exception. Neither the constructor nor the static block for the > class is called. > > See attached for an example. > > 10:08:26,384 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > [SampleImplementationA] Class not found during the loading phase : > samepackage.SampleImplementation > 10:08:26,385 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > [SampleImplementationA] createInstance -> The POJO constructor > invocation failed : null > 10:08:26,387 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > Cannot create a POJO instance, the POJO constructor invocation has > thrown an exception : null > java.lang.RuntimeException: Cannot create a POJO instance, the POJO > constructor invocation has thrown an exception : null > at > org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java > :639) > at > org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.jav > a:776) > at > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > ler.__stateChanged(LifecycleCallbackHandler.java:156) > at > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > ler.stateChanged(LifecycleCallbackHandler.java) > at > org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:440 > ) > at > org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:321) > at > org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory. > java:155) > at > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > .java:298) > at > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > .java:235) > at > org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCr > eator.java:360) > at > org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java: > 89) > at org.apache.felix.ipojo.Extender.parse(Extender.java:269) > at > org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:208) > at org.apache.felix.ipojo.Extender.access$600(Extender.java:52) > at > org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:669) > at java.lang.Thread.run(Thread.java:619) > 10:08:26,387 | ERROR | Thread-29 | SamePackage Two > | ? ? | [ERROR] SampleImplementation : > Cannot create a POJO instance, the POJO constructor invocation has > thrown an exception : null > 10:08:26,388 | ERROR | Thread-29 | ipojo > | ? ? | [ERROR] iPOJO Instance Creator > : A matching factory was found for {component=SampleImplementation, > instance.name=SampleImplementationA}, but the instantiation failed : The > configuration is not correct for the type SampleImplementation : Cannot > create a POJO instance, the POJO constructor invocation has thrown an > exception : null > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Two bundles with the same package.On 11/5/09 4:27, peter lawrey wrote:
> Hello Richard, > Thank you for clarifying this. > Perhaps the error message can be improved, in situations which work > under Java but not OSGi. esp. if you are migrating an existing > application which works. ;) > It would be nice to give a better error message, but it is difficult to detect split package situations. What you did is perfectly legal as far as the framework is concerned, but the framework interprets differently than what you were expecting. -> richard > Kind Regards, > Peter. > > -----Original Message----- > From: Richard S. Hall [mailto:heavy@...] > Sent: 04 November 2009 15:24 > To: users@... > Subject: Re: Two bundles with the same package. > > > > On 11/4/09 4:18, peter lawrey wrote: > >> Hello, >> I have found that having the same package in two bundles, where one >> depends on the other causes a problem. This is ok if the bundles are >> independent, but if the same package appears in more than one bundle, >> only one bundle will work. >> >> > You are creating a split package (i.e., a package spanning multiple > bundles) then exporting/importing this package from both bundles. This > sort of thing is specifically not allowed by OSGi, so this is just an > error in your bundles. > > If you import a package from another bundle, it will completely shadow > an internal package of the same name. See the OSGi spec on class search > order. Imports are searched before the bundle class path and they are > terminal. > > By both importing and exporting the package, you are giving the OSGi > framework the choice to treat the bundle as an importer or an exporter > (in this case the "or" is "xor"). So, in your scenario, most likely one > of your bundles is being selected as an exporter and the other is being > selected as an importer. > > Moral to the story, don't use split packages. > > -> richard > > >> When I attempt to load the second bundle I get the following error. >> However if the second bundle uses a different package, there is no >> problem. >> I don't know if this should be an error or not but it could be >> > handled > >> better, either by reporting the true error or not reporting an error >> > and > >> working. >> One think I found confusing was the message "Cannot create a POJO >> instance, the POJO constructor invocation has thrown an exception : >> null" which indicates that the constructor was called but threw an >> unknown exception. Neither the constructor nor the static block for >> > the > >> class is called. >> >> See attached for an example. >> >> 10:08:26,384 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] SampleImplementation >> > : > >> [SampleImplementationA] Class not found during the loading phase : >> samepackage.SampleImplementation >> 10:08:26,385 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] SampleImplementation >> > : > >> [SampleImplementationA] createInstance -> The POJO constructor >> invocation failed : null >> 10:08:26,387 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] SampleImplementation >> > : > >> Cannot create a POJO instance, the POJO constructor invocation has >> thrown an exception : null >> java.lang.RuntimeException: Cannot create a POJO instance, the POJO >> constructor invocation has thrown an exception : null >> at >> >> > org.apache.felix.ipojo.InstanceManager.createObject(InstanceManager.java > >> :639) >> at >> >> > org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.jav > >> a:776) >> at >> >> > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > >> ler.__stateChanged(LifecycleCallbackHandler.java:156) >> at >> >> > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > >> ler.stateChanged(LifecycleCallbackHandler.java) >> at >> >> > org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:440 > >> ) >> at >> org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:321) >> at >> >> > org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory. > >> java:155) >> at >> >> > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > >> .java:298) >> at >> >> > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > >> .java:235) >> at >> >> > org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCr > >> eator.java:360) >> at >> >> > org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java: > >> 89) >> at org.apache.felix.ipojo.Extender.parse(Extender.java:269) >> at >> org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:208) >> at >> > org.apache.felix.ipojo.Extender.access$600(Extender.java:52) > >> at >> org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:669) >> at java.lang.Thread.run(Thread.java:619) >> 10:08:26,387 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] SampleImplementation >> > : > >> Cannot create a POJO instance, the POJO constructor invocation has >> thrown an exception : null >> 10:08:26,388 | ERROR | Thread-29 | ipojo >> | ? ? | [ERROR] iPOJO Instance >> > Creator > >> : A matching factory was found for {component=SampleImplementation, >> instance.name=SampleImplementationA}, but the instantiation failed : >> > The > >> configuration is not correct for the type SampleImplementation : >> > Cannot > >> create a POJO instance, the POJO constructor invocation has thrown an >> exception : null >> >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@... >> For additional commands, e-mail: users-help@... >> > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
Re: Usage of Architecture service and access of propertiesOn 04.11.2009, at 17:05, Vlatko Davidovski wrote: > Thanks for your response Clement. > Basically what I would like to do, is to have a possibility to > programmatically get all @ServiceProperty by their name > (name="system.property") and in such a way have a method for example: > > public String getProperty(String name) that will return me the value > for this property. > > Of course I can manually access each field. But I would like to > automate this, as I might have a lot of these fields. On the other > side I can use reflection, but then it is more complicated to get > the actual name of the property rather than the field name. Hi, Ok, I understand your problem. There is two way to handle such scenario. The first one is to use the Architecture service (that your instance provide) as a service dependency and then getting the service properties. The other way is to inject the service reference that you're providing and get the service properties registered. The service reference can be injected thanks to bind methods. Once you get it (optional dependency filtered to match yourself), you just have to get the service properties. Regards, Clement > > Vlatko > > On Nov 4, 2009, at 11:27 AM, Clement Escoffier wrote: > >> Hi, >> >> On 03.11.2009, at 21:11, Vlatko Davidovski wrote: >> >>> Hi! >>> >>> Given that I have a sample class: >>> >>> @Component(architecture=true, immediate = true, propagation = >>> true, managedservice = "org.client.ClientServiceImpl") >>> @Provides >>> public class ClientServiceImpl implements ClientService { >>> >>> @ServiceProperty(name="system.property", value="value1") >>> private String systemProperty; >>> >>> @Property(name="application.property", value="value2") >>> private String applicationProperty; >>> >>> @Requires >>> private Architecture architecture; >>> >>> >>> @Validate >>> public void start() { >>> >>> } >>> >>> @Invalidate >>> public void stop() { >>> >>> } >>> >>> } >> >> You can access the properties just by using the fields >> (systemProperty and applicationProperty). >> >> >> About architecture, this code does not inject your Architecture >> service, but get one from the service registry (should be the one >> with the lower service id). If you want your architecture you have >> to filter the requirement with an LDAP filter like: >> filter >> = >> "(architecture.instance >> =org.apache.felix.ipojo.sample.MyComponentImpl-0)" >> >> Regards, >> >> Clement >> >>> >>> How can I access the values of systemProperty and >>> applicationProperty inside start() method? >>> >>> Thanks! >>> Vlatko >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
|
|
RE: Two bundles with the same package.When it processes the @Component annotation it can check whether the
class will be loaded, and give an explanation as to why it won't. It must at least find/read the annotation as it able to map the name of the component to the class name (which it later fails to look up) Given the class will not be loaded perhaps it shouldn't read the annotation and just reject the bundle at load time. i.e. it kind of half loads the class which I find a bit odd. Of course, I think it would be much simpler if the class loading used a class path approach like the URLCLassLoader does, but I assume there is a good reason the standard prevents this from happening. (Obviously karaf needs to follow the standard, so there is not much you can do about it) -----Original Message----- From: Richard S. Hall [mailto:heavy@...] Sent: 05 November 2009 14:46 To: users@... Subject: Re: Two bundles with the same package. On 11/5/09 4:27, peter lawrey wrote: > Hello Richard, > Thank you for clarifying this. > Perhaps the error message can be improved, in situations which work > under Java but not OSGi. esp. if you are migrating an existing > application which works. ;) > It would be nice to give a better error message, but it is difficult to detect split package situations. What you did is perfectly legal as far as the framework is concerned, but the framework interprets differently than what you were expecting. -> richard > Kind Regards, > Peter. > > -----Original Message----- > From: Richard S. Hall [mailto:heavy@...] > Sent: 04 November 2009 15:24 > To: users@... > Subject: Re: Two bundles with the same package. > > > > On 11/4/09 4:18, peter lawrey wrote: > >> Hello, >> I have found that having the same package in two bundles, where >> depends on the other causes a problem. This is ok if the bundles are >> independent, but if the same package appears in more than one bundle, >> only one bundle will work. >> >> > You are creating a split package (i.e., a package spanning multiple > bundles) then exporting/importing this package from both bundles. This > sort of thing is specifically not allowed by OSGi, so this is just an > error in your bundles. > > If you import a package from another bundle, it will completely shadow > an internal package of the same name. See the OSGi spec on class > order. Imports are searched before the bundle class path and they are > terminal. > > By both importing and exporting the package, you are giving the OSGi > framework the choice to treat the bundle as an importer or an exporter > (in this case the "or" is "xor"). So, in your scenario, most likely one > of your bundles is being selected as an exporter and the other is being > selected as an importer. > > Moral to the story, don't use split packages. > > -> richard > > >> When I attempt to load the second bundle I get the following error. >> However if the second bundle uses a different package, there is no >> problem. >> I don't know if this should be an error or not but it could be >> > handled > >> better, either by reporting the true error or not reporting an error >> > and > >> working. >> One think I found confusing was the message "Cannot create a POJO >> instance, the POJO constructor invocation has thrown an exception : >> null" which indicates that the constructor was called but threw an >> unknown exception. Neither the constructor nor the static block for >> > the > >> class is called. >> >> See attached for an example. >> >> 10:08:26,384 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] >> > : > >> [SampleImplementationA] Class not found during the loading phase : >> samepackage.SampleImplementation >> 10:08:26,385 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] SampleImplementation >> > : > >> [SampleImplementationA] createInstance -> The POJO constructor >> invocation failed : null >> 10:08:26,387 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] SampleImplementation >> > : > >> Cannot create a POJO instance, the POJO constructor invocation has >> thrown an exception : null >> java.lang.RuntimeException: Cannot create a POJO instance, the POJO >> constructor invocation has thrown an exception : null >> at >> >> > > >> :639) >> at >> >> > org.apache.felix.ipojo.InstanceManager.getPojoObject(InstanceManager.jav > >> a:776) >> at >> >> > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > >> ler.__stateChanged(LifecycleCallbackHandler.java:156) >> at >> >> > org.apache.felix.ipojo.handlers.lifecycle.callback.LifecycleCallbackHand > >> ler.stateChanged(LifecycleCallbackHandler.java) >> at >> >> > org.apache.felix.ipojo.InstanceManager.setState(InstanceManager.java:440 > >> ) >> at >> org.apache.felix.ipojo.InstanceManager.start(InstanceManager.java:321) >> at >> >> > org.apache.felix.ipojo.ComponentFactory.createInstance(ComponentFactory. > >> java:155) >> at >> >> > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > >> .java:298) >> at >> >> > org.apache.felix.ipojo.IPojoFactory.createComponentInstance(IPojoFactory > >> .java:235) >> at >> >> > org.apache.felix.ipojo.InstanceCreator$ManagedInstance.create(InstanceCr > >> eator.java:360) >> at >> >> > org.apache.felix.ipojo.InstanceCreator.addInstance(InstanceCreator.java: > >> 89) >> at org.apache.felix.ipojo.Extender.parse(Extender.java:269) >> at >> org.apache.felix.ipojo.Extender.startManagementFor(Extender.java:208) >> at >> > org.apache.felix.ipojo.Extender.access$600(Extender.java:52) > >> at >> org.apache.felix.ipojo.Extender$CreatorThread.run(Extender.java:669) >> at java.lang.Thread.run(Thread.java:619) >> 10:08:26,387 | ERROR | Thread-29 | SamePackage Two >> | ? ? | [ERROR] >> > : > >> Cannot create a POJO instance, the POJO constructor invocation has >> thrown an exception : null >> 10:08:26,388 | ERROR | Thread-29 | ipojo >> | ? ? | [ERROR] iPOJO Instance >> > Creator > >> : A matching factory was found for {component=SampleImplementation, >> instance.name=SampleImplementationA}, but the instantiation failed : >> > The > >> configuration is not correct for the type SampleImplementation : >> > Cannot > >> create a POJO instance, the POJO constructor invocation has thrown an >> exception : null >> >> >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscribe@... >> For additional commands, e-mail: users-help@... >> > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@... > For additional commands, e-mail: users-help@... > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@... For additional commands, e-mail: users-help@... |
| Free embeddable forum powered by Nabble | Forum Help |