Multiple topics for DistributedEventAdmin [message #1008255] |
Mon, 11 February 2013 13:37  |
Eclipse User |
|
|
|
I have a bundle which has registered a distributedeventadmin for a particular topic:
EventAdmin admin = new DistributedEventAdmin(context);
IContainer container = manager.getContainerFactory().createContainer("ecf.generic.server");
sharedObjectContainer = (ISharedObjectContainer) container.getAdapter(ISharedObjectContainer.class);
ISharedObjectManager manager1 = sharedObjectContainer.getSharedObjectManager();
Properties props = new Properties();
props.put(EventConstants.EVENT_TOPIC, "uk_co_xlegal_xbundle3_remote");
manager1.addSharedObject(IDFactory.getDefault().createStringID("uk.co.xlegal.xbundle3.remote"), (ISharedObject) admin, props);
I have a second bundle, which needs to register another topic for distribution by the DistributedEventManager. I was thinking along the lines of:
//assume these get the registered distributedeventadmin and icontainermanager
admin = (EventAdmin) this.getServiceImplementingClass(EventAdmin.class)
IContainerManager manager = (IContainerManager) this.getServiceImplementingClass(IContainerManager.class
//could be done better, I'm sure
IContainer[] containers = manager.getAllContainers();
IContainer container = (containers.length == 1)? containers[0] : null;
ISharedObjectContainer sharedObjectContainer = (ISharedObjectContainer) ((IAdaptable) container).getAdapter(ISharedObjectContainer.class);
ISharedObjectManager manager1 = sharedObjectContainer.getSharedObjectManager();
Properties props = new Properties();
props.put(EventConstants.EVENT_TOPIC, "uk_co_xlegal_liveshow_annotation");
//do I just re-register the distributedeventadmin in the sharedobjectmanager with the additional topic as a property?
manager1.addSharedObject(IDFactory.getDefault().createStringID("uk_co_xlegal_liveshow_annotation"), (ISharedObject) admin, props);
Is this the correct way of doing this?
Thanks
Robert
|
|
|
Re: Multiple topics for DistributedEventAdmin [message #1008304 is a reply to message #1008255] |
Mon, 11 February 2013 15:04   |
Eclipse User |
|
|
|
Hi Robert.
Robert Onslow wrote on Mon, 11 February 2013 13:37I have a bundle which has registered a distributedeventadmin for a particular topic:
EventAdmin admin = new DistributedEventAdmin(context);
IContainer container = manager.getContainerFactory().createContainer("ecf.generic.server");
sharedObjectContainer = (ISharedObjectContainer) container.getAdapter(ISharedObjectContainer.class);
ISharedObjectManager manager1 = sharedObjectContainer.getSharedObjectManager();
Properties props = new Properties();
props.put(EventConstants.EVENT_TOPIC, "uk_co_xlegal_xbundle3_remote");
manager1.addSharedObject(IDFactory.getDefault().createStringID("uk.co.xlegal.xbundle3.remote"), (ISharedObject) admin, props);
Right. This very similar to what's in the eventadmin example
Quote:
I have a second bundle, which needs to register another topic for distribution by the DistributedEventManager. I was thinking along the lines of:
//assume these get the registered distributedeventadmin and icontainermanager
admin = (EventAdmin) this.getServiceImplementingClass(EventAdmin.class)
IContainerManager manager = (IContainerManager) this.getServiceImplementingClass(IContainerManager.class
//could be done better, I'm sure
IContainer[] containers = manager.getAllContainers();
IContainer container = (containers.length == 1)? containers[0] : null;
ISharedObjectContainer sharedObjectContainer = (ISharedObjectContainer) ((IAdaptable) container).getAdapter(ISharedObjectContainer.class);
ISharedObjectManager manager1 = sharedObjectContainer.getSharedObjectManager();
Properties props = new Properties();
props.put(EventConstants.EVENT_TOPIC, "uk_co_xlegal_liveshow_annotation");
//do I just re-register the distributedeventadmin in the sharedobjectmanager with the additional topic as a property?
manager1.addSharedObject(IDFactory.getDefault().createStringID("uk_co_xlegal_liveshow_annotation"), (ISharedObject) admin, props);
Is this the correct way of doing this?
No, I don't think this will do what you are looking to do. First, though...let me ask: are you running multiple containers (with unique ids...like: ecftcp://host:3282/server and ecftcp://host:3282/server1? The reason I ask is that it is possible to do this (multiple container instances...with different paths...running on the same port).
I don't think you are doing this, although, it is possible. Rather, it looks like you have one server container (i.e. with ID ecftcp://host:3282/server or similar), and that you want to create and register *another* EventAdmin...so that this server can send and/or receive on a new topic. It seems like this is what you are looking to do...if my interpretation is incorrect then let me know and I'll adjust.
If this is correct (that you want to have a completely new topic and EventAdmin available), then what you should probably do is create a new DistributedEventAdmin instance, call start() on it, then add it to the container instance (i.e. the one with ID=ecftcp://host:3282/server if there are multiples). So the code to do this would/should look something like:
Given: newTopic
EventAdmin newEventAdmin = new DistributedEventAdmin(context);
newEventAdmin.start();
ISharedObjectMangager soManager = getSOManager(); // get appropriate container and the shared object manager it exposes
// Add this new DistributedAdmin...identified within container via *newTopic*
soManager.addSharedObject(IDFactory.createStringID(newTopic),newEventAdmin,null);
// Start newEventAdmin...since it's now added
newEventAdmin.start();
// register the new EventAdmin with newTopic
Map props = new HashMap();
props.put(EventConstants.EVENT_TOPIC,newTopic);
context.registerService(EventAdmin.class.getName(),newEventAdmin,props);
// At this point, EventAdmin service (implemented by newEventAdmin) will be available...e.g. EventAdmin ServiceTrackers (and/or ds) can filter by EVENT_TOPIC to get the EventAdmin of the proper topic...for sending. And EventHandlers can be registered with this newTopic to receive messages sent to that topic.
Does this help with your use case?
|
|
|
|
Powered by
FUDForum. Page generated in 0.05210 seconds