You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by xuhb <xu...@tongtech.com> on 2011/10/17 08:32:40 UTC

How to find a class of bundle from Host application?

Hi:
    I am using osgi environment (felix) embedded in a Host Application; 
    Now the host application want to use a class from a specified osgi bundle, 
    Could standard osgi support such usage? 
    or felix support such extension usage?
Thanks any suggestion

Re: How to find a class of bundle from Host application?

Posted by Dileepa Jayakody <di...@wso2.com>.
Hi,

Think this thread is useful in finding a solution to your problem.
http://forums.dzone.com/eclipse/118-access-osgi-servicees-outside-osgi-environment.html#post380

Thanks,
Dileepa
On Mon, Oct 17, 2011 at 1:00 PM, Dileepa Jayakody <di...@wso2.com> wrote:

> Hi all,
>
> I'm a newbie to OSGI.
> Doesn't an osgi bundle act as a normal jar in a non-osgi environment? An
> osgi bundle is basically a jar with some additional meta info in it's
> manifest which is read by the osgi framework to enable osgi related stuff
> from the jar(bundle) as per my understanding.
>
> So, ideally if you add the osgi bundle in the host application's class-path
> (which is non-osgi) it will just be considered as a normal jar and it should
> be able to import the class from the bundle just like it does from a normal
> jar. Did you try adding the jar to your host-application and importing it?
> Just a suggestion from a newbie, keen to learn more on osgi.
>
> Thanks,
> Dileepa
>
> On Mon, Oct 17, 2011 at 12:14 PM, xuhb <xu...@tongtech.com> wrote:
>
>> Sorry, I  expressed my requirement un-correctly;
>>
>> Actually, the host application just know the name of class and want to
>> choose such class from embedded osgi environment ?
>> Could I?
>> Must I create a bundle (which import such class) dynamically and retrive
>> class from the dynamic created bundle? Is there other facilitate method?
>>
>> Thanks any suggestion
>> ----- Original Message -----
>> From: "xuhb" <xu...@tongtech.com>
>> To: <us...@felix.apache.org>
>> Sent: Monday, October 17, 2011 2:32 PM
>> Subject: How to find a class of bundle from Host application?
>>
>>
>> > Hi:
>> >    I am using osgi environment (felix) embedded in a Host Application;
>> >    Now the host application want to use a class from a specified osgi
>> bundle,
>> >    Could standard osgi support such usage?
>> >    or felix support such extension usage?
>> > Thanks any suggestion
>>
>
>
>
> --
> Dileepa Jayakody,
> Software Engineer, WSO2 Inc.
> Lean . Enterprise . Middleware
>
>


-- 
Dileepa Jayakody,
Software Engineer, WSO2 Inc.
Lean . Enterprise . Middleware

Re: How to find a class of bundle from Host application?

Posted by Dileepa Jayakody <di...@wso2.com>.
Hi all,

I'm a newbie to OSGI.
Doesn't an osgi bundle act as a normal jar in a non-osgi environment? An
osgi bundle is basically a jar with some additional meta info in it's
manifest which is read by the osgi framework to enable osgi related stuff
from the jar(bundle) as per my understanding.

So, ideally if you add the osgi bundle in the host application's class-path
(which is non-osgi) it will just be considered as a normal jar and it should
be able to import the class from the bundle just like it does from a normal
jar. Did you try adding the jar to your host-application and importing it?
Just a suggestion from a newbie, keen to learn more on osgi.

Thanks,
Dileepa

On Mon, Oct 17, 2011 at 12:14 PM, xuhb <xu...@tongtech.com> wrote:

> Sorry, I  expressed my requirement un-correctly;
>
> Actually, the host application just know the name of class and want to
> choose such class from embedded osgi environment ?
> Could I?
> Must I create a bundle (which import such class) dynamically and retrive
> class from the dynamic created bundle? Is there other facilitate method?
>
> Thanks any suggestion
> ----- Original Message -----
> From: "xuhb" <xu...@tongtech.com>
> To: <us...@felix.apache.org>
> Sent: Monday, October 17, 2011 2:32 PM
> Subject: How to find a class of bundle from Host application?
>
>
> > Hi:
> >    I am using osgi environment (felix) embedded in a Host Application;
> >    Now the host application want to use a class from a specified osgi
> bundle,
> >    Could standard osgi support such usage?
> >    or felix support such extension usage?
> > Thanks any suggestion
>



-- 
Dileepa Jayakody,
Software Engineer, WSO2 Inc.
Lean . Enterprise . Middleware

Re: How to find a class of bundle from Host application?

Posted by xuhb <xu...@tongtech.com>.
Thanks a lot.

We still have some technical "worry" about Glassfish V3;

In order to fullfil our requirement, we need to use the new feature of Glassfish V3 : " using EJB  as osgi bundle";
We belive the OSGI framework is reliable, also we believe j2ee feature of Glassfish are reliable;
But we are worring about if the feature ("EJB as osgi bundle") is reliable or not? 

So we decide to choice a simpled solution to resolve our problem, that's is : 
1)let application act as traditional j2ee application
2)let common service act as osgi services. 
3)Support a proxy for tradition application to retrieve services exits in OSGI;


----- Original Message ----- 
From: "Sahoo" <sa...@oracle.com>
To: <xu...@tongtech.com>
Sent: Thursday, November 03, 2011 5:06 PM
Subject: Re: How to find a class of bundle from Host application?


> On Wednesday 02 November 2011 09:13 AM, xuhb wrote:
>> Also some APPServer( etc: Glassfish) does support OSGI features, but we cannot migrate to such a server.
> Just curious to know the reason for not able to migrate? Are you worried 
> about cost of migrations or incompatibility in feature set or other 
> factors like business requirements?
> 
> Sahoo
>

Re: How to find a class of bundle from Host application?

Posted by xuhb <xu...@tongtech.com>.
Hi, Neil:

Thanks your advise. and I also tried some other mechanism. but they are not so good as OSGI service;
As you have said, "OSGi already provides excellent support for versioning and evolution of services and service APIs without needing to mess around with classloaders." 
Just because OSGI has such advantage, we want to use it as a service provider;

But our real  difficult is "how to share the service of OSGI from outside(the host application), when the interface of service is dynamical loaded, not pre-installed in the host-application"
The host application outside OSGI is a traditional j2ee container. It's hardly be transformed to a bundle.

Also some APPServer( etc: Glassfish) does support OSGI features, but we cannot migrate to such a server.

Is there any good advise?


----- Original Message ----- 
From: "Neil Bartlett" <nj...@gmail.com>
To: <us...@felix.apache.org>
Sent: Tuesday, October 18, 2011 8:47 PM
Subject: Re: How to find a class of bundle from Host application?


> Hi xuhb,
> 
> Sorry but I am not convinced about your need to get the classes from the bundles. OSGi already provides excellent support for versioning and evolution of services and service APIs without needing to mess around with classloaders.
> 
> Other people on this thread have shown you how to do things the way you want to do it. I can't stop you from following those pointers, but I strongly advise you to rethink, learn more about how services work, and try to use them in the way they were intended to be used.
> 
> Rgds,
> Neil
> 
> 
> 
> On Tuesday, 18 October 2011 at 06:27, xuhb wrote:
> 
>> We think highly of the "ligh weight service" usage of osgi; 
>> This is the real reason why we need resolve classes of osgi from host-application;
>> 
>> So we are hoping: if we can build a "light weight service" system based on OSGI, then we can not only achieve benefit of service-orient system, but also we can still using the valuable artifact provided by app-server(etc: web-container, ResourceAdaptor/JCA, TransactionManager, management..)
>> 
>> ----- Original Message ----- 
>> From: "xuhb" <xuhb@tongtech.com (mailto:xuhb@tongtech.com)>
>> To: <users@felix.apache.org (mailto:users@felix.apache.org)>
>> Sent: Tuesday, October 18, 2011 12:35 PM
>> Subject: Re: How to find a class of bundle from Host application?
>> 
>> 
>> > 
>> > ----- Original Message ----- 
>> > From: "Neil Bartlett" <njbartlett@gmail.com (mailto:njbartlett@gmail.com)>
>> > To: <users@felix.apache.org (mailto:users@felix.apache.org)>
>> > Sent: Monday, October 17, 2011 3:46 PM
>> > Subject: Re: How to find a class of bundle from Host application?
>> > 
>> > 
>> > > Could you please explain a little more why you want to do this.
>> > > 
>> > > What you're asking for may be possible, but these kinds of problems can nearly always be solved better using OSGi Services. For example, do you *really* need a class, or do you just need an instance of an object of a particular type?
>> > 
>> > Previously, our application are based on a app-server, business module is implements as Spring/EJB; 
>> > But we have encounter such difficult:
>> > 
>> > 1) When a new version application is update, the user always don't ask for the the new version to replace the old version, but ask for the new and old version system both run for a while simultaneously; Because the different organize of the customer cannot migrate the new version simultaneously;
>> > 
>> > 2) In our application there are always some business logical which should be extract as shared service, but these services also must be versioned;
>> > 
>> > To resolve our practical problem , we need a plugin system, which can contribute services of different version; and the application could choose which one it can use; That's why we need first resolve a classes from osgi before using the osgi service; 
>> > 
>> > If we doesn't just limited in our practical problem, then we want to treat the osgi to act as a "light weight service" system. 
>> > Here "ligh weight service" composed of two part : 1) contract: the java interface; 2) implementation: the osgi service object;
>> > That's to say, we wants:
>> > 
>> > 1) A new "ligh weight service" could be installed at run time and is discovered by client (exist in host-application);
>> >  etc: A jsp could resolve to the java interface of a "light weight service", and invoke the osgi service;
>> > 2) The implementation of "light weight service" can be un-aware to client (exit in host-application). and could be updated dynamically;
>> > 
>> > This is osgi's natual;
>> > 
>> > 3) The update of "light weight service"' could be awared by the client, and re-resolve to it.
>> > This is only used for failure test, becuase updating of contract( the java interface) can cause un-reasonable problem; 
>> > Actually, we just need to know: "contract is update, the client may corrupt" ,and give a report. that's enough;
>> > 
>> > > Rgds
>> > > Neil
>> > > 
>> > > 
>> > > 
>> > > On Monday, 17 October 2011 at 07:44, xuhb wrote:
>> > > 
>> > > > Sorry, I expressed my requirement un-correctly;
>> > > > 
>> > > > Actually, the host application just know the name of class and want to choose such class from embedded osgi environment ?
>> > > > Could I? 
>> > > > Must I create a bundle (which import such class) dynamically and retrive class from the dynamic created bundle? Is there other facilitate method?
>> > > > 
>> > > > Thanks any suggestion
>> > > > ----- Original Message ----- 
>> > > > From: "xuhb" <xuhb@tongtech.com (mailto:xuhb@tongtech.com)>
>> > > > To: <users@felix.apache.org (mailto:users@felix.apache.org)>
>> > > > Sent: Monday, October 17, 2011 2:32 PM
>> > > > Subject: How to find a class of bundle from Host application?
>> > > > 
>> > > > 
>> > > > > Hi:
>> > > > >  I am using osgi environment (felix) embedded in a Host Application; 
>> > > > >  Now the host application want to use a class from a specified osgi bundle, 
>> > > > >  Could standard osgi support such usage? 
>> > > > >  or felix support such extension usage?
>> > > > > Thanks any suggestion
> 
>

Re: How to find a class of bundle from Host application?

Posted by Neil Bartlett <nj...@gmail.com>.
Hi xuhb,

Sorry but I am not convinced about your need to get the classes from the bundles. OSGi already provides excellent support for versioning and evolution of services and service APIs without needing to mess around with classloaders.

Other people on this thread have shown you how to do things the way you want to do it. I can't stop you from following those pointers, but I strongly advise you to rethink, learn more about how services work, and try to use them in the way they were intended to be used.

Rgds,
Neil



On Tuesday, 18 October 2011 at 06:27, xuhb wrote:

> We think highly of the "ligh weight service" usage of osgi; 
> This is the real reason why we need resolve classes of osgi from host-application;
> 
> So we are hoping: if we can build a "light weight service" system based on OSGI, then we can not only achieve benefit of service-orient system, but also we can still using the valuable artifact provided by app-server(etc: web-container, ResourceAdaptor/JCA, TransactionManager, management..)
> 
> ----- Original Message ----- 
> From: "xuhb" <xuhb@tongtech.com (mailto:xuhb@tongtech.com)>
> To: <users@felix.apache.org (mailto:users@felix.apache.org)>
> Sent: Tuesday, October 18, 2011 12:35 PM
> Subject: Re: How to find a class of bundle from Host application?
> 
> 
> > 
> > ----- Original Message ----- 
> > From: "Neil Bartlett" <njbartlett@gmail.com (mailto:njbartlett@gmail.com)>
> > To: <users@felix.apache.org (mailto:users@felix.apache.org)>
> > Sent: Monday, October 17, 2011 3:46 PM
> > Subject: Re: How to find a class of bundle from Host application?
> > 
> > 
> > > Could you please explain a little more why you want to do this.
> > > 
> > > What you're asking for may be possible, but these kinds of problems can nearly always be solved better using OSGi Services. For example, do you *really* need a class, or do you just need an instance of an object of a particular type?
> > 
> > Previously, our application are based on a app-server, business module is implements as Spring/EJB; 
> > But we have encounter such difficult:
> > 
> > 1) When a new version application is update, the user always don't ask for the the new version to replace the old version, but ask for the new and old version system both run for a while simultaneously; Because the different organize of the customer cannot migrate the new version simultaneously;
> > 
> > 2) In our application there are always some business logical which should be extract as shared service, but these services also must be versioned;
> > 
> > To resolve our practical problem , we need a plugin system, which can contribute services of different version; and the application could choose which one it can use; That's why we need first resolve a classes from osgi before using the osgi service; 
> > 
> > If we doesn't just limited in our practical problem, then we want to treat the osgi to act as a "light weight service" system. 
> > Here "ligh weight service" composed of two part : 1) contract: the java interface; 2) implementation: the osgi service object;
> > That's to say, we wants:
> > 
> > 1) A new "ligh weight service" could be installed at run time and is discovered by client (exist in host-application);
> >  etc: A jsp could resolve to the java interface of a "light weight service", and invoke the osgi service;
> > 2) The implementation of "light weight service" can be un-aware to client (exit in host-application). and could be updated dynamically;
> > 
> > This is osgi's natual;
> > 
> > 3) The update of "light weight service"' could be awared by the client, and re-resolve to it.
> > This is only used for failure test, becuase updating of contract( the java interface) can cause un-reasonable problem; 
> > Actually, we just need to know: "contract is update, the client may corrupt" ,and give a report. that's enough;
> > 
> > > Rgds
> > > Neil
> > > 
> > > 
> > > 
> > > On Monday, 17 October 2011 at 07:44, xuhb wrote:
> > > 
> > > > Sorry, I expressed my requirement un-correctly;
> > > > 
> > > > Actually, the host application just know the name of class and want to choose such class from embedded osgi environment ?
> > > > Could I? 
> > > > Must I create a bundle (which import such class) dynamically and retrive class from the dynamic created bundle? Is there other facilitate method?
> > > > 
> > > > Thanks any suggestion
> > > > ----- Original Message ----- 
> > > > From: "xuhb" <xuhb@tongtech.com (mailto:xuhb@tongtech.com)>
> > > > To: <users@felix.apache.org (mailto:users@felix.apache.org)>
> > > > Sent: Monday, October 17, 2011 2:32 PM
> > > > Subject: How to find a class of bundle from Host application?
> > > > 
> > > > 
> > > > > Hi:
> > > > >  I am using osgi environment (felix) embedded in a Host Application; 
> > > > >  Now the host application want to use a class from a specified osgi bundle, 
> > > > >  Could standard osgi support such usage? 
> > > > >  or felix support such extension usage?
> > > > > Thanks any suggestion


Re: How to find a class of bundle from Host application?

Posted by xuhb <xu...@tongtech.com>.
We think highly of the "ligh weight service" usage of osgi; 
This is the real reason why we need resolve classes of osgi from host-application;

So we are hoping: if we can build a "light weight service" system based on OSGI, then we can not only achieve benefit of  service-orient system, but also we can still using the valuable artifact provided by app-server(etc: web-container, ResourceAdaptor/JCA, TransactionManager, management..)

----- Original Message ----- 
From: "xuhb" <xu...@tongtech.com>
To: <us...@felix.apache.org>
Sent: Tuesday, October 18, 2011 12:35 PM
Subject: Re: How to find a class of bundle from Host application?


> 
> ----- Original Message ----- 
> From: "Neil Bartlett" <nj...@gmail.com>
> To: <us...@felix.apache.org>
> Sent: Monday, October 17, 2011 3:46 PM
> Subject: Re: How to find a class of bundle from Host application?
> 
> 
>> Could you please explain a little more why you want to do this.
>> 
>> What you're asking for may be possible, but these kinds of problems can nearly always be solved better using OSGi Services. For example, do you *really* need a class, or do you just need an instance of an object of a particular type?
> 
> Previously, our application are based on a app-server,  business module is implements as Spring/EJB;  
> But we have encounter such difficult:
> 
> 1) When a new version application is update,  the user always don't ask for the the new version to replace the old version, but ask for the new and old version system both run for a while simultaneously; Because the different organize of the customer cannot migrate the new version simultaneously;
> 
> 2) In our application there are always some business logical which should be extract as shared service, but these services also must be versioned;
> 
> To resolve our practical problem , we need a plugin system, which can contribute services of different version; and the application could choose which one it can use; That's why we need first resolve a  classes from osgi  before using the osgi service;  
> 
> If we doesn't just limited in our practical problem, then we want to treat the osgi to act as a "light weight service" system. 
> Here "ligh weight service" composed of two part : 1) contract: the java interface; 2) implementation: the osgi service object;
> That's to say, we wants:
> 
> 1)  A new "ligh weight service" could be installed at run time and is discovered by  client (exist in host-application);
>    etc: A jsp could resolve to the java interface of a "light weight service", and invoke the osgi service;
> 2) The  implementation of "light weight service" can be un-aware to client (exit in host-application). and could be updated dynamically;
> 
> This is osgi's natual;
> 
> 3) The update of "light weight service"' could be awared by the client, and re-resolve to it.
> This is only used for failure test, becuase updating of contract( the java interface) can cause un-reasonable problem; 
> Actually, we just need to know: "contract is update, the client may corrupt" ,and give a report. that's enough;
> 
>> Rgds
>> Neil
>> 
>> 
>> 
>> On Monday, 17 October 2011 at 07:44, xuhb wrote:
>> 
>>> Sorry, I expressed my requirement un-correctly;
>>> 
>>> Actually, the host application just know the name of class and want to choose such class from embedded osgi environment ?
>>> Could I? 
>>> Must I create a bundle (which import such class) dynamically and retrive class from the dynamic created bundle? Is there other facilitate method?
>>> 
>>> Thanks any suggestion
>>> ----- Original Message ----- 
>>> From: "xuhb" <xuhb@tongtech.com (mailto:xuhb@tongtech.com)>
>>> To: <users@felix.apache.org (mailto:users@felix.apache.org)>
>>> Sent: Monday, October 17, 2011 2:32 PM
>>> Subject: How to find a class of bundle from Host application?
>>> 
>>> 
>>> > Hi:
>>> >  I am using osgi environment (felix) embedded in a Host Application; 
>>> >  Now the host application want to use a class from a specified osgi bundle, 
>>> >  Could standard osgi support such usage? 
>>> >  or felix support such extension usage?
>>> > Thanks any suggestion
>> 
>>

Re: How to find a class of bundle from Host application?

Posted by xuhb <xu...@tongtech.com>.
----- Original Message ----- 
From: "Neil Bartlett" <nj...@gmail.com>
To: <us...@felix.apache.org>
Sent: Monday, October 17, 2011 3:46 PM
Subject: Re: How to find a class of bundle from Host application?


> Could you please explain a little more why you want to do this.
> 
> What you're asking for may be possible, but these kinds of problems can nearly always be solved better using OSGi Services. For example, do you *really* need a class, or do you just need an instance of an object of a particular type?

Previously, our application are based on a app-server,  business module is implements as Spring/EJB;  
But we have encounter such difficult:

1) When a new version application is update,  the user always don't ask for the the new version to replace the old version, but ask for the new and old version system both run for a while simultaneously; Because the different organize of the customer cannot migrate the new version simultaneously;

2) In our application there are always some business logical which should be extract as shared service, but these services also must be versioned;

To resolve our practical problem , we need a plugin system, which can contribute services of different version; and the application could choose which one it can use; That's why we need first resolve a  classes from osgi  before using the osgi service;  

If we doesn't just limited in our practical problem, then we want to treat the osgi to act as a "light weight service" system. 
Here "ligh weight service" composed of two part : 1) contract: the java interface; 2) implementation: the osgi service object;
That's to say, we wants:

1)  A new "ligh weight service" could be installed at run time and is discovered by  client (exist in host-application);
    etc: A jsp could resolve to the java interface of a "light weight service", and invoke the osgi service;
2) The  implementation of "light weight service" can be un-aware to client (exit in host-application). and could be updated dynamically;

This is osgi's natual;

3) The update of "light weight service"' could be awared by the client, and re-resolve to it.
This is only used for failure test, becuase updating of contract( the java interface) can cause un-reasonable problem; 
Actually, we just need to know: "contract is update, the client may corrupt" ,and give a report. that's enough;
 
> Rgds
> Neil
> 
> 
> 
> On Monday, 17 October 2011 at 07:44, xuhb wrote:
> 
>> Sorry, I expressed my requirement un-correctly;
>> 
>> Actually, the host application just know the name of class and want to choose such class from embedded osgi environment ?
>> Could I? 
>> Must I create a bundle (which import such class) dynamically and retrive class from the dynamic created bundle? Is there other facilitate method?
>> 
>> Thanks any suggestion
>> ----- Original Message ----- 
>> From: "xuhb" <xuhb@tongtech.com (mailto:xuhb@tongtech.com)>
>> To: <users@felix.apache.org (mailto:users@felix.apache.org)>
>> Sent: Monday, October 17, 2011 2:32 PM
>> Subject: How to find a class of bundle from Host application?
>> 
>> 
>> > Hi:
>> >  I am using osgi environment (felix) embedded in a Host Application; 
>> >  Now the host application want to use a class from a specified osgi bundle, 
>> >  Could standard osgi support such usage? 
>> >  or felix support such extension usage?
>> > Thanks any suggestion
> 
>

Re: How to find a class of bundle from Host application?

Posted by Neil Bartlett <nj...@gmail.com>.
Could you please explain a little more why you want to do this.

What you're asking for may be possible, but these kinds of problems can nearly always be solved better using OSGi Services. For example, do you *really* need a class, or do you just need an instance of an object of a particular type?

Rgds
Neil



On Monday, 17 October 2011 at 07:44, xuhb wrote:

> Sorry, I expressed my requirement un-correctly;
> 
> Actually, the host application just know the name of class and want to choose such class from embedded osgi environment ?
> Could I? 
> Must I create a bundle (which import such class) dynamically and retrive class from the dynamic created bundle? Is there other facilitate method?
> 
> Thanks any suggestion
> ----- Original Message ----- 
> From: "xuhb" <xuhb@tongtech.com (mailto:xuhb@tongtech.com)>
> To: <users@felix.apache.org (mailto:users@felix.apache.org)>
> Sent: Monday, October 17, 2011 2:32 PM
> Subject: How to find a class of bundle from Host application?
> 
> 
> > Hi:
> >  I am using osgi environment (felix) embedded in a Host Application; 
> >  Now the host application want to use a class from a specified osgi bundle, 
> >  Could standard osgi support such usage? 
> >  or felix support such extension usage?
> > Thanks any suggestion


Re: How to find a class of bundle from Host application?

Posted by xuhb <xu...@tongtech.com>.
Sorry, I  expressed my requirement un-correctly;

Actually, the host application just know the name of class and want to choose such class from embedded osgi environment ?
Could I? 
Must I create a bundle (which import such class) dynamically and retrive class from the dynamic created bundle? Is there other facilitate method?

Thanks any suggestion
----- Original Message ----- 
From: "xuhb" <xu...@tongtech.com>
To: <us...@felix.apache.org>
Sent: Monday, October 17, 2011 2:32 PM
Subject: How to find a class of bundle from Host application?


> Hi:
>    I am using osgi environment (felix) embedded in a Host Application; 
>    Now the host application want to use a class from a specified osgi bundle, 
>    Could standard osgi support such usage? 
>    or felix support such extension usage?
> Thanks any suggestion