You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Rajini Sivaram <ra...@googlemail.com> on 2007/06/15 18:09:38 UTC
Implementation of ServiceReference.isAssignableTo different in various OSGi framework implementations
Hello,
I am working on SCA-OSGi integration to enable OSGi bundles to form the
implementation type for Apache Tuscany SCA components. I have run into some
problems because of the way service references are filtered in Felix.
This is the scenario. We startup Felix runtime in embedded mode inside
Tuscany. To intercept an OSGi service, a proxy is registered into the OSGi
service registry. The interface used by the proxy is of the same classloader
as the one seen by the requestor bundle (it was loaded using
requestorBundle.loadClass). The classloader of the system bundle however has
access to this interface loaded by the application classloader. The
requestor has a wire for the interface, but the provider (system bundle)
doesn't. The test performed for ServiceReference.isAssignableTo seems to be
different for Equinox, Knopflerfish and Felix. In both Equinox and
Knopflerfish, the proxy service is returned to the requestor bundle when
getServiceReference is called. Felix, however first tests if the class
loaded by the provider is the same as the class loaded by the requestor (
ServiceRegistrationImpl.isClassAccessible()). If the class cannot be loaded
by the provider, then the class of the registered object is tested. Is the
first test which prevents bundles from registering services of objects using
different classloaders strictly necessary? Wouldn't it be sufficient to test
the class of the object registered?
Thank you...
Regards,
Rajini
Re: Implementation of ServiceReference.isAssignableTo different in
various OSGi framework implementations
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Just a follow up on this...it turns out that removing the test to load
from the registering bundle is not always correct...in fact, it causes
Spring-OSGi to fail.
The issue for them is that the registering module DOES have access to
the service interface, but it is ALSO available on the class path. For
them they are passing the first test, but they fail the second since the
class gets returned from the class path (actually from
org.apache.maven.surefire.booter.IsolatedClassLoader)...
Needless to say, we need to think about this issue some more...
-> richard
Rajini Sivaram wrote:
> Hello,
>
> I am working on SCA-OSGi integration to enable OSGi bundles to form the
> implementation type for Apache Tuscany SCA components. I have run into
> some
> problems because of the way service references are filtered in Felix.
>
> This is the scenario. We startup Felix runtime in embedded mode inside
> Tuscany. To intercept an OSGi service, a proxy is registered into the
> OSGi
> service registry. The interface used by the proxy is of the same
> classloader
> as the one seen by the requestor bundle (it was loaded using
> requestorBundle.loadClass). The classloader of the system bundle
> however has
> access to this interface loaded by the application classloader. The
> requestor has a wire for the interface, but the provider (system bundle)
> doesn't. The test performed for ServiceReference.isAssignableTo seems
> to be
> different for Equinox, Knopflerfish and Felix. In both Equinox and
> Knopflerfish, the proxy service is returned to the requestor bundle when
> getServiceReference is called. Felix, however first tests if the class
> loaded by the provider is the same as the class loaded by the requestor (
> ServiceRegistrationImpl.isClassAccessible()). If the class cannot be
> loaded
> by the provider, then the class of the registered object is tested. Is
> the
> first test which prevents bundles from registering services of objects
> using
> different classloaders strictly necessary? Wouldn't it be sufficient
> to test
> the class of the object registered?
>
>
> Thank you...
>
> Regards,
>
> Rajini
>
Re: Implementation of ServiceReference.isAssignableTo different in various OSGi framework implementations
Posted by Rajini Sivaram <ra...@googlemail.com>.
Richard,
Thank you very much for providing the fix so quickly. It works now!
Thank you...
Regards,
Rajini
On 6/18/07, Richard S. Hall <he...@ungoverned.org> wrote:
>
> Ok, the change has been committed and deployed...let me know if it is
> working now...
>
> -> richard
>
> Richard S. Hall wrote:
> > Rajini Sivaram wrote:
> >> Hello,
> >>
> >> I am working on SCA-OSGi integration to enable OSGi bundles to form the
> >> implementation type for Apache Tuscany SCA components. I have run
> >> into some
> >> problems because of the way service references are filtered in Felix.
> >>
> >> This is the scenario. We startup Felix runtime in embedded mode inside
> >> Tuscany. To intercept an OSGi service, a proxy is registered into the
> >> OSGi
> >> service registry. The interface used by the proxy is of the same
> >> classloader
> >> as the one seen by the requestor bundle (it was loaded using
> >> requestorBundle.loadClass). The classloader of the system bundle
> >> however has
> >> access to this interface loaded by the application classloader. The
> >> requestor has a wire for the interface, but the provider (system
> bundle)
> >> doesn't. The test performed for ServiceReference.isAssignableTo seems
> >> to be
> >> different for Equinox, Knopflerfish and Felix. In both Equinox and
> >> Knopflerfish, the proxy service is returned to the requestor bundle
> when
> >> getServiceReference is called. Felix, however first tests if the class
> >> loaded by the provider is the same as the class loaded by the
> >> requestor (
> >> ServiceRegistrationImpl.isClassAccessible()). If the class cannot be
> >> loaded
> >> by the provider, then the class of the registered object is tested.
> >> Is the
> >> first test which prevents bundles from registering services of
> >> objects using
> >> different classloaders strictly necessary? Wouldn't it be sufficient
> >> to test
> >> the class of the object registered?
> >
> > Yes, you could be right, because if the service object class is loaded
> > from the provider, then it should be discovered by the second check
> > anyway, right? Thus, it seems like it should only be necessary to do
> > the second check which will cover both cases...I think... :-)
> >
> > Anyone want to venture a guess as to whether my logic is correct? If
> > so, I can commit a fix...
> >
> > -> richard
> >
>
Re: Implementation of ServiceReference.isAssignableTo different in
various OSGi framework implementations
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Ok, the change has been committed and deployed...let me know if it is
working now...
-> richard
Richard S. Hall wrote:
> Rajini Sivaram wrote:
>> Hello,
>>
>> I am working on SCA-OSGi integration to enable OSGi bundles to form the
>> implementation type for Apache Tuscany SCA components. I have run
>> into some
>> problems because of the way service references are filtered in Felix.
>>
>> This is the scenario. We startup Felix runtime in embedded mode inside
>> Tuscany. To intercept an OSGi service, a proxy is registered into the
>> OSGi
>> service registry. The interface used by the proxy is of the same
>> classloader
>> as the one seen by the requestor bundle (it was loaded using
>> requestorBundle.loadClass). The classloader of the system bundle
>> however has
>> access to this interface loaded by the application classloader. The
>> requestor has a wire for the interface, but the provider (system bundle)
>> doesn't. The test performed for ServiceReference.isAssignableTo seems
>> to be
>> different for Equinox, Knopflerfish and Felix. In both Equinox and
>> Knopflerfish, the proxy service is returned to the requestor bundle when
>> getServiceReference is called. Felix, however first tests if the class
>> loaded by the provider is the same as the class loaded by the
>> requestor (
>> ServiceRegistrationImpl.isClassAccessible()). If the class cannot be
>> loaded
>> by the provider, then the class of the registered object is tested.
>> Is the
>> first test which prevents bundles from registering services of
>> objects using
>> different classloaders strictly necessary? Wouldn't it be sufficient
>> to test
>> the class of the object registered?
>
> Yes, you could be right, because if the service object class is loaded
> from the provider, then it should be discovered by the second check
> anyway, right? Thus, it seems like it should only be necessary to do
> the second check which will cover both cases...I think... :-)
>
> Anyone want to venture a guess as to whether my logic is correct? If
> so, I can commit a fix...
>
> -> richard
>
Re: Implementation of ServiceReference.isAssignableTo different in
various OSGi framework implementations
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Rajini Sivaram wrote:
> If you do put the fix in, when will it be available in a Felix
> release? Is
> there a new release planned soon?
Well, when I commit it today, then I will also do a deploy, so it will
be available in the snapshot repo immediately.
As far as being available in an official release, this will probably be
our goal for July.
-> richard
>
> Thank you...
>
> Regards,
>
> Rajini
>
>
> On 6/18/07, Richard S. Hall <he...@ungoverned.org> wrote:
>>
>> Rajini Sivaram wrote:
>> > Thank you, Richard. The fix will be of great help to me.
>> >
>> > I imagine that the first check will need to be removed to support
>> delayed
>> > services with Declarative Services for Felix since presumably DS also
>> > installs proxy services in order to implement delayed services.
>>
>> Proxies are not needed in DS because it can just use the ServiceFactory
>> interface...
>>
>> Even then, it seems that your scenario is only relevant if the registrar
>> also has access to the same class of the provider's service object,
>> right? In general, DS, for example, would not have access to any service
>> object interfaces so the first check would always fail and the second
>> test would be used. At least, that is my understanding.
>>
>> I haven't committed the changes yet, but I should be the end of the day,
>> I imagine...I just want to think about it a little bit more before doing
>> so...
>>
>> Thanks again.
>>
>> -> richard
>>
>> >
>> > Thank you...
>> >
>> > Regards,
>> >
>> > Rajini
>> >
>> >
>> > On 6/15/07, Richard S. Hall <he...@ungoverned.org> wrote:
>> >>
>> >> Rajini Sivaram wrote:
>> >> > Hello,
>> >> >
>> >> > I am working on SCA-OSGi integration to enable OSGi bundles to form
>> >> the
>> >> > implementation type for Apache Tuscany SCA components. I have run
>> into
>> >> > some
>> >> > problems because of the way service references are filtered in
>> Felix.
>> >> >
>> >> > This is the scenario. We startup Felix runtime in embedded mode
>> inside
>> >> > Tuscany. To intercept an OSGi service, a proxy is registered
>> into the
>> >> > OSGi
>> >> > service registry. The interface used by the proxy is of the same
>> >> > classloader
>> >> > as the one seen by the requestor bundle (it was loaded using
>> >> > requestorBundle.loadClass). The classloader of the system bundle
>> >> > however has
>> >> > access to this interface loaded by the application classloader. The
>> >> > requestor has a wire for the interface, but the provider (system
>> >> bundle)
>> >> > doesn't. The test performed for ServiceReference.isAssignableTo
>> seems
>> >> > to be
>> >> > different for Equinox, Knopflerfish and Felix. In both Equinox and
>> >> > Knopflerfish, the proxy service is returned to the requestor bundle
>> >> when
>> >> > getServiceReference is called. Felix, however first tests if the
>> class
>> >> > loaded by the provider is the same as the class loaded by the
>> >> requestor
>> >> (
>> >> > ServiceRegistrationImpl.isClassAccessible()). If the class
>> cannot be
>> >> > loaded
>> >> > by the provider, then the class of the registered object is tested.
>> Is
>> >> > the
>> >> > first test which prevents bundles from registering services of
>> objects
>> >> > using
>> >> > different classloaders strictly necessary? Wouldn't it be
>> sufficient
>> >> > to test
>> >> > the class of the object registered?
>> >>
>> >> Yes, you could be right, because if the service object class is
>> loaded
>> >> from the provider, then it should be discovered by the second check
>> >> anyway, right? Thus, it seems like it should only be necessary to do
>> the
>> >> second check which will cover both cases...I think... :-)
>> >>
>> >> Anyone want to venture a guess as to whether my logic is correct? If
>> so,
>> >> I can commit a fix...
>> >>
>> >> -> richard
>> >>
>> >>
>> >
>>
>
Re: Implementation of ServiceReference.isAssignableTo different in various OSGi framework implementations
Posted by Rajini Sivaram <ra...@googlemail.com>.
Richard,
Yes, you are right. With DS, the bundle wont have access to the class, so
the first test wont cause the same problem.
If you do put the fix in, when will it be available in a Felix release? Is
there a new release planned soon?
Thank you...
Regards,
Rajini
On 6/18/07, Richard S. Hall <he...@ungoverned.org> wrote:
>
> Rajini Sivaram wrote:
> > Thank you, Richard. The fix will be of great help to me.
> >
> > I imagine that the first check will need to be removed to support
> delayed
> > services with Declarative Services for Felix since presumably DS also
> > installs proxy services in order to implement delayed services.
>
> Proxies are not needed in DS because it can just use the ServiceFactory
> interface...
>
> Even then, it seems that your scenario is only relevant if the registrar
> also has access to the same class of the provider's service object,
> right? In general, DS, for example, would not have access to any service
> object interfaces so the first check would always fail and the second
> test would be used. At least, that is my understanding.
>
> I haven't committed the changes yet, but I should be the end of the day,
> I imagine...I just want to think about it a little bit more before doing
> so...
>
> Thanks again.
>
> -> richard
>
> >
> > Thank you...
> >
> > Regards,
> >
> > Rajini
> >
> >
> > On 6/15/07, Richard S. Hall <he...@ungoverned.org> wrote:
> >>
> >> Rajini Sivaram wrote:
> >> > Hello,
> >> >
> >> > I am working on SCA-OSGi integration to enable OSGi bundles to form
> >> the
> >> > implementation type for Apache Tuscany SCA components. I have run
> into
> >> > some
> >> > problems because of the way service references are filtered in Felix.
> >> >
> >> > This is the scenario. We startup Felix runtime in embedded mode
> inside
> >> > Tuscany. To intercept an OSGi service, a proxy is registered into the
> >> > OSGi
> >> > service registry. The interface used by the proxy is of the same
> >> > classloader
> >> > as the one seen by the requestor bundle (it was loaded using
> >> > requestorBundle.loadClass). The classloader of the system bundle
> >> > however has
> >> > access to this interface loaded by the application classloader. The
> >> > requestor has a wire for the interface, but the provider (system
> >> bundle)
> >> > doesn't. The test performed for ServiceReference.isAssignableTo seems
> >> > to be
> >> > different for Equinox, Knopflerfish and Felix. In both Equinox and
> >> > Knopflerfish, the proxy service is returned to the requestor bundle
> >> when
> >> > getServiceReference is called. Felix, however first tests if the
> class
> >> > loaded by the provider is the same as the class loaded by the
> >> requestor
> >> (
> >> > ServiceRegistrationImpl.isClassAccessible()). If the class cannot be
> >> > loaded
> >> > by the provider, then the class of the registered object is tested.
> Is
> >> > the
> >> > first test which prevents bundles from registering services of
> objects
> >> > using
> >> > different classloaders strictly necessary? Wouldn't it be sufficient
> >> > to test
> >> > the class of the object registered?
> >>
> >> Yes, you could be right, because if the service object class is loaded
> >> from the provider, then it should be discovered by the second check
> >> anyway, right? Thus, it seems like it should only be necessary to do
> the
> >> second check which will cover both cases...I think... :-)
> >>
> >> Anyone want to venture a guess as to whether my logic is correct? If
> so,
> >> I can commit a fix...
> >>
> >> -> richard
> >>
> >>
> >
>
Re: Implementation of ServiceReference.isAssignableTo different in
various OSGi framework implementations
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Rajini Sivaram wrote:
> Thank you, Richard. The fix will be of great help to me.
>
> I imagine that the first check will need to be removed to support delayed
> services with Declarative Services for Felix since presumably DS also
> installs proxy services in order to implement delayed services.
Proxies are not needed in DS because it can just use the ServiceFactory
interface...
Even then, it seems that your scenario is only relevant if the registrar
also has access to the same class of the provider's service object,
right? In general, DS, for example, would not have access to any service
object interfaces so the first check would always fail and the second
test would be used. At least, that is my understanding.
I haven't committed the changes yet, but I should be the end of the day,
I imagine...I just want to think about it a little bit more before doing
so...
Thanks again.
-> richard
>
> Thank you...
>
> Regards,
>
> Rajini
>
>
> On 6/15/07, Richard S. Hall <he...@ungoverned.org> wrote:
>>
>> Rajini Sivaram wrote:
>> > Hello,
>> >
>> > I am working on SCA-OSGi integration to enable OSGi bundles to form
>> the
>> > implementation type for Apache Tuscany SCA components. I have run into
>> > some
>> > problems because of the way service references are filtered in Felix.
>> >
>> > This is the scenario. We startup Felix runtime in embedded mode inside
>> > Tuscany. To intercept an OSGi service, a proxy is registered into the
>> > OSGi
>> > service registry. The interface used by the proxy is of the same
>> > classloader
>> > as the one seen by the requestor bundle (it was loaded using
>> > requestorBundle.loadClass). The classloader of the system bundle
>> > however has
>> > access to this interface loaded by the application classloader. The
>> > requestor has a wire for the interface, but the provider (system
>> bundle)
>> > doesn't. The test performed for ServiceReference.isAssignableTo seems
>> > to be
>> > different for Equinox, Knopflerfish and Felix. In both Equinox and
>> > Knopflerfish, the proxy service is returned to the requestor bundle
>> when
>> > getServiceReference is called. Felix, however first tests if the class
>> > loaded by the provider is the same as the class loaded by the
>> requestor
>> (
>> > ServiceRegistrationImpl.isClassAccessible()). If the class cannot be
>> > loaded
>> > by the provider, then the class of the registered object is tested. Is
>> > the
>> > first test which prevents bundles from registering services of objects
>> > using
>> > different classloaders strictly necessary? Wouldn't it be sufficient
>> > to test
>> > the class of the object registered?
>>
>> Yes, you could be right, because if the service object class is loaded
>> from the provider, then it should be discovered by the second check
>> anyway, right? Thus, it seems like it should only be necessary to do the
>> second check which will cover both cases...I think... :-)
>>
>> Anyone want to venture a guess as to whether my logic is correct? If so,
>> I can commit a fix...
>>
>> -> richard
>>
>>
>
Re: Implementation of ServiceReference.isAssignableTo different in various OSGi framework implementations
Posted by Rajini Sivaram <ra...@googlemail.com>.
Thank you, Richard. The fix will be of great help to me.
I imagine that the first check will need to be removed to support delayed
services with Declarative Services for Felix since presumably DS also
installs proxy services in order to implement delayed services.
Thank you...
Regards,
Rajini
On 6/15/07, Richard S. Hall <he...@ungoverned.org> wrote:
>
> Rajini Sivaram wrote:
> > Hello,
> >
> > I am working on SCA-OSGi integration to enable OSGi bundles to form the
> > implementation type for Apache Tuscany SCA components. I have run into
> > some
> > problems because of the way service references are filtered in Felix.
> >
> > This is the scenario. We startup Felix runtime in embedded mode inside
> > Tuscany. To intercept an OSGi service, a proxy is registered into the
> > OSGi
> > service registry. The interface used by the proxy is of the same
> > classloader
> > as the one seen by the requestor bundle (it was loaded using
> > requestorBundle.loadClass). The classloader of the system bundle
> > however has
> > access to this interface loaded by the application classloader. The
> > requestor has a wire for the interface, but the provider (system bundle)
> > doesn't. The test performed for ServiceReference.isAssignableTo seems
> > to be
> > different for Equinox, Knopflerfish and Felix. In both Equinox and
> > Knopflerfish, the proxy service is returned to the requestor bundle when
> > getServiceReference is called. Felix, however first tests if the class
> > loaded by the provider is the same as the class loaded by the requestor
> (
> > ServiceRegistrationImpl.isClassAccessible()). If the class cannot be
> > loaded
> > by the provider, then the class of the registered object is tested. Is
> > the
> > first test which prevents bundles from registering services of objects
> > using
> > different classloaders strictly necessary? Wouldn't it be sufficient
> > to test
> > the class of the object registered?
>
> Yes, you could be right, because if the service object class is loaded
> from the provider, then it should be discovered by the second check
> anyway, right? Thus, it seems like it should only be necessary to do the
> second check which will cover both cases...I think... :-)
>
> Anyone want to venture a guess as to whether my logic is correct? If so,
> I can commit a fix...
>
> -> richard
>
>
Re: Implementation of ServiceReference.isAssignableTo different in
various OSGi framework implementations
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Rajini Sivaram wrote:
> Hello,
>
> I am working on SCA-OSGi integration to enable OSGi bundles to form the
> implementation type for Apache Tuscany SCA components. I have run into
> some
> problems because of the way service references are filtered in Felix.
>
> This is the scenario. We startup Felix runtime in embedded mode inside
> Tuscany. To intercept an OSGi service, a proxy is registered into the
> OSGi
> service registry. The interface used by the proxy is of the same
> classloader
> as the one seen by the requestor bundle (it was loaded using
> requestorBundle.loadClass). The classloader of the system bundle
> however has
> access to this interface loaded by the application classloader. The
> requestor has a wire for the interface, but the provider (system bundle)
> doesn't. The test performed for ServiceReference.isAssignableTo seems
> to be
> different for Equinox, Knopflerfish and Felix. In both Equinox and
> Knopflerfish, the proxy service is returned to the requestor bundle when
> getServiceReference is called. Felix, however first tests if the class
> loaded by the provider is the same as the class loaded by the requestor (
> ServiceRegistrationImpl.isClassAccessible()). If the class cannot be
> loaded
> by the provider, then the class of the registered object is tested. Is
> the
> first test which prevents bundles from registering services of objects
> using
> different classloaders strictly necessary? Wouldn't it be sufficient
> to test
> the class of the object registered?
Yes, you could be right, because if the service object class is loaded
from the provider, then it should be discovered by the second check
anyway, right? Thus, it seems like it should only be necessary to do the
second check which will cover both cases...I think... :-)
Anyone want to venture a guess as to whether my logic is correct? If so,
I can commit a fix...
-> richard