You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Brendan Haverlock <br...@webreachinc.com> on 2009/04/17 20:03:57 UTC

Migrating a UI to OSGI

Hi all,

 

I am currently migrating our application to use the OSGI framework on both
the client and server programs.  The server portion of the program was
relatively straightforward, however, I am having some difficulties adapting
OSGI to the client architecture.  Basically, I've refactored every client
package to expose its own service.  However, there are so many GUI classes
and components that have dependencies to other services that I don't really
know what to do.  I don't want to make every UI component its own service
because I know there has to be a better way.  Is there a way to specify that
a component is a dependency and needs the service injection into one of its
fields, but it isn't a service itself?  Right now, I am creating my service
dependencies as follows:

 

public class UserBundleActivator extends DependencyActivatorBase {

 

    public void init(BundleContext context, DependencyManager manager)
throws Exception {

      Service svc;

      

      // Service implementations

            

      svc = createService().setInterface(UserService.class.getName(),
null).setImplementation(UserServiceImpl.class);

 
svc.add(createServiceDependency().setService(CoreService.class).setRequired(
true));

 
svc.add(createServiceDependency().setService(ExtensionService.class).setRequ
ired(true));

      manager.add(svc);

        

      // Non-service dependencies

 

      // UI component dependencies here?

}

 

Please help because I know there has to be a better way.

 

Thank you!

 

Brendan Haverlock

 


RE: Migrating a UI to OSGI

Posted by Brendan Haverlock <br...@webreachinc.com>.
Is there a way I can just ask the service registry for the implementations
of the services in these non-service UI classes instead of trying to inject
them?  If I can set the fields manually from the registry, then everything
will work fine.  Otherwise, I can't see this ever working because all the
constructors in my UI components need to use the other services to gain
access to components to, for example, set the owning JFrame.  

Thanks!

Brendan Haverlock

-----Original Message-----
From: Dennis Geurts [mailto:dennis.geurts@luminis.nl] 
Sent: Friday, April 17, 2009 1:56 PM
To: users@felix.apache.org
Subject: Re: Migrating a UI to OSGI


Thanks Marcel; I didn't know that ! lol, never considered NOT setting an
interface...

dennis

On 17 apr 2009, at 22:49, Marcel Offermans wrote:

> Hello Brendan, Dennis,
>
> On Apr 17, 2009, at 21:50 , Dennis Geurts wrote:
>
>> one little pointer: Since you are using the dependency manager;
>>
>> you do not necessarily need to call 'manager.add(svc)' to instigate 
>> the dependency injection,
>>
>> it suffices to call svc.start(), thus, your ui components are NOT 
>> registered as services, but DO get injected with the dependencies you 
>> define...
>
> This is not entirely correct, Dennis. You should add services to the 
> manager, and not start them yourselves. If a service does not define 
> an interface, ie there is no .setInterface() call, then no service 
> will be published.
>
>>> I am currently migrating our application to use the OSGI framework 
>>> on both the client and server programs.  The server portion of the 
>>> program was relatively straightforward, however, I am having some 
>>> difficulties adapting OSGI to the client architecture.  Basically, 
>>> I've refactored every client package to expose its own service.  
>>> However, there are so many GUI classes and components that have 
>>> dependencies to other services that I don't really know what to do.  
>>> I don't want to make every UI component its own service because I 
>>> know there has to be a better way.  Is there a way to specify that a 
>>> component is a dependency and needs the service injection into one 
>>> of its fields, but it isn't a service itself?
>
> Yes, there is a way to inject depencencies into a whole collection of 
> objects, if that collection itself remains unchanged.
>
> Check out this page:
>
> http://felix.apache.org/site/dependency-manager-usage.html
>
> specifically, look at the "Using compositions" part. Say you have a 
> UI, which is basically build out of a big tree of components, then you 
> can inject dependencies into all those components by having that
> getInstance() call return all of them.
>
> Greetings, Marcel
>
>
> ---------------------------------------------------------------------
> 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: Migrating a UI to OSGI

Posted by Marcel Offermans <ma...@luminis.nl>.
No problem, that should work. The setInstance() method takes either a  
Class (which it then lazily instantiates) or some Object instance  
(which it will use directly).

On Apr 20, 2009, at 21:12 , Brendan Haverlock wrote:

> Oh no, I just reread your post and saw the setImplementation()  
> method using
> the getInstance().  Doh, my mistake.  I'll try this and let you know  
> how it
> works.
>
> On Mon, Apr 20, 2009 at 12:08 PM, Brendan Haverlock <
> brendanh@webreachinc.com> wrote:
>
>> Marcel,
>>
>> There is a bit of a problem with your approach.
>>
>> Dependency manager makes its own instance of Services.class when it
>> registers it as a server and uses this class to inject the service
>> references.  So, every time I try to make a reference to the  
>> singleton, as
>> you can imagine, all the services are null.  I was wondering what  
>> OSGi
>> magic
>> you could give me to get around this. I even tried to make the  
>> service
>> references static and had no avail.
>>
>> Thanks again for you help!
>>
>> Brendan Haverlock
>>
>> -----Original Message-----
>> From: Marcel Offermans [mailto:marcel.offermans@luminis.nl]
>> Sent: Friday, April 17, 2009 2:38 PM
>> To: users@felix.apache.org
>> Subject: Re: Migrating a UI to OSGI
>>
>> On Apr 17, 2009, at 23:19 , Brendan Haverlock wrote:
>>
>>> Thanks for the replies guys!
>>
>> You're welcome.
>>
>>> Well, this is so odd though because I mean a lot of my components
>>> take in
>>> parameters to the constructor and I don't just have one instance of
>>> that
>>> component.  I make multiple components based on what params are
>>> passed in.
>>> Setting the implementation class will just inject into one instance
>>> of these
>>> classes.  And, a lot of times these UI components need to make calls
>>> to
>>> other services from their constructor, so adding them to the manager
>>> breaks
>>> them because the other services aren't injected at that point.
>>
>> Another way is to have one "singleton" in your bundle that has all
>> service references. A singleton inside an OSGi bundle will be local  
>> to
>> that bundle, and if you don't export it, nobody else can see it, so
>> from a design point of view it's not that bad.
>>
>> So start with something like:
>>
>> manager
>> .add 
>> (createService().setImplementation(Services.getInstance()).add( /*
>> all dependencies you need */ ));
>>
>> and have a Services class something like:
>>
>> public class Services {
>>  public static Services instance;
>>  public static Services getInstance() { /* implement singleton here
>> */ };
>>  public volatile MyFirstInjectedService m_s1;
>>  public volatile MySecondInjectedService m_s2; // etc..
>> }
>>
>> and use them in your Swing components like this:
>>
>>  Services.getInstance().m_s1.invokeSomeMethod();
>>
>> Greetings, Marcel
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>>
>
>
> -- 
> Brendan Haverlock
> WebReach, Inc.
> Work: 949-255-5054
> AIM: wr brendanh


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


Re: Migrating a UI to OSGI

Posted by Brendan Haverlock <br...@webreachinc.com>.
Oh no, I just reread your post and saw the setImplementation() method using
the getInstance().  Doh, my mistake.  I'll try this and let you know how it
works.

On Mon, Apr 20, 2009 at 12:08 PM, Brendan Haverlock <
brendanh@webreachinc.com> wrote:

> Marcel,
>
> There is a bit of a problem with your approach.
>
> Dependency manager makes its own instance of Services.class when it
> registers it as a server and uses this class to inject the service
> references.  So, every time I try to make a reference to the singleton, as
> you can imagine, all the services are null.  I was wondering what OSGi
> magic
> you could give me to get around this. I even tried to make the service
> references static and had no avail.
>
> Thanks again for you help!
>
> Brendan Haverlock
>
> -----Original Message-----
> From: Marcel Offermans [mailto:marcel.offermans@luminis.nl]
> Sent: Friday, April 17, 2009 2:38 PM
> To: users@felix.apache.org
> Subject: Re: Migrating a UI to OSGI
>
> On Apr 17, 2009, at 23:19 , Brendan Haverlock wrote:
>
> > Thanks for the replies guys!
>
> You're welcome.
>
> > Well, this is so odd though because I mean a lot of my components
> > take in
> > parameters to the constructor and I don't just have one instance of
> > that
> > component.  I make multiple components based on what params are
> > passed in.
> > Setting the implementation class will just inject into one instance
> > of these
> > classes.  And, a lot of times these UI components need to make calls
> > to
> > other services from their constructor, so adding them to the manager
> > breaks
> > them because the other services aren't injected at that point.
>
> Another way is to have one "singleton" in your bundle that has all
> service references. A singleton inside an OSGi bundle will be local to
> that bundle, and if you don't export it, nobody else can see it, so
> from a design point of view it's not that bad.
>
> So start with something like:
>
> manager
> .add(createService().setImplementation(Services.getInstance()).add( /*
> all dependencies you need */ ));
>
> and have a Services class something like:
>
> public class Services {
>   public static Services instance;
>   public static Services getInstance() { /* implement singleton here
> */ };
>   public volatile MyFirstInjectedService m_s1;
>   public volatile MySecondInjectedService m_s2; // etc..
> }
>
> and use them in your Swing components like this:
>
>   Services.getInstance().m_s1.invokeSomeMethod();
>
> Greetings, Marcel
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
>


-- 
Brendan Haverlock
WebReach, Inc.
Work: 949-255-5054
AIM: wr brendanh

RE: Migrating a UI to OSGI

Posted by Brendan Haverlock <br...@webreachinc.com>.
Marcel,

There is a bit of a problem with your approach.

Dependency manager makes its own instance of Services.class when it
registers it as a server and uses this class to inject the service
references.  So, every time I try to make a reference to the singleton, as
you can imagine, all the services are null.  I was wondering what OSGi magic
you could give me to get around this. I even tried to make the service
references static and had no avail.

Thanks again for you help!

Brendan Haverlock

-----Original Message-----
From: Marcel Offermans [mailto:marcel.offermans@luminis.nl] 
Sent: Friday, April 17, 2009 2:38 PM
To: users@felix.apache.org
Subject: Re: Migrating a UI to OSGI

On Apr 17, 2009, at 23:19 , Brendan Haverlock wrote:

> Thanks for the replies guys!

You're welcome.

> Well, this is so odd though because I mean a lot of my components  
> take in
> parameters to the constructor and I don't just have one instance of  
> that
> component.  I make multiple components based on what params are  
> passed in.
> Setting the implementation class will just inject into one instance  
> of these
> classes.  And, a lot of times these UI components need to make calls  
> to
> other services from their constructor, so adding them to the manager  
> breaks
> them because the other services aren't injected at that point.

Another way is to have one "singleton" in your bundle that has all  
service references. A singleton inside an OSGi bundle will be local to  
that bundle, and if you don't export it, nobody else can see it, so  
from a design point of view it's not that bad.

So start with something like:

manager 
.add(createService().setImplementation(Services.getInstance()).add( /*  
all dependencies you need */ ));

and have a Services class something like:

public class Services {
   public static Services instance;
   public static Services getInstance() { /* implement singleton here  
*/ };
   public volatile MyFirstInjectedService m_s1;
   public volatile MySecondInjectedService m_s2; // etc..
}

and use them in your Swing components like this:

   Services.getInstance().m_s1.invokeSomeMethod();

Greetings, Marcel


---------------------------------------------------------------------
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: Migrating a UI to OSGI

Posted by Brendan Haverlock <br...@webreachinc.com>.
Marcel, thanks a bunch!  I can just make a Services.java for each of the
bundles and just put all the possible services that the bundle needs there.
That way I am still using OSGI to populate those services to ensure the
dependencies but then I don't have to worry about them in the actual UI
components.  Just in time too because I was about to revert everything and
say it was a lost cause and roll my own services registry for the client.

Brendan Haverlock
WebReach, Inc.
Software Engineer
Work: 949-255-5054
AIM: wr brendanh


-----Original Message-----
From: Marcel Offermans [mailto:marcel.offermans@luminis.nl] 
Sent: Friday, April 17, 2009 2:38 PM
To: users@felix.apache.org
Subject: Re: Migrating a UI to OSGI

On Apr 17, 2009, at 23:19 , Brendan Haverlock wrote:

> Thanks for the replies guys!

You're welcome.

> Well, this is so odd though because I mean a lot of my components  
> take in
> parameters to the constructor and I don't just have one instance of  
> that
> component.  I make multiple components based on what params are  
> passed in.
> Setting the implementation class will just inject into one instance  
> of these
> classes.  And, a lot of times these UI components need to make calls  
> to
> other services from their constructor, so adding them to the manager  
> breaks
> them because the other services aren't injected at that point.

Another way is to have one "singleton" in your bundle that has all  
service references. A singleton inside an OSGi bundle will be local to  
that bundle, and if you don't export it, nobody else can see it, so  
from a design point of view it's not that bad.

So start with something like:

manager 
.add(createService().setImplementation(Services.getInstance()).add( /*  
all dependencies you need */ ));

and have a Services class something like:

public class Services {
   public static Services instance;
   public static Services getInstance() { /* implement singleton here  
*/ };
   public volatile MyFirstInjectedService m_s1;
   public volatile MySecondInjectedService m_s2; // etc..
}

and use them in your Swing components like this:

   Services.getInstance().m_s1.invokeSomeMethod();

Greetings, Marcel


---------------------------------------------------------------------
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: Migrating a UI to OSGI

Posted by Marcel Offermans <ma...@luminis.nl>.
On Apr 17, 2009, at 23:19 , Brendan Haverlock wrote:

> Thanks for the replies guys!

You're welcome.

> Well, this is so odd though because I mean a lot of my components  
> take in
> parameters to the constructor and I don't just have one instance of  
> that
> component.  I make multiple components based on what params are  
> passed in.
> Setting the implementation class will just inject into one instance  
> of these
> classes.  And, a lot of times these UI components need to make calls  
> to
> other services from their constructor, so adding them to the manager  
> breaks
> them because the other services aren't injected at that point.

Another way is to have one "singleton" in your bundle that has all  
service references. A singleton inside an OSGi bundle will be local to  
that bundle, and if you don't export it, nobody else can see it, so  
from a design point of view it's not that bad.

So start with something like:

manager 
.add(createService().setImplementation(Services.getInstance()).add( /*  
all dependencies you need */ ));

and have a Services class something like:

public class Services {
   public static Services instance;
   public static Services getInstance() { /* implement singleton here  
*/ };
   public volatile MyFirstInjectedService m_s1;
   public volatile MySecondInjectedService m_s2; // etc..
}

and use them in your Swing components like this:

   Services.getInstance().m_s1.invokeSomeMethod();

Greetings, Marcel


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


RE: Migrating a UI to OSGI

Posted by Brendan Haverlock <br...@webreachinc.com>.
Thanks for the replies guys! 

Well, this is so odd though because I mean a lot of my components take in
parameters to the constructor and I don't just have one instance of that
component.  I make multiple components based on what params are passed in.
Setting the implementation class will just inject into one instance of these
classes.  And, a lot of times these UI components need to make calls to
other services from their constructor, so adding them to the manager breaks
them because the other services aren't injected at that point.

Brendan Haverlock
WebReach, Inc.
Software Engineer
Work: 949-255-5054
AIM: wr brendanh

-----Original Message-----
From: Dennis Geurts [mailto:dennis.geurts@luminis.nl] 
Sent: Friday, April 17, 2009 1:56 PM
To: users@felix.apache.org
Subject: Re: Migrating a UI to OSGI


Thanks Marcel; I didn't know that ! lol, never considered NOT setting an
interface...

dennis

On 17 apr 2009, at 22:49, Marcel Offermans wrote:

> Hello Brendan, Dennis,
>
> On Apr 17, 2009, at 21:50 , Dennis Geurts wrote:
>
>> one little pointer: Since you are using the dependency manager;
>>
>> you do not necessarily need to call 'manager.add(svc)' to instigate 
>> the dependency injection,
>>
>> it suffices to call svc.start(), thus, your ui components are NOT 
>> registered as services, but DO get injected with the dependencies you 
>> define...
>
> This is not entirely correct, Dennis. You should add services to the 
> manager, and not start them yourselves. If a service does not define 
> an interface, ie there is no .setInterface() call, then no service 
> will be published.
>
>>> I am currently migrating our application to use the OSGI framework 
>>> on both the client and server programs.  The server portion of the 
>>> program was relatively straightforward, however, I am having some 
>>> difficulties adapting OSGI to the client architecture.  Basically, 
>>> I've refactored every client package to expose its own service.  
>>> However, there are so many GUI classes and components that have 
>>> dependencies to other services that I don't really know what to do.  
>>> I don't want to make every UI component its own service because I 
>>> know there has to be a better way.  Is there a way to specify that a 
>>> component is a dependency and needs the service injection into one 
>>> of its fields, but it isn't a service itself?
>
> Yes, there is a way to inject depencencies into a whole collection of 
> objects, if that collection itself remains unchanged.
>
> Check out this page:
>
> http://felix.apache.org/site/dependency-manager-usage.html
>
> specifically, look at the "Using compositions" part. Say you have a 
> UI, which is basically build out of a big tree of components, then you 
> can inject dependencies into all those components by having that
> getInstance() call return all of them.
>
> Greetings, Marcel
>
>
> ---------------------------------------------------------------------
> 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: Migrating a UI to OSGI

Posted by Dennis Geurts <de...@luminis.nl>.
Thanks Marcel; I didn't know that ! lol, never considered NOT setting  
an interface...

dennis

On 17 apr 2009, at 22:49, Marcel Offermans wrote:

> Hello Brendan, Dennis,
>
> On Apr 17, 2009, at 21:50 , Dennis Geurts wrote:
>
>> one little pointer: Since you are using the dependency manager;
>>
>> you do not necessarily need to call 'manager.add(svc)' to instigate
>> the dependency injection,
>>
>> it suffices to call svc.start(), thus, your ui components are NOT
>> registered as services, but DO get injected
>> with the dependencies you define...
>
> This is not entirely correct, Dennis. You should add services to the
> manager, and not start them yourselves. If a service does not define
> an interface, ie there is no .setInterface() call, then no service
> will be published.
>
>>> I am currently migrating our application to use the OSGI framework
>>> on both
>>> the client and server programs.  The server portion of the program
>>> was
>>> relatively straightforward, however, I am having some difficulties
>>> adapting
>>> OSGI to the client architecture.  Basically, I've refactored every
>>> client
>>> package to expose its own service.  However, there are so many GUI
>>> classes
>>> and components that have dependencies to other services that I
>>> don't really
>>> know what to do.  I don't want to make every UI component its own
>>> service
>>> because I know there has to be a better way.  Is there a way to
>>> specify that
>>> a component is a dependency and needs the service injection into
>>> one of its
>>> fields, but it isn't a service itself?
>
> Yes, there is a way to inject depencencies into a whole collection of
> objects, if that collection itself remains unchanged.
>
> Check out this page:
>
> http://felix.apache.org/site/dependency-manager-usage.html
>
> specifically, look at the "Using compositions" part. Say you have a
> UI, which is basically build out of a big tree of components, then you
> can inject dependencies into all those components by having that
> getInstance() call return all of them.
>
> Greetings, Marcel
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>


Re: Migrating a UI to OSGI

Posted by Marcel Offermans <ma...@luminis.nl>.
Hello Brendan, Dennis,

On Apr 17, 2009, at 21:50 , Dennis Geurts wrote:

> one little pointer: Since you are using the dependency manager;
>
> you do not necessarily need to call 'manager.add(svc)' to instigate  
> the dependency injection,
>
> it suffices to call svc.start(), thus, your ui components are NOT  
> registered as services, but DO get injected
> with the dependencies you define...

This is not entirely correct, Dennis. You should add services to the  
manager, and not start them yourselves. If a service does not define  
an interface, ie there is no .setInterface() call, then no service  
will be published.

>> I am currently migrating our application to use the OSGI framework  
>> on both
>> the client and server programs.  The server portion of the program  
>> was
>> relatively straightforward, however, I am having some difficulties  
>> adapting
>> OSGI to the client architecture.  Basically, I've refactored every  
>> client
>> package to expose its own service.  However, there are so many GUI  
>> classes
>> and components that have dependencies to other services that I  
>> don't really
>> know what to do.  I don't want to make every UI component its own  
>> service
>> because I know there has to be a better way.  Is there a way to  
>> specify that
>> a component is a dependency and needs the service injection into  
>> one of its
>> fields, but it isn't a service itself?

Yes, there is a way to inject depencencies into a whole collection of  
objects, if that collection itself remains unchanged.

Check out this page:

http://felix.apache.org/site/dependency-manager-usage.html

specifically, look at the "Using compositions" part. Say you have a  
UI, which is basically build out of a big tree of components, then you  
can inject dependencies into all those components by having that  
getInstance() call return all of them.

Greetings, Marcel


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


Re: Migrating a UI to OSGI

Posted by Marcel Offermans <ma...@luminis.nl>.
On Apr 17, 2009, at 22:39 , Brendan Haverlock wrote:

> Thanks Dennis!  That does make some sense, but isn’t it still silly  
> to have to implement all those methods (init, start, stop) on simple  
> swing components?

Those life cycle methods are optional. You do not need to implement  
them. If you don't need them, and they're not there, then nothing will  
be invoked. That's probably fine for Swing components.

For the rest, see my earlier mail.

Greetings, Marcel


RE: Migrating a UI to OSGI

Posted by Brendan Haverlock <br...@webreachinc.com>.
Thanks Dennis!  That does make some sense, but isn't it still silly to have
to implement all those methods (init, start, stop) on simple swing
components?

 

Or, do I just implement the start() method since I'm not going to be adding
it to the manager, and then put the code that I use to initialize the swing
component there instead of the current method?

 

I just want to make sure that I do this the "right" way.

 

Brendan Haverlock

 

From: Dennis Geurts [mailto:dennis.geurts@luminis.nl] 
Sent: Friday, April 17, 2009 12:50 PM
To: users@felix.apache.org
Subject: Re: Migrating a UI to OSGI

 

 

Hi Brendan,

 

 

Good to see you are using the dependency manager!

 

The choices you need to make are indeed difficult, so there others might
have more to say about that.

 

one little pointer: Since you are using the dependency manager; 

 

you do not necessarily need to call 'manager.add(svc)' to instigate the
dependency injection, 

 

it suffices to call svc.start(), thus, your ui components are NOT registered
as services, but DO get injected

with the dependencies you define...

 

 

Regards, Dennis

 

 

 

On 17 apr 2009, at 20:03, Brendan Haverlock wrote:





Hi all,



I am currently migrating our application to use the OSGI framework on both
the client and server programs.  The server portion of the program was
relatively straightforward, however, I am having some difficulties adapting
OSGI to the client architecture.  Basically, I've refactored every client
package to expose its own service.  However, there are so many GUI classes
and components that have dependencies to other services that I don't really
know what to do.  I don't want to make every UI component its own service
because I know there has to be a better way.  Is there a way to specify that
a component is a dependency and needs the service injection into one of its
fields, but it isn't a service itself?  Right now, I am creating my service
dependencies as follows:



public class UserBundleActivator extends DependencyActivatorBase {



   public void init(BundleContext context, DependencyManager manager)
throws Exception {

     Service svc;



     // Service implementations



     svc = createService().setInterface(UserService.class.getName(),
null).setImplementation(UserServiceImpl.class);


svc.add(createServiceDependency().setService(CoreService.class).setRequired(
true));


svc.add(createServiceDependency().setService(ExtensionService.class).setRequ
ired(true));

     manager.add(svc);



     // Non-service dependencies



     // UI component dependencies here?

}



Please help because I know there has to be a better way.



Thank you!



Brendan Haverlock




 



No trees were killed in the sending of this message. However, a large number
of electrons were terribly disturbed!
-------------------------------------------------
Dennis Geurts
luminis

iQ Products B.V.

K.v.k Centraal Gelderland: 09 16 28 93
-------------------------------------------------
+31 6 12078236
dennis.geurts@luminis.nl
www.luminis.nl <http://www.luminis.nl/> 
-------------------------------------------------

 


Re: Migrating a UI to OSGI

Posted by Dennis Geurts <de...@luminis.nl>.
Hi Brendan,


Good to see you are using the dependency manager!

The choices you need to make are indeed difficult, so there others  
might have more to say about that.

one little pointer: Since you are using the dependency manager;

you do not necessarily need to call 'manager.add(svc)' to instigate  
the dependency injection,

it suffices to call svc.start(), thus, your ui components are NOT  
registered as services, but DO get injected
with the dependencies you define...


Regards, Dennis



On 17 apr 2009, at 20:03, Brendan Haverlock wrote:

> Hi all,
>
>
>
> I am currently migrating our application to use the OSGI framework  
> on both
> the client and server programs.  The server portion of the program was
> relatively straightforward, however, I am having some difficulties  
> adapting
> OSGI to the client architecture.  Basically, I've refactored every  
> client
> package to expose its own service.  However, there are so many GUI  
> classes
> and components that have dependencies to other services that I don't  
> really
> know what to do.  I don't want to make every UI component its own  
> service
> because I know there has to be a better way.  Is there a way to  
> specify that
> a component is a dependency and needs the service injection into one  
> of its
> fields, but it isn't a service itself?  Right now, I am creating my  
> service
> dependencies as follows:
>
>
>
> public class UserBundleActivator extends DependencyActivatorBase {
>
>
>
>    public void init(BundleContext context, DependencyManager manager)
> throws Exception {
>
>      Service svc;
>
>
>
>      // Service implementations
>
>
>
>      svc = createService().setInterface(UserService.class.getName(),
> null).setImplementation(UserServiceImpl.class);
>
>
> svc 
> .add 
> (createServiceDependency().setService(CoreService.class).setRequired(
> true));
>
>
> svc 
> .add 
> (createServiceDependency().setService(ExtensionService.class).setRequ
> ired(true));
>
>      manager.add(svc);
>
>
>
>      // Non-service dependencies
>
>
>
>      // UI component dependencies here?
>
> }
>
>
>
> Please help because I know there has to be a better way.
>
>
>
> Thank you!
>
>
>
> Brendan Haverlock
>
>
>



No trees were killed in the sending of this message. However, a large  
number of electrons were terribly disturbed!
-------------------------------------------------
Dennis Geurts
luminis
iQ Products B.V.
K.v.k Centraal Gelderland: 09 16 28 93
-------------------------------------------------
+31 6 12078236
dennis.geurts@luminis.nl
www.luminis.nl
-------------------------------------------------