Interaction Between two plugins

Hi,

I’m trying to establish communication between two plugins. Here one plugin will signal another plugin when it’s done with certain task and other plugin, upon receiving the signal, will start working. I’m trying to implement this using events. So first plugin will raise an event and other plugin will be invoked by listening to it. But, I don’t know if this is possible by using custom event. Any help on how should I move forward with this?

Thanks in advance.

Hi Ankit,
you can do this with events.
The easiest case is that the custom event only uses “generally available” datatypes, e.g. String, Long or datatypes from the system bundle (e.g. Page) or other generally available datatypes - otherwise you might get complicated OSGi import / export relationships.
Also think about that events are still processed synchonously (afaik), i.e. within the same thread. So if you need to do long running stuff, you might need some kind of hand-off mechanism, if the thread that published the event shouldn’t wait for a long time (e.g. a HTTP request thread probably shouldn’t wait for a few minutes, or you will get all kinds of errors - unresponsive UI, depletion of threads, request timeouts).

Cheers, Chris

Hi Chris,

Thanks for replying. I thought of using custom event. But the thing here is that I want to use a simple POJO as an event just to signal other plugin that it should start working. It’ll get some data which is not possible with my plugin and that will take only few seconds. After that the second plugin will store data in global storage(pluginSettings map) which we are using to pass information.

Problem here is that the listening plugin might be able to access the custom event as I’ve no way to import it there. Or I have but I don’t know it. Can you please explain your solution with an example? I can share the code I’m trying to write if you want.

Thanks,

Hi,
it’s all a question of who depends on who.
In my case I have an event defined in plugin A and plugin A also publishes that event using the eventPublisher.publish method. Plugin A also exports that event definition via OSGi.
Plugin B listens for that event and imports the definition via OSGi, that’s it.
In my case Plugin A cannot depend on the Plugin B, because plugin B is optional, but plugin B can depend on A.

If you cannot have that kind of relationship, without having tested this - you could still publish an event in the form of a generally available datatype, e.g. a Map. The map should only use datatypes that are also available to the event consumer and it should have some kind of unique type identifier that you can filter on (so you do not consume events that are a Map from other events).

Cheers, Chris