Difference between revisions of "EIG:Distributed EventAdmin Service"

From Eclipsepedia

Jump to: navigation, search
(Using the Distributed EventAdmin Service)
 
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
==Introduction==
+
=[[EIG:Integrators Guide|Distributed EventAdmin Service]]=
  
OSGi declares an EventAdmin service that is responsible for distributing events to listeners registered via the (org.osgi.service.event.EventHandler).  It's possible to create distributed implementations of such services using JMS and/or other messaging frameworks for distributing messages to other OSGi frameworks.
+
{{:EIG:Introduction to Distributed EventAdmin}}
 
+
[[Image:Distributedeventadmin.png]]
+
 
+
ECF's provider architecture allows the creation of a distributed EventAdmin implementation that can use a variety of wire protocols.  For example, ActiveMQ/JMS 5.2 as above, or ECF generic, XMPP, JavaGroups, commercial/proprietary messaging buses, or any others that can implement the ECF Shared Object API.
+
 
+
==Using the Distributed EventAdmin Service==
+
 
+
First, install ECF 3.0.  [http://www.eclipse.org/ecf/downloads.php Here is the download page].
+
 
+
Then get the two projects that implement the event admin example.  [[Media:Example.eventadmin.psf | This is a project set file]].  Save the project set file to your local disk and then import to get into your Eclipse workspace.  For direct CVS access:
+
 
+
host:  '''dev.eclipse.org'''
+
path:  '''/cvsroot/rt'''
+
module: '''org.eclipse.ecf/examples/bundles'''
+
projects: '''org.eclipse.ecf.examples.eventadmin, org.eclipse.ecf.examples.eventadmin.app'''
+

Latest revision as of 07:24, 26 February 2011

Contents

[edit] Distributed EventAdmin Service

[edit] Introduction to Distributed EventAdmin

OSGi declares an EventAdmin service that is responsible for distributing events to listeners registered via the (org.osgi.service.event.EventHandler). It's possible to create distributed implementations of such services using JMS and/or other messaging frameworks for distributing messages to other OSGi frameworks.

Distributedeventadmin.png

ECF's provider architecture allows the creation of a distributed EventAdmin implementation that can use a variety of wire protocols. For example, ActiveMQ/JMS 5.2 as above, or ECF generic, XMPP, JavaGroups, commercial/proprietary messaging buses, or any others that can implement the ECF Shared Object API.

[edit] Getting the Distributed EventAdmin Service

First, install ECF. Instructions on how to do that are on the Download page.

Then get the two projects that implement the event admin example. This must be done after you have gotten the sources. How to get the sources is described in the Download Source Code.

Get the following two projects from the source tree:

  • module: org.eclipse.ecf/server-side/bundles, project: org.eclipse.ecf.remoteservice.eventadmin
  • module: org.eclipse.ecf/examples/bundles, project: org.eclipse.ecf.examples.eventadmin.app

[edit] Running an Example Server and Clients

Once these two projects are in your workspace, you can run the ECF generic based server and client by opening the product editor for the following product files:

org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Server.product

org.eclipse.ecf.examples.eventadmin.app/EventAdmin Generic Client.product

Productlaunch.png


To run, click on 'Launch an Eclipse application' at the lower left.

If you run the EventAdmin Generic Server.product, you should get output to the console every few seconds like this:

handleEvent
	topic=defaultTopic
	message=message #0
	sender=ecftcp://localhost:3787/server
handleEvent
	topic=defaultTopic
	message=message #1
	sender=ecftcp://localhost:3787/server
...

This indicates that the EventAdmin service is being accessed to send test messages every 2 seconds. Here's the code (in org.eclipse.ecf.examples.internal.eventadmin.app.TestSender class) that is making the EventAdmin.postEvent call:

      Map msgProps = new Properties();
      msgProps.put("message", "message #"
                   + messageCounter++);
      msgProps.put("sender", sender);
      eventAdmin.postEvent(new Event(topic, msgProps));

What this does is create an Event instance with values for a couple of properties (i.e. "message", and "sender"), and then call eventAdmin.postEvent(Event) to have the eventAdmin implementation deliver the message to EventHandlers.

The test event handler implementation is this (in org.eclipse.ecf.examples.internal.eventadmin.app.TestEventHandler class):

public class TestEventHandler implements EventHandler {
 
	public void handleEvent(Event event) {
		System.out.println("handleEvent\n\ttopic=" + event.getTopic()
				+ "\n\tmessage=" + event.getProperty("message") + "\n\tsender="
				+ event.getProperty("sender"));
	}
 
}

The TestEventHandler class is registered as an instance of EventHandler upon application startup (in org.eclipse.ecf.examples.internal.eventadmin.app.EventAdminManagerApplication)

                Dictionary dictionary = new Hashtable();
                dictionary.put(EventConstants.EVENT_TOPIC,"*"); // Needed, otherwise you don't see any events at all
		testEventHandlerRegistration = bundleContext.registerService(
				EventHandler.class.getName(), new TestEventHandler(), dictionary);

If a EventAdmin Generic Server.product and 1 or more EventAdmin Generic Client.products are started then both the clients and the server will act as both message senders and EventHandlers (receivers), and the output will appear something like this

handleEvent
	topic=defaultTopic
	message=message #3
	sender=ecftcp://localhost:3787/server
handleEvent
	topic=defaultTopic
	message=message #0
	sender=9POAn/uwLgZyU5krxfjDhhhAuMU=
handleEvent
	topic=defaultTopic
	message=message #4
	sender=ecftcp://localhost:3787/server
handleEvent
	topic=defaultTopic
	message=message #1
	sender=9POAn/uwLgZyU5krxfjDhhhAuMU=
...

You can see that the 'sender' is different for the server (i.e. ecftcp://localhost:3787/server) than for the client(s) (i.e. 9POAn/uwLgZyU5krxfjDhhhAuMU=). This indicates that both the server and the client are sending messages, and receiving them (delivered to the EventHandler's that have been registered).

See the following two classes for info on how the test server and client are structured

org.eclipse.ecf.examples.internal.eventadmin.app.EventAdminManagerApplication org.eclipse.ecf.examples.internal.eventadmin.app.EventAdminClientApplication

[edit] Related Documentation

THIS MUST BE REMOVED AFTER DOCUMENTATION FINISHED (WJ)

Distributed OSGi Services with ECF

Getting Started with ECF's RFC119 Implementation

Getting Started with Using the ECF Remote Services API

ECF API Docs

API Javadocs


Eclipse Communication Framework
API
API DocumentationJavadocProvidersECF/Bot Framework
Components
ServersShared EditingShared Code Plug-in
Development
Development GuidelinesIntegrators Guide