Home » Eclipse Projects » Eclipse 4 » Syncing different Parts together
Syncing different Parts together [message #1663497] |
Tue, 10 March 2015 12:55 |
|
Dear experts,
this is a more of a high-level design question.
I am building an E4 RCP application here, where I have a central GIS map and 1+ parts (eg JFace viewers) which I want to be tightly synchronized altogether.
I would like to ask to you all what would be your personal approach to this task, implementation-wise, keeping into account that performance counts here due to the heavy burden of map updates/editing.
I have the feeling that using a sort of "star-shaped" data-binding (1 observable model with N GUI elements on the other end) is the most robust method here, while playing with sending/posting events + DI is somewhat more loosely-coupled and more prone to errors.
How would you tackle this architecture?
How does Eclipse itself work it out?
Thanks for any help,
-Piero
[Updated on: Tue, 10 March 2015 13:39] Report message to a moderator
|
|
| |
Re: Syncing different Parts together [message #1668112 is a reply to message #1668032] |
Thu, 12 March 2015 10:34 |
|
Thank you for sharing Mateusz,
so you have based your whole architecture on messages being sent over the event bus, where listeners react by using the @UIEventTopic annotation as method params. Is that correct?
I am however not sure about this UISynchronizer object you send around: are you using it explicitly?
Is that still reliable when you combine N fragment plugins in order to build an application? I mean, I guess so but I am experiencing unpredictable and somewhat aleatory behaviours here, maybe due to conflicts between plugins which share the same application context / event bus.
Sometimes I see as well that sending and posting an event via broker can produce very different results, and I am not sure about how the framework handles the buffers for asynchronized events down there, or how to control it.
Thank you very much for any hint, reference, or help,
-Piero
[Updated on: Thu, 12 March 2015 10:35] Report message to a moderator
|
|
|
Re: Syncing different Parts together [message #1668861 is a reply to message #1668112] |
Thu, 12 March 2015 17:22 |
Mateusz Malinowski Messages: 36 Registered: March 2013 Location: Bristol |
Member |
|
|
Hi Piero,
The @UIEventTopic is used purely for EventBroker, when it sends message to its listeners. Note, that this annotation forces that method to be run on UI thread. If you want to avoid that, just use @EventTopic. The latter creates a separate thread to handle the method.
EventBroker just sends data here and there. And it is bounded to those classes which have access to E4 Model (parts, handlers, addons, etc). I have a model that is a singleton class to be accessed by any other java class in my application. It also stores all most important data (e.g. some classes which are too big to be saved in preferences and can be easily instantiated at the application start-up). Now this singleton class provides a method to register a listener (interface with one method) and method that will trigger its listeners update method. This allows to transport data to all classes in the application.
Now UISynchronizer can be injected in any part. And if this part listens to your model updates, it will automatically receive new data. But this update doesn't happen on UI thread, so the UISynchronizer allows to dispatch runnable on the UI thread (synchronizer.async or something like that).
So generally, your data is being transported using as many non-UI threads as you want, and the UI thread will only update your controls, maps, etc. with current model state.
And this approach works well on application with multiple plugins and fragment.e4xmi files.
Send and post methods from EventBroker are quite nice for synchronisation, as one of them returns straight away, while the other blocks current thread. Just remember that when you use event broker from UI thread, not to block it. Otherwise you will have deadlock. There are many ways how you can exploit this functionality.
Mateusz
|
|
| |
Re: Syncing different Parts together [message #1691720 is a reply to message #1668861] |
Thu, 09 April 2015 09:37 |
|
Dear Mateusz + @all,
my experience so far pushes me to some confusion with regards to @EventTopic and @UIEventTopic.
While I successfully received a non-UI-related event (sent via broker within the same plugin/bundle) with my optional @EventTopic annotation in the handler, I could not receive an OSGi (sent via EventAdmin in an other plugin/bundle) with it.
Surprisingly changing my annotation to @UIEventTopic fix things.
Why is this happening? I was expecting a pure OSGi event to me more probably caught by an @EventTopic rather than UI event.
Thanks for your clarifications
-Piero
PS Declaring an event handler with OSGi XML component works fine too, but I like annotations more than DS since I can read the event ID right inside the handler and not somewhere else.
|
|
| |
Re: Syncing different Parts together [message #1691769 is a reply to message #1691726] |
Thu, 09 April 2015 14:30 |
|
Thank you Dirk,
as you know already, I found it very useful
Regarding this topic, still I double-checked all the conditions and there was nothing missing (apparently): I confirm that @EventTopic is broken, and additionally after a couple of successfull handling, neither the @UIEventTopic now is working.
Only the service component event handler successfully receives the event now: I can just stick to it but it would be highly educative to understand what is breaking up things here... There are some hidden factors here that go beyond single plugin configuration.
In general, there are frequent unexpected behaviours (of course, by no means dependent on Eclipse, certainly my misuse).
@Dirk: for instance, I tried to fetch the EventAdmin service programmatically from the bundle activator instead via DS, and I had to run it 2-3 times getting some NullPointerException before magically getting it to work smoothly (but without changing no-line): these kind of things. What are my colleagues and I missing?
|
|
| |
Re: Syncing different Parts together [message #1691851 is a reply to message #1691773] |
Fri, 10 April 2015 07:33 |
|
Hi Dirk,
thanks again.
Well no: now both @EventTopic and @UIEventTopic do not work. I do not have to update the UI, I was just using the latter because it worked a couple of times at first before it would break without any explicit code/configuration change.
I take the EventAdmin service via the ServiceTracker, like done in the Eclipse EventBroker:
@SuppressWarnings({ "unchecked", "rawtypes" })
public EventAdmin getEventAdmin() {
if (eventAdminTracker == null) {
eventAdminTracker = new ServiceTracker(bundleContext,
EventAdmin.class.getName(), null);
eventAdminTracker.open();
}
return (EventAdmin) eventAdminTracker.getService();
}
By now I'll just go with my handler declared as OSGi component, no big issue. If any further ideas come out, please post here. Thanks again to all of you
[Updated on: Fri, 10 April 2015 07:34] Report message to a moderator
|
|
| | | |
Goto Forum:
Current Time: Wed Sep 25 14:38:49 GMT 2024
Powered by FUDForum. Page generated in 0.10676 seconds
|