Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » E4 Injection/Event System(Keeping 3 objects in sync.)
E4 Injection/Event System [message #1692371] Wed, 15 April 2015 11:31 Go to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Hi,

short description: I need to keep three objects in sync.
So, whenever A changes I need to first update B and then update C.
All objects are in the eclipse context.

I came up with the following way, but am unsure if it is unsafe or bad style.
Let's say, we start by injecting object A into the eclipse context:
context.set(A.class, a);


In order to get object B in sync, I was thinking about implementing the following code to a manager class which is always present in the context:
@Inject
@Optional
public void doProcessing(A a) {
    B b = new B(a));
    context.set(B.class, b);
}


Within class C which is created at program startup, I would do the following:
@Inject
@Optional
private A a;

@Inject
@Optional
public void doProcessing(B b) {
    //do something with a and b!
}


What do you think about this? Would you rather use the event system?
Re: E4 Injection/Event System [message #1692376 is a reply to message #1692371] Wed, 15 April 2015 11:51 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
[...]

> @Inject
> @Optional
> private A a;
>
> @Inject
> @Optional
> public void doProcessing(B b) {
> //do something with a and b!
> }
>

I'm 99% sure that you could do:

@Inject
@Optional
public void doProcessing(A a, B b) {
//do something with a and b!
}
Re: E4 Injection/Event System [message #1692383 is a reply to message #1692376] Wed, 15 April 2015 12:18 Go to previous messageGo to next message
Alexander Klatt is currently offline Alexander KlattFriend
Messages: 59
Registered: April 2014
Member
Actually it seems as I must to do it like that.
For my example, object A was null for some reason. Racing condition?

But would you rather use events for this or does it seem okay?

Thomas Schindl wrote on Wed, 15 April 2015 11:51
[...]
I'm 99% sure that you could do:

@Inject
@Optional
public void doProcessing(A a, B b) {
//do something with a and b!
}

[Updated on: Wed, 15 April 2015 12:31]

Report message to a moderator

Re: E4 Injection/Event System [message #1692414 is a reply to message #1692383] Wed, 15 April 2015 14:12 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2903
Registered: July 2012
Senior Member
In case of racing conditions on multiple value injection you might want to look at @GroupUpdates which is intended to batch updates.

https://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection#.40GroupUpdates_.28org.eclipse.e4.core.di.annotations.29
Previous Topic:Syncing different Parts together
Next Topic:Switching binding context based on selection
Goto Forum:
  


Current Time: Tue Sep 24 04:39:12 GMT 2024

Powered by FUDForum. Page generated in 0.03824 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top