Skip to main content
Jump to: navigation, search

Difference between revisions of "EIG:JGroups provider"

(A Sample JGroups Client Container)
(A Sample JGroups Client Container)
Line 111: Line 111:
 
<source lang="java">
 
<source lang="java">
 
IContainerFactory factory = getContainerManager().getContainerFactory();
 
IContainerFactory factory = getContainerManager().getContainerFactory();
JGroupsClientContainer  jgroupsClient = (JGroupsClientContainer )factory.createContainer( "ecf.jgroups.client", "jgroups:///testConfig?stackName=udp" );
+
 
 +
// create container
 +
JGroupsClientContainer  jgroupsClient = (JGroupsClientContainer )factory
 +
          .createContainer( "ecf.jgroups.client", "jgroups:///testConfig?stackName=udp" );
 +
 
 +
// ID of manager is the url
 
String managerID = IDFactory.getDefault().createID("ecf.namespace.jgroupsid", "jgroups:///testConfig?stackName=udp");
 
String managerID = IDFactory.getDefault().createID("ecf.namespace.jgroupsid", "jgroups:///testConfig?stackName=udp");
 +
 +
// connect client to  manager
 
jGroupsClient.connect( managerID, null );
 
jGroupsClient.connect( managerID, null );
  
Line 118: Line 125:
 
props0.put("jgroups", "doc");
 
props0.put("jgroups", "doc");
  
 +
// send topic interest to the groups
 
jGroupsClient.postEvent(new Event("jgroups", props0));
 
jGroupsClient.postEvent(new Event("jgroups", props0));
  

Revision as of 13:22, 7 March 2011

EIG jgroupslogo.jpg

JGroups Provider

JGroups provider allows to adapt the JGroups protocol to an ECF container, consequently providing all of JGroups capabilities to ECF applications.

Protocol JGroups is documented at the JGroups site.

Required/used Bundles

The Example provider needs the following bundles.

Bundle Description Start Level
org.eclipse.ecf.provider.jgroups The provider / required default
org.eclipse.ecf.provider.jgroups.ui Provides the ui
org.eclipse.ecf.provider.server An example JGroups manager 4
org.eclipse.ecf.clients.jgroups A sample JGroups client default

JGroups Container Instantiation

JGroups container ID : ecf.jgroups.manager

Sample code:

IContainerFactory factory = getContainerManager().getContainerFactory();
IContainer containerManager = factory.createContainer( "ecf.jgroups.manager", "jgroups:///testConfig?stackName=udp" );

All stack names (refer to JGroups site for explanation of stacks) are available in the conf/ directory of distribution plugin. The stack description begins with a config tag. This config can be cut and added in a protocol stack (protocol_stacks) to configure the transport. There is a default stack configured by default with ID : org.eclipse.ecf.provider.jgroups.default. This stack can be configured with the extension point org.eclipse.ecf.provider.jgroups.stackConfig, providing an ID and a config file.

JGroups extension point configuration

The way to initialize a container with his own stack is therefore:

IContainer containerManager = factory.createContainer( "ecf.jgroups.manager", "jgroups:///testConfig?stackID=mystack" );

A file named mystack.xml should have been configured and linked to the extension point in the JGroups plugin.

JGroups Use

Now that the container is initialized, we can use it.

First, we create a client container for the JGroups provider:

IContainer client = ContainerFactory.getDefault().createContainer("ecf.jgroups.client");

Second, we must connect our newly created container to the JGroups group.

		final ID targetID = IDFactory.getDefault().createID(
				client.getConnectNamespace(),
				new Object[] { "jgroups:///testConfig?stackID=mystack" });
		client.connect(targetID, null);

Then, we can repeat this operation as many times as needed.

Now, we could work with the group, relying on JGroups reliable multicast protocols.

A Sample JGroups Client Container

ECF comes with an instance of the OSGi spec admin event service, DistributedEventAdmin which observes events of the framework.

An implementation of an jgroups provider client can implement the org.osgi.service.event.EventAdmin service, providing all jgroups client the availability to send messages with a topic property.

public class JGroupsClientContainer extends ClientSOContainer implements
		EventAdmin {
 
	private final DistributedEventAdmin eventAdminImpl;
 
	public JGroupsClientContainer(SOContainerConfig config)
			throws IDCreateException {
		super(config);
		// hook in context for events
		final BundleContext context = Activator.getContext();
		eventAdminImpl = new DistributedEventAdmin(context);
		eventAdminImpl.start();
 
		// register as EventAdmin service instance
		Properties props0 = new Properties();
		props0.put(EventConstants.EVENT_TOPIC, "*");
		context.registerService(
				"org.osgi.service.event.EventAdmin", eventAdminImpl, props0);
 
	}

Now, as a client, I can post/send == aSync/sync topics on the group.

IContainerFactory factory = getContainerManager().getContainerFactory();
 
// create container
JGroupsClientContainer  jgroupsClient = (JGroupsClientContainer )factory
           .createContainer( "ecf.jgroups.client", "jgroups:///testConfig?stackName=udp" );
 
// ID of manager is the url
String managerID = IDFactory.getDefault().createID("ecf.namespace.jgroupsid", "jgroups:///testConfig?stackName=udp");
 
// connect client to  manager
jGroupsClient.connect( managerID, null );
 
Map props0 = new Hashtable();
props0.put("jgroups", "doc");
 
// send topic interest to the groups
jGroupsClient.postEvent(new Event("jgroups", props0));

The client container has been started and now can be used in this group manager. Here it sends its interest on the topic jgroups with property doc.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.