You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by David Gallardo <dg...@gmail.com> on 2009/04/08 05:21:27 UTC

Fragments?

Hi all-

I'm trying to implement an OSGi-based framework that has a dynamic
proxy service that is shared by other components in the framework. The
basic idea is that each component registers a set of interfaces with
the dynamic proxy and is then able to utilize those interfaces as
implemented dynamically by the proxy. Interfaces belonging to other
components should not be visible.

My initial plan was to have two bundles for each component, one a
regular bundle and one a fragment. Supposing there are two components,
it would look something like this (pom.xml and manifest syntax issues
aside):

ComponentA-interfaces
   Fragment-Host: Dynamic proxy
   Export-Package: component-a.interfaces

ComponentA
  Dependency: ComponentA-interfaces

ComponentB-interfaces
   Fragment-Host: Dynamic proxy
   Export-Package: component-b.interfaces

ComponentB
  Dependency: ComponentB-interfaces

Now the problem that occurs when I try this with Felix is that it
throws an exception because fragments with exports are currently not
supported.

Given that, is there another way that I can make the interfaces
visible to only the owning component and the proxy? (I.e. in the
example above, ComponentA-interfaces should not be visible to
ComponentB, and vice versa.) Or should I consider another OSGi
framework such as Knoplerfish or Equinox that supports fragments with
exports?

Thanks in advance for any guidance.

@D

-- 
Follow me on twitter: djgallardo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Fragments?

Posted by David Gallardo <dg...@gmail.com>.
Peter, Stuart -

Using a bridging classloader did the trick & I've now got my
application up & running.

I'm going to have to do some re-thinking and refactoring to set up my
proxy as a proxy factory service as you suggest, (and better manage
things as other bundles come & go), but this is a good start.

Thanks for your help!

@D

On Tue, Apr 7, 2009 at 11:19 PM, Peter Kriens <pe...@aqute.biz> wrote:
> Using fragments to do class loader hacks is usually not a good idea ...
> Fragments have all the bad aspects of inheritance. This is no problem for
> internationalization code or native code which both are intricately tied to
> the host. However, it is an awful extension mechanism. Even in this simple
> example it is already hard to see the relations. For extension mechanisms,
> there are services ...
>
> The normal way is to use a ProxyFactory service. This service should create
> a bridging class loader for all the interfaces that are used in the proxy.
> This is quite easy to do because you just use each of the involved class
> loaders.
>
> I've written a blog about this some time ago:
> http://www.osgi.org/blog/2008/08/classy-solutions-to-tricky-proxies.html
>
> Some more links are at the comments in the end.
>
> Kind regards,
>
>        Peter Kriens
>
>
>
> On 8 apr 2009, at 05:21, David Gallardo wrote:
>
>> Hi all-
>>
>> I'm trying to implement an OSGi-based framework that has a dynamic
>> proxy service that is shared by other components in the framework. The
>> basic idea is that each component registers a set of interfaces with
>> the dynamic proxy and is then able to utilize those interfaces as
>> implemented dynamically by the proxy. Interfaces belonging to other
>> components should not be visible.
>>
>> My initial plan was to have two bundles for each component, one a
>> regular bundle and one a fragment. Supposing there are two components,
>> it would look something like this (pom.xml and manifest syntax issues
>> aside):
>>
>> ComponentA-interfaces
>>  Fragment-Host: Dynamic proxy
>>  Export-Package: component-a.interfaces
>>
>> ComponentA
>>  Dependency: ComponentA-interfaces
>>
>> ComponentB-interfaces
>>  Fragment-Host: Dynamic proxy
>>  Export-Package: component-b.interfaces
>>
>> ComponentB
>>  Dependency: ComponentB-interfaces
>>
>> Now the problem that occurs when I try this with Felix is that it
>> throws an exception because fragments with exports are currently not
>> supported.
>>
>> Given that, is there another way that I can make the interfaces
>> visible to only the owning component and the proxy? (I.e. in the
>> example above, ComponentA-interfaces should not be visible to
>> ComponentB, and vice versa.) Or should I consider another OSGi
>> framework such as Knoplerfish or Equinox that supports fragments with
>> exports?
>>
>> Thanks in advance for any guidance.
>>
>> @D
>>
>> --
>> Follow me on twitter: djgallardo
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>



-- 
Follow me on twitter: djgallardo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Fragments?

Posted by Peter Kriens <pe...@aqute.biz>.
Using fragments to do class loader hacks is usually not a good  
idea ... Fragments have all the bad aspects of inheritance. This is no  
problem for internationalization code or native code which both are  
intricately tied to the host. However, it is an awful extension  
mechanism. Even in this simple example it is already hard to see the  
relations. For extension mechanisms, there are services ...

The normal way is to use a ProxyFactory service. This service should  
create a bridging class loader for all the interfaces that are used in  
the proxy. This is quite easy to do because you just use each of the  
involved class loaders.

I've written a blog about this some time ago: http://www.osgi.org/blog/2008/08/classy-solutions-to-tricky-proxies.html

Some more links are at the comments in the end.

Kind regards,

	Peter Kriens



On 8 apr 2009, at 05:21, David Gallardo wrote:

> Hi all-
>
> I'm trying to implement an OSGi-based framework that has a dynamic
> proxy service that is shared by other components in the framework. The
> basic idea is that each component registers a set of interfaces with
> the dynamic proxy and is then able to utilize those interfaces as
> implemented dynamically by the proxy. Interfaces belonging to other
> components should not be visible.
>
> My initial plan was to have two bundles for each component, one a
> regular bundle and one a fragment. Supposing there are two components,
> it would look something like this (pom.xml and manifest syntax issues
> aside):
>
> ComponentA-interfaces
>   Fragment-Host: Dynamic proxy
>   Export-Package: component-a.interfaces
>
> ComponentA
>  Dependency: ComponentA-interfaces
>
> ComponentB-interfaces
>   Fragment-Host: Dynamic proxy
>   Export-Package: component-b.interfaces
>
> ComponentB
>  Dependency: ComponentB-interfaces
>
> Now the problem that occurs when I try this with Felix is that it
> throws an exception because fragments with exports are currently not
> supported.
>
> Given that, is there another way that I can make the interfaces
> visible to only the owning component and the proxy? (I.e. in the
> example above, ComponentA-interfaces should not be visible to
> ComponentB, and vice versa.) Or should I consider another OSGi
> framework such as Knoplerfish or Equinox that supports fragments with
> exports?
>
> Thanks in advance for any guidance.
>
> @D
>
> -- 
> Follow me on twitter: djgallardo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Fragments?

Posted by Stuart McCulloch <mc...@gmail.com>.
2009/4/8 David Gallardo <dg...@gmail.com>

> Hi all-
>
> I'm trying to implement an OSGi-based framework that has a dynamic
> proxy service that is shared by other components in the framework. The
> basic idea is that each component registers a set of interfaces with
> the dynamic proxy and is then able to utilize those interfaces as
> implemented dynamically by the proxy. Interfaces belonging to other
> components should not be visible.
>
> My initial plan was to have two bundles for each component, one a
> regular bundle and one a fragment. Supposing there are two components,
> it would look something like this (pom.xml and manifest syntax issues
> aside):
>
> ComponentA-interfaces
>   Fragment-Host: Dynamic proxy
>   Export-Package: component-a.interfaces
>
> ComponentA
>  Dependency: ComponentA-interfaces
>
> ComponentB-interfaces
>   Fragment-Host: Dynamic proxy
>   Export-Package: component-b.interfaces
>
> ComponentB
>  Dependency: ComponentB-interfaces
>
> Now the problem that occurs when I try this with Felix is that it
> throws an exception because fragments with exports are currently not
> supported.
>
> Given that, is there another way that I can make the interfaces
> visible to only the owning component and the proxy? (I.e. in the
> example above, ComponentA-interfaces should not be visible to
> ComponentB, and vice versa.) Or should I consider another OSGi
> framework such as Knoplerfish or Equinox that supports fragments with
> exports?
>

you could consider creating custom classloaders to bridge
between each client bundle and the proxy bundle - then use
these custom classloaders when generating the proxies

that's what we do over at Guice to support AOP in OSGi:

  http://code.google.com/p/google-guice/wiki/ClassLoading
  http://code.google.com/p/google-guice/wiki/OSGi

the relevant code can be found here:


http://google-guice.googlecode.com/svn/trunk/src/com/google/inject/internal/BytecodeGen.java

you should also apply this patch to get the latest fixes:

  http://code.google.com/p/google-guice/issues/detail?id=343#c5

but you could probably use something a lot simpler

FYI, I discussed bridge classloading in my EclipseCon talk:


http://peaberry.googlecode.com/files/peaberry%20-%20blending%20services%20and%20extensions.odp

HTH

Thanks in advance for any guidance.
>
> @D
>
> --
> Follow me on twitter: djgallardo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>

-- 
Cheers, Stuart