|
Re: Declarative Services in an Eclipse Application [message #122619 is a reply to message #122609] |
Mon, 15 December 2008 09:40 |
Thomas Schindl 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 #123047 is a reply to message #123035] |
Tue, 16 December 2008 15:27 |
Eclipse User |
|
|
|
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 |
|
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 |
Eclipse User |
|
|
|
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 #123182 is a reply to message #123145] |
Wed, 17 December 2008 20:43 |
|
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/
|
|
|
Powered by
FUDForum. Page generated in 0.02383 seconds