Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Global Event Service
Global Event Service [message #455727] Wed, 04 October 2006 14:32 Go to next message
Eclipse UserFriend
Hi,

I'm looking for a service like the SelectionService, but with the
possibility to send different events. For example I want to register a
View as listener for a user-defined event (e.g. file loaded/saved) and
register other parts as provider like the SelectionListener/Provider. Is
there such a service or have I to implement it myself?

Thanks in advance,

Ingo
Re: Global Event Service [message #455733 is a reply to message #455727] Wed, 04 October 2006 22:04 Go to previous messageGo to next message
Eclipse UserFriend
OSGi provides a global event service. Check out
http://www.eclipse.org/equinox/bundles/

Later,
PW
Re: Global Event Service [message #455754 is a reply to message #455733] Thu, 05 October 2006 09:00 Go to previous messageGo to next message
Eclipse UserFriend
Hi Paul,

the Event Admin Service seems to be right for me, thanks. But I have
trouble understanding how to use this service. I copied the
org.eclipse.equinox.event-plugin in my Eclipse plugin folder and added the
plugin to the dependencies in my application. Furthermore I imported the
package org.osgi.service.event in my Manifest-file. It looks sth. like
this:

Manifest.mf:
...
Import-Package: org.osgi.service.event;version="1.0.1"
...

Then I tried to get access to the service with the following instruction:

PlatformUI.getWorkbench().getService(EventAdmin.class);

But this don't work. I tried several solutions, with or without importing
the package in the manifest, using EventAdminImpl class as argument, but
nothing changed. I have no ideas how to use this service, can anyone help
me, please?

Thanks in advance,

Ingo
Re: Global Event Service [message #455763 is a reply to message #455754] Thu, 05 October 2006 13:26 Go to previous messageGo to next message
Eclipse UserFriend
Ingo Kroh wrote:
>
> PlatformUI.getWorkbench().getService(EventAdmin.class);


The eclipse IServiceLocator doesn't provide access to OSGi services,
just eclipse workbench services (and only a few in 3.2, we're hoping to
add more).

Find references to how the PackageAdmin service is used. i.e.:

BundleContext context = ....;
ServiceReference packageAdminRef = context
.getServiceReference(PackageAdmin.class.getName());
PackageAdmin packageAdmin = null;
if (packageAdminRef != null) {
packageAdmin = (PackageAdmin) context.getService(packageAdminRef);
}
if (packageAdmin!=null) {
// use the service
}
context.ungetService(packageAdminRef);

There should be docs somewhere that describe the OSGi service model.

Later,
PW
Re: Global Event Service [message #455773 is a reply to message #455754] Thu, 05 October 2006 20:46 Go to previous messageGo to next message
Eclipse UserFriend
Ingo Kroh wrote:
>
> Manifest.mf:
> ..
> Import-Package: org.osgi.service.event;version="1.0.1"
> ..

Oh, and why not just require the plugin? Import-Package is useful if
you can't have a direct dependency on a plugin, or expect possibly
different plugins to provide a package for you (like icu4j and the icu4j
stub plugins).

Later,
PW
Re: Global Event Service [message #455798 is a reply to message #455773] Fri, 06 October 2006 09:47 Go to previous messageGo to next message
Eclipse UserFriend
Hi Paul,

I thought that the Equinox Bundles were implemented extra for Eclipse and
I can get access to them like I posted it. In that case I misunderstood
the usage. Concerning the import of the org.osgi.service.event package I
think I need this, because otherwise I can't use the class EventAdmin. The
org.eclipse.equinox.event plugin only has the classes EventAdminImpl and
Activator, and at both Eclipse says discouraged access.

Ingo
Re: Global Event Service [message #455806 is a reply to message #455798] Fri, 06 October 2006 11:12 Go to previous messageGo to next message
Eclipse UserFriend
Ingo Kroh wrote:
> Hi Paul,
>
> I thought that the Equinox Bundles were implemented extra for Eclipse
> and I can get access to them like I posted it. In that case I
> misunderstood the usage. Concerning the import of the
> org.osgi.service.event package I think I need this, because otherwise I
> can't use the class EventAdmin. The org.eclipse.equinox.event plugin
> only has the classes EventAdminImpl and Activator, and at both Eclipse
> says discouraged access.


Package imports in the java files themselves are fine.

It's just your Import-Package header in your MANIFEST. Why not just
make the event service plugin a required bundle for your plugin? Your
java files will be able to see the correct imports.

But Import-Package doesn't buy you anything over Require-Bundle,
*unless* you plan on providing a number of OSGi event service
implementations in different plugins.

Also, I wouldn't tie your plugin to verion 1.0.1 unless you really need to.


The equinox bundles are extra (you'll have to ship the equinox event
plugin along with your plugin).

Later,
PW
Re: Global Event Service [message #455823 is a reply to message #455806] Sat, 07 October 2006 15:45 Go to previous messageGo to next message
Eclipse UserFriend
http://www.knopflerfish.org/osgi_service_tutorial.html
"Paul Webster" <pwebster@ca.ibm.com> wrote in message
news:eg5rv0$j2k$1@utils.eclipse.org...
> Ingo Kroh wrote:
>> Hi Paul,
>>
>> I thought that the Equinox Bundles were implemented extra for Eclipse and
>> I can get access to them like I posted it. In that case I misunderstood
>> the usage. Concerning the import of the org.osgi.service.event package I
>> think I need this, because otherwise I can't use the class EventAdmin.
>> The org.eclipse.equinox.event plugin only has the classes EventAdminImpl
>> and Activator, and at both Eclipse says discouraged access.
>
>
> Package imports in the java files themselves are fine.
>
> It's just your Import-Package header in your MANIFEST. Why not just make
> the event service plugin a required bundle for your plugin? Your java
> files will be able to see the correct imports.
>
> But Import-Package doesn't buy you anything over Require-Bundle, *unless*
> you plan on providing a number of OSGi event service implementations in
> different plugins.
>
> Also, I wouldn't tie your plugin to verion 1.0.1 unless you really need
> to.
>
>
> The equinox bundles are extra (you'll have to ship the equinox event
> plugin along with your plugin).
>
> Later,
> PW
Re: Global Event Service [message #455885 is a reply to message #455806] Mon, 09 October 2006 08:07 Go to previous messageGo to next message
Eclipse UserFriend
Hi Paul,

I hope you don't think I'm stupid, but I don't understand how to make the
event service plugin a required bundle for my plugin where I can access
the EventAdmin class. I just can add the org.eclipse.equinox.event plugin
to my required plugins, but not org.osgi.service.event or anything else
from org.osgi.*. Then I can't access the class EventAdmin if I don't use
Import-Package in my manifest. I read the Event Admin Service
specification in the OSGi Service Platform Service Compendium Release 4,
and they say in chapter 113.12:

Event Admin Package Version 1.1.
Bundles wishing to use this package must list the package in the Import-
Package header of the bundle’s manifest. For example:
Import-Package: org.osgi.service.event; version=1.1

Now I'm a little bit confused about what you say and what the
specification says. But I'm new in RCP development, and perhaps I didn't
really understand what you mean.

Next problem I have is how to start the service. I read I can do this in
the config.ini with the following instruction:

osgi.bundles=org.eclipse.equinox.event@start

But if I do so I get a BundleException (Bundle "org.eclipse.equinox.event"
version "1.0.0.v20060601a" has already been installed from:
update@plugins/org.eclipse.equinox.event_1.0.0.v20060601a.jar) and the
service will not start. So I considered to do this programmatically in my
plugin's start-method, but I'm not sure what is the best way to do this.
If I use the Activator class from the event service plugin Eclipse says
discouraged access. But how could I start this service, what is the normal
procedure?

And after slowly understanding how to use this service I'm meanwhile not
sure if this service is really right for me. I think this service is
designed for sending/handling events between Bundles, not inside a bundle.
I hit on it because I need to register an EventHandler service for each
handler. But to do so I need the BundleContext and the only class I have a
reference to it is my Activator class. I solve this by adding a method
registerService(EventHandler, Dictionary) to my Activator class and cache
the BundleContext from the start method. Is this approach bad practice or
would you say you can let this?

Ingo
Re: Global Event Service [message #455914 is a reply to message #455885] Mon, 09 October 2006 20:41 Go to previous messageGo to next message
Eclipse UserFriend
Ingo Kroh wrote:
> Hi Paul,
>
> I hope you don't think I'm stupid, but I don't understand how to make
> the event service plugin a required bundle for my plugin where I can
> access the EventAdmin class. I just can add the
> org.eclipse.equinox.event plugin to my required plugins, but not
> org.osgi.service.event or anything else from org.osgi.*. Then I can't
> access the class EventAdmin if I don't use Import-Package in my
> manifest. I read the Event Admin Service specification in the OSGi
> Service Platform Service Compendium Release 4, and they say in chapter
> 113.12:
>
> Event Admin Package Version 1.1.
> Bundles wishing to use this package must list the package in the Import-
> Package header of the bundle�s manifest. For example:
> Import-Package: org.osgi.service.event; version=1.1

If that's what they say, I'd go with it. I'm not sure how the import
package would allow something to work when a require-bundle does, but I
haven't actually tried it with the event bundle (so my information is
general, not specific).

> Next problem I have is how to start the service. I read I can do this in
> the config.ini with the following instruction:
>
> osgi.bundles=org.eclipse.equinox.event@start

I'm not sure why the event service won't start for your ... it should be
done either 1) adding it to the osgi.bundles or 2) possibly calling into
a class.

You can start another bundle deliberately by using
org.eclipse.core.runtime.Platform#getBundle(String) to get the Bundle,
checking the state, and calling Bundle#start().


> And after slowly understanding how to use this service I'm meanwhile not
> sure if this service is really right for me. I think this service is
> designed for sending/handling events between Bundles, not inside a
> bundle. I hit on it because I need to register an EventHandler service
> for each handler. But to do so I need the BundleContext and the only
> class I have a reference to it is my Activator class. I solve this by
> adding a method registerService(EventHandler, Dictionary) to my
> Activator class and cache the BundleContext from the start method. Is
> this approach bad practice or would you say you can let this?

This is a common approach for plugins that need the BundleContext, they
cache it in their Activator.

Maybe this event service is too heavy weight for what you want to do.
Another option is to provide your "event service" as a singleton through
a static method on your Activator.
org.eclipse.core.commands.common.EventManager (in
org.eclipse.core.commands) provides an abstract base class that can be
specialized with your listeners.

Later,
PW
Re: Global Event Service [message #455926 is a reply to message #455914] Tue, 10 October 2006 05:52 Go to previous messageGo to next message
Eclipse UserFriend
Hi Paul,

thanks a lot for your help. Now I am able to send events inside and across
plugins. I think I even need this service, because I need the possibility
to send events across plugins. I just wasn't sure if this is a good
solution because I looked for sth. similar to the selection service. Also
I don't know if I could do this with my own implementation (I think it
should work, but then I have to spend a lot of time to sth. what already
exists).

Ingo
Re: Global Event Service [message #460055 is a reply to message #455926] Tue, 12 December 2006 14:00 Go to previous messageGo to next message
Eclipse UserFriend
I have been attempting to do something similar and have been following along with this tread. It seems I am having a problem starting or registering the EventAdmin service. The following code produces a null for ea:

tracker = new ServiceTracker(context, EventAdmin.class.getName(), null);
tracker.open();
EventAdmin ea = (EventAdmin) tracker.getService();

What do I need to do to get the EventAdmin service started or registered to begin with?
Re: Global Event Service [message #460056 is a reply to message #460055] Tue, 12 December 2006 14:08 Go to previous message
Eclipse UserFriend
I initially added osgi.bundles=org.eclipse.equinox.event@start to my config.ini and it didn't seem to work but I just went back and started over and the EventAdmin service started and I can send events. Sorry, not sure why it didn't work the first time.
Previous Topic:Interaction of Views and Actions - triggering actions from views & accessing views from actions
Next Topic:[databinding] what's the status
Goto Forum:
  


Current Time: Wed Mar 26 08:02:48 EDT 2025

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

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

Back to the top