Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Declarative Services in an Eclipse Application
Declarative Services in an Eclipse Application [message #122609] Mon, 15 December 2008 08:51 Go to next message
Alexis R. is currently offline Alexis R.Friend
Messages: 10
Registered: July 2009
Junior Member
Hello!

I have a bit of a more general question than most. I am new to this OSGi
Services thing, but I have allready seen some aspects of a project I am
working on, that would be conceptionaly better if they where defined as a
Declarative Service.
For a couple of days I have been trying to figure out how to use
Declarative Services for an Eclipse Plugin. I have been able to launch my
example code as an OSGi framework but how will I go about launching the
same code from a plugin? I have a component that offers a service
implementing an interface. Let's say the service has the name "ServiceA"
:)
Now I have my Eclipse Plug-In code and I would like to use this
"ServiceA" everytime the user selection an Action from a menu.
What is the correct was of doing this? A very first problem I am facing
is how do I launch my eclipse-launch-configuration with declarative
services included? For the OSGi launch one needs to add the
org.eclipse.equniox.ds bundle. But how do I do the analog thing for my
eclipse-launch-configuration? I found some wiki page for using DS with a
RCP and that should be fundamentaly the same but following the
instructions ( edditing the config.ini file ) didn't bring the desired
results.
Can somebody point me to the right direction?

Thank you for reading this far and thank you for your time!

Greetings,
Alexis
Re: Declarative Services in an Eclipse Application [message #122619 is a reply to message #122609] Mon, 15 December 2008 09:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I've written an example application some time ago where I also show how
to use DS.

The sources are available here [1].

The things you are interested in are:
- Starting ds when applications starts [2] - this could also be done in
a customized config.ini of course
- Declaration of the DS [3,4,5]
- Accessing the DS [6,7,8,9]

Tom

[1] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/
[2] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.app/src/at/bestsolution/socc er/app/intro/Application.java
[3] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui/OSGI-INF/
[4] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui/src/at/bestsolution/socce r/ui/IImageStorage.java
[5] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui/src/at/bestsolution/socce r/ui/internal/ImageStorageImpl.java
[6] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/Activator.java
[7] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.playeradmin/src/at/bestso lution/soccer/ui/playeradmin/PlayerAdministrationDialog.java
[8] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.associationteamadmin/src/ at/bestsolution/soccer/ui/associationteamadmin/Activator.jav a
[9] http://publicsvn.bestsolution.at/repos/java/examples/EMF-Dat abinding/at.bestsolution.soccer.ui.associationteamadmin/src/ at/bestsolution/soccer/ui/associationteamadmin/TeamAdministr ationForm.java


Alexis R. schrieb:
> Hello!
> I have a bit of a more general question than most. I am new to this OSGi
> Services thing, but I have allready seen some aspects of a project I am
> working on, that would be conceptionaly better if they where defined as
> a Declarative Service. For a couple of days I have been trying to
> figure out how to use Declarative Services for an Eclipse Plugin. I have
> been able to launch my example code as an OSGi framework but how will I
> go about launching the same code from a plugin? I have a component that
> offers a service implementing an interface. Let's say the service has
> the name "ServiceA" :) Now I have my Eclipse Plug-In code and I would
> like to use this "ServiceA" everytime the user selection an Action from
> a menu. What is the correct was of doing this? A very first problem I am
> facing is how do I launch my eclipse-launch-configuration with
> declarative services included? For the OSGi launch one needs to add the
> org.eclipse.equniox.ds bundle. But how do I do the analog thing for my
> eclipse-launch-configuration? I found some wiki page for using DS with a
> RCP and that should be fundamentaly the same but following the
> instructions ( edditing the config.ini file ) didn't bring the desired
> results. Can somebody point me to the right direction?
>
> Thank you for reading this far and thank you for your time!
>
> Greetings,
> Alexis
>
>
>


--
B e s t S o l u t i o n . at
------------------------------------------------------------ --------
Tom Schindl JFace-Committer
------------------------------------------------------------ --------
Re: Declarative Services in an Eclipse Application [message #123004 is a reply to message #122619] Mon, 15 December 2008 10:12 Go to previous messageGo to next message
Alexis R. is currently offline Alexis R.Friend
Messages: 10
Registered: July 2009
Junior Member
Thank you very much! You just made my day:D
Re: Declarative Services in an Eclipse Application [message #123035 is a reply to message #122619] Tue, 16 December 2008 13:35 Go to previous messageGo to next message
Alexis R. is currently offline Alexis R.Friend
Messages: 10
Registered: July 2009
Junior Member
Hi!

With our help I have written a very small plug-in that uses a service. Or
I should say doesn't use. I have downloaded and installed the equinox.ds
jar and the util jar. The starting of the org.eclipse.equinox.ds now
works. But when I try to get a ServiceReference for my service I get a
null.

My OSGI-INF:

<?xml version="1.0" encoding="UTF-8"?>
<component immediate="true" name="com.ventuja.service">
<implementation class="com.ventuja.service.implementation.Messenger"/>
<service>
<provide interface="com.ventuja.plugin.interfaces.IMessenger"/>
</service>
</component>

Here is my code that I use to get the ServiceReference:

public IMessenger getMessenger() {
//gives a null
ServiceReference ref =
context.getServiceReference(IMessenger.class.getName());
if( ref != null ) {
return (IMessenger) context.getService(ref);
}
return null;
}

It is located in the Activator class of my plugin.

Do I need to change something in my build files or something similar?

I exported my example and have it here:
http://www.ventuja.com/dsplugin.zip if anybody is interested in peeking
into it:)

Thanks you for reading!
Alexis
Re: Declarative Services in an Eclipse Application [message #123047 is a reply to message #123035] Tue, 16 December 2008 15:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ekkehard.gentz-software.de

if you type
services
in your osgi console - is the service listed ?

Alexis R. schrieb:
> Hi!
>
> With our help I have written a very small plug-in that uses a service.
> Or I should say doesn't use. I have downloaded and installed the
> equinox.ds jar and the util jar. The starting of the
> org.eclipse.equinox.ds now works. But when I try to get a
> ServiceReference for my service I get a null.
> My OSGI-INF:
> <?xml version="1.0" encoding="UTF-8"?>
> <component immediate="true" name="com.ventuja.service">
> <implementation class="com.ventuja.service.implementation.Messenger"/>
> <service>
> <provide interface="com.ventuja.plugin.interfaces.IMessenger"/>
> </service>
> </component>
>
> Here is my code that I use to get the ServiceReference:
>
> public IMessenger getMessenger() {
> //gives a null
> ServiceReference ref =
> context.getServiceReference(IMessenger.class.getName());
> if( ref != null ) {
> return (IMessenger) context.getService(ref);
> }
> return null;
> }
>
> It is located in the Activator class of my plugin.
>
> Do I need to change something in my build files or something similar?
>
> I exported my example and have it here:
> http://www.ventuja.com/dsplugin.zip if anybody is interested in peeking
> into it:)
>
> Thanks you for reading!
> Alexis
>
Re: Declarative Services in an Eclipse Application [message #123071 is a reply to message #123035] Tue, 16 December 2008 20:34 Go to previous messageGo to next message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Alexis R. schrieb:
> Do I need to change something in my build files or something similar?

I'd try launching from the Eclipse workspace first as an OSGi
application to eliminate other potential sources of problems. Make sure
that the build.properties includes the OSGI-INF folder.

Is the bundle containing the service started? I recently played with DS
and I recall that I had to start the bundles containing the service
components as well. Just starting the Equinox DS bundle wasn't enough.
But I haven't digged deeper to investigate the reason for this. My
previous assumption was that DS would start the bundles contributing
service components as necessary (similar to the extension registry). But
I haven't found clarification/confirmation in the spec yet.

-Gunnar

--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Re: Declarative Services in an Eclipse Application [message #123110 is a reply to message #123035] Wed, 17 December 2008 07:34 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: b.l.kelly.bigpond.com

The activation of the bundle occurs before DS looks for the service
component definitions, so it won't have published the service.

I think it is safest to always use another service component to access the
services published by a service component. If you use static binding then it
also takes less code as DS does all the work of tracking the service
availability.

"Alexis R." <alexis.raptarchis@googlemail.com> wrote in message
news:6989048d7baf599c0fff567d9738b4fc$1@www.eclipse.org...
> Hi!
>
> With our help I have written a very small plug-in that uses a service. Or
> I should say doesn't use. I have downloaded and installed the equinox.ds
> jar and the util jar. The starting of the org.eclipse.equinox.ds now
> works. But when I try to get a ServiceReference for my service I get a
> null.
> My OSGI-INF:
> <?xml version="1.0" encoding="UTF-8"?>
> <component immediate="true" name="com.ventuja.service">
> <implementation class="com.ventuja.service.implementation.Messenger"/>
> <service>
> <provide interface="com.ventuja.plugin.interfaces.IMessenger"/>
> </service>
> </component>
>
> Here is my code that I use to get the ServiceReference:
>
> public IMessenger getMessenger() {
> //gives a null
> ServiceReference ref =
> context.getServiceReference(IMessenger.class.getName());
> if( ref != null ) {
> return (IMessenger) context.getService(ref);
> }
> return null;
> }
>
> It is located in the Activator class of my plugin.
>
> Do I need to change something in my build files or something similar?
>
> I exported my example and have it here:
> http://www.ventuja.com/dsplugin.zip if anybody is interested in peeking
> into it:)
>
> Thanks you for reading!
> Alexis
>
Re: Declarative Services in an Eclipse Application [message #123121 is a reply to message #123071] Wed, 17 December 2008 12:30 Go to previous messageGo to next message
Alexis R. is currently offline Alexis R.Friend
Messages: 10
Registered: July 2009
Junior Member
Hello Gunnar!

You are right! If I first manually start my bundle then it works. But I
can't imagine that this is the way Declarative Services are intented to be
used. Or maybe I have a conceptional problem.

What I have , or better said want to have , is a host plugin that uses
services from other plugins/bundles. My host plugin doesn't know which
bundles will be available so starting them explicitly isn't an option and
imho would go against the whole point of OSGi and a SOA in general no?

I will try to dig deeper into the issue , but still any tips would be
greatly appreciated!

Thanks,
Alexis


Gunnar Wagenknecht wrote:

> Alexis R. schrieb:
>> Do I need to change something in my build files or something similar?

> I'd try launching from the Eclipse workspace first as an OSGi
> application to eliminate other potential sources of problems. Make sure
> that the build.properties includes the OSGI-INF folder.

> Is the bundle containing the service started? I recently played with DS
> and I recall that I had to start the bundles containing the service
> components as well. Just starting the Equinox DS bundle wasn't enough.
> But I haven't digged deeper to investigate the reason for this. My
> previous assumption was that DS would start the bundles contributing
> service components as necessary (similar to the extension registry). But
> I haven't found clarification/confirmation in the spec yet.

> -Gunnar
Re: Declarative Services in an Eclipse Application [message #123145 is a reply to message #123035] Wed, 17 December 2008 13:23 Go to previous messageGo to next message
Alexis R. is currently offline Alexis R.Friend
Messages: 10
Registered: July 2009
Junior Member
Hello!

I am replying to my own post because I have found the solution to the
problem ( or better said xmux in the #eclipse irc channel ). It is
intended that one has to start the bundle before DS can collect the
services declared in the bundles. The simplest way of doing this is to use
the startup extension-point from the bundles declaring the services. If
that is a good idea in the long run is a different question but atleast it
works this way.
Also manually starting org.eclipse.equinox.ds through
Platform.getBundle("org.eclipse.equinox.ds").start() is also not needed.

Maybe this info helps somebody in the future!
Thank you for all your help!
Re: Declarative Services in an Eclipse Application [message #123182 is a reply to message #123145] Wed, 17 December 2008 20:43 Go to previous message
Gunnar Wagenknecht is currently offline Gunnar WagenknechtFriend
Messages: 486
Registered: July 2009
Location: San Francisco ✈ Germany
Senior Member

Alexis R. schrieb:
> services declared in the bundles. The simplest way of doing this is to use
> the startup extension-point from the bundles declaring the services. If
> that is a good idea in the long run is a different question but atleast it
> works this way.

The UI startup extension point? Uhh that's hackish. Anyway, I created
the concept of server roles in CloudFree. It is similar to the
application model but allows a more dynamic composition of bundles to be
started or stopped at runtime.

-Gunnar

--
Gunnar Wagenknecht
gunnar@wagenknecht.org
http://wagenknecht.org/
Previous Topic:"Deploying the info center as web archive" problem
Next Topic:Why doesn't a "initial@reference" bundle export packages ?
Goto Forum:
  


Current Time: Tue Mar 19 08:39:22 GMT 2024

Powered by FUDForum. Page generated in 0.02383 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top