Home » Eclipse Projects » Equinox » Extension Points conversion to OSGI Service Registry
Extension Points conversion to OSGI Service Registry [message #70136] |
Mon, 17 July 2006 15:58 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: lamont_gilbert.rigidsoftware.com
I have an application that uses extension points. one plugin exposes an
extension point and two other plugins implement them. Its discovered at
runtime and the user can select which implementation he wishes to use.
Now I understand there are OSGI services and this is the OSGI way to do it
and Eclipse is becoming more OSGI so I should probably do it that way.
From what I have gathered I will need the Declarative Service so I can
register the implementations. Then at runtime just ask the bundlecontext
for all implementations and go from there.
Is this right? I really have not been able to find any information on
Eclipse website about how to implement an OSGI service. I saw some
powerpoint slides, but it was a rather incomplete example and not very
clear without the talking I suppose.
Is there a resource to learn how to use Eclipse OSGI service registry?
--
Respectfully,
CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into the
sheepfold{}, but climbeth up some other *way, the same is a thief and a
robber."
|
|
|
Re: Extension Points conversion to OSGI Service Registry [message #70260 is a reply to message #70136] |
Tue, 18 July 2006 16:21 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: neil.integility.com
Hi CL,
> Now I understand there are OSGI services and this is the OSGI way to do it
> and Eclipse is becoming more OSGI so I should probably do it that way.
> From what I have gathered I will need the Declarative Service so I can
> register the implementations. Then at runtime just ask the bundlecontext
> for all implementations and go from there.
There are two sides to the equation; firstly registering the service and
secondly accessing or consuming the service.
Registering a service is very easy and does not need to be done with
Declarative Services (although it can be). All you need is some code in
your bundle Activator (the Plugin class in pre-OSGI terminology). Put the
following in the start() method:
MyService impl = new MyServiceImpl(); // Create the implementation
object
Dictionary props = new HashTable();
props.put("foo", "bar"); // Optional properties
reg = context.registerService(MyService.class.getName(), props);
// reg is an instance field of type ServiceRegistration
Then in the stop() method you simply unregister:
reg.unregister();
Consuming the service is more difficult because you have to worry about
the dynamic nature of the service registry, ie services can come and go at
any time. In particular you should avoid making your code dependent on the
order in which bundles are started... ie if your code needs ThingyService,
you can't assume that ThingyService is available immediately. Therefore
you generally need to listen to the service registry so that you can
"bind" to the services you need as they become available.
There are various ways of doing that, including a number of "code only"
approaches, but by far the easiest way is to use Declarative Services.
> Is there a resource to learn how to use Eclipse OSGI service registry?
There is a good tutorial at
http://www.knopflerfish.org/osgi_service_tutorial.html. Knopflerfish is an
alternative OSGI implementation, but the Service Registry is standard OSGI
so everything in that tutorial also applies in Eclipse.
Unfortunately that tutorial doesn't cover Declarative Services, and I
don't know of any alternative tutorial that does. The best resource
currently is the DS chapter of the OSGI Compendium specification itself.
After reading that spec, the Eclipse specific stuff you need to know is
that the SCR (the name for the DS runtime) is implemented in the
org.eclipse.equinox.ds bundle, which you need to download separately from
http://download.eclipse.org/eclipse/equinox/. Then you need to ensure that
that bundle gets started at runtime, which you can do either by editing
osgi.bundles in config.ini or by manually starting the bundle through the
OSGI console.
Regards,
Neil
|
|
|
Re: Extension Points conversion to OSGI Service Registry [message #70281 is a reply to message #70260] |
Tue, 18 July 2006 20:53 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: lamont_gilbert.rigidsoftware.com
I definitely need DS. Without DS I would have to autostart all my bundles
wether they are used or not. I suppose when you really thing about it
since DS is just another auto-started bundle, auto-starting my own bundles
is really no worse. Its just a paradigm shift.
The notion of 'starting' will have to change. Starting will have to imply
registration but not imply any useage. Once I make this change I'll will
still need some way to know when my bundle is actually about to be used.
Else, eclipse will be a very slow starting platform as everyone starts
their bundles and loads their resources with platform start..
Neil Bartlett wrote:
> Hi CL,
>
>> Now I understand there are OSGI services and this is the OSGI way to do
>> it and Eclipse is becoming more OSGI so I should probably do it that way.
>> From what I have gathered I will need the Declarative Service so I can
>> register the implementations. Then at runtime just ask the bundlecontext
>> for all implementations and go from there.
>
> There are two sides to the equation; firstly registering the service and
> secondly accessing or consuming the service.
>
> Registering a service is very easy and does not need to be done with
> Declarative Services (although it can be). All you need is some code in
> your bundle Activator (the Plugin class in pre-OSGI terminology). Put the
> following in the start() method:
>
> MyService impl = new MyServiceImpl(); // Create the implementation
> object
> Dictionary props = new HashTable();
> props.put("foo", "bar"); // Optional properties
> reg = context.registerService(MyService.class.getName(), props);
> // reg is an instance field of type ServiceRegistration
>
> Then in the stop() method you simply unregister:
>
> reg.unregister();
>
> Consuming the service is more difficult because you have to worry about
> the dynamic nature of the service registry, ie services can come and go at
> any time. In particular you should avoid making your code dependent on the
> order in which bundles are started... ie if your code needs ThingyService,
> you can't assume that ThingyService is available immediately. Therefore
> you generally need to listen to the service registry so that you can
> "bind" to the services you need as they become available.
>
You mean service location can come and go. Surely a service, once obtained,
can not leave until it is released?
This will be tricky. However, can I infer that all autostarted bundles will
be started before the UI becomes available? If so then it will be the same
as today for me.
> There are various ways of doing that, including a number of "code only"
> approaches, but by far the easiest way is to use Declarative Services.
>
>
>> Is there a resource to learn how to use Eclipse OSGI service registry?
>
> There is a good tutorial at
> http://www.knopflerfish.org/osgi_service_tutorial.html. Knopflerfish is an
> alternative OSGI implementation, but the Service Registry is standard OSGI
> so everything in that tutorial also applies in Eclipse.
>
> Unfortunately that tutorial doesn't cover Declarative Services, and I
> don't know of any alternative tutorial that does. The best resource
> currently is the DS chapter of the OSGI Compendium specification itself.
>
> After reading that spec, the Eclipse specific stuff you need to know is
> that the SCR (the name for the DS runtime) is implemented in the
> org.eclipse.equinox.ds bundle, which you need to download separately from
> http://download.eclipse.org/eclipse/equinox/. Then you need to ensure that
> that bundle gets started at runtime, which you can do either by editing
> osgi.bundles in config.ini or by manually starting the bundle through the
> OSGI console.
>
> Regards,
> Neil
Thanks, Ill give it a go. Seems pretty straightforward.
--
Respectfully,
CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into the
sheepfold{}, but climbeth up some other *way, the same is a thief and a
robber."
|
|
| |
Re: Extension Points conversion to OSGI Service Registry [message #70320 is a reply to message #70300] |
Wed, 19 July 2006 03:55 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: lamont_gilbert.rigidsoftware.com
Interesting. I need to hear that talk. After my quick stab at services I
can see that it really does not fit at all. The service itself cant notify
anyone that its available without the bundle starting but since no one
knows the service exists the bundle will never start...
I would have to create a system whereby I could 'register' available
services in some fashion. I would end up duplicating the existing
extension points architecture or the DS thing.
I think ill stick with the extension points.
Thanks for the info,
Carl
Pascal Rapicault wrote:
> Gilbert,
>
> Services and extension/extension points are complementary mechanisms and
> each have their strengths and drawbacks. It is not because eclipse is
> using osgi that suddenly everybody should move to use service and drop the
> extension (In fact eclipse itself only uses a few services). In your case
> I would argue that you should stay with extension / extension points
> because you want the activation on use and probably the ability to
> discover properties about the extension.
>
> I think there was a talk about registry vs services at eclipse con by Jeff
> and BJ
>
> hth
>
> PaScaL
>
> "CL [dnoyeb] Gilbert" <lamont_gilbert@rigidsoftware.com> wrote in message
> news:e9gc3d$7ie$1@utils.eclipse.org...
>> I have an application that uses extension points. one plugin exposes an
>> extension point and two other plugins implement them. Its discovered at
>> runtime and the user can select which implementation he wishes to use.
>>
>> Now I understand there are OSGI services and this is the OSGI way to do
>> it and Eclipse is becoming more OSGI so I should probably do it that way.
>> From what I have gathered I will need the Declarative Service so I can
>> register the implementations. Then at runtime just ask the bundlecontext
>> for all implementations and go from there.
>>
>> Is this right? I really have not been able to find any information on
>> Eclipse website about how to implement an OSGI service. I saw some
>> powerpoint slides, but it was a rather incomplete example and not very
>> clear without the talking I suppose.
>>
>> Is there a resource to learn how to use Eclipse OSGI service registry?
>>
>>
>> --
>> Respectfully,
>>
>> CL Gilbert
>> "Verily, verily, I say unto you, He that entereth not by the door() into
> the
>> sheepfold{}, but climbeth up some other *way, the same is a thief and a
>> robber."
>>
--
Respectfully,
CL Gilbert
"Verily, verily, I say unto you, He that entereth not by the door() into the
sheepfold{}, but climbeth up some other *way, the same is a thief and a
robber."
|
|
|
Goto Forum:
Current Time: Fri Aug 16 16:11:56 GMT 2024
Powered by FUDForum. Page generated in 0.04149 seconds
|