Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Question about @EventTopic annotations
Question about @EventTopic annotations [message #870134] Sun, 06 May 2012 21:38 Go to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
Hi everybody,

I am playing with the IEventBroker service and @EventTopic injections
but I have some unexpected behaviors that I don't understand, so I am
asking for some help.

I am using Eclipse Juno M6 + Eclipse E4 Tools + Eclipse E4 Tools Bridge
for 3.x

Basically I have two POJOs (PublishView and SubscribeView) that define
two views, one with a button for posting events, and the other one which
defines a handler.

I also have two DIViewPart for displaying these views inside an instance
of the SDK.

The code is pretty straighforward and it's here:
http://pastebin.com/dTTq4Knw

The PublishView has an injected IEventBroker field so that I can do a
eventBroker.send("foo", "Hello") when the button is pressed.

The SubscribeView has the following method for handling the events
posted on the "foo" topic:

@Inject
public void handleFoo(@EventTopic("foo") Object data) {
System.out.format("Received foo: %s\n", data);
}

Now, what I expected was to see on the console a "Received foo: hello"
message each time I press the button. But, instead, I have the following
behavior:

1) If I run the plugin in the SDK, at startup I see on the console a
message like this one:

Received foo:
org.eclipse.equinox.console.command.adapter.CommandProviderAdapter@217a26f4

1.1) When I click the button, eventBroker.send("foo", "hello") is called
but nothing is received by the handler

2) If I run the plugin as an E4 RCP application, at startup I see on the
console the following exception:

org.eclipse.e4.core.di.InjectionException: Unable to process
"SubscribeView#handleFoo()": no actual value was found for the argument
"Object[@org.eclipse.e4.ui.di.UIEventTopic(value=foo)]".

2.1) If I click the button everything works. I correctly see "Received
foo: Hello" messages on the console every time I press the button.

Now the questions are:

* What are the two "spurious" events that I receive at startup? I mean,
"foo" is not a topic that should be used anywhere in the platform, so
why do I receive events from the platform on that topic?

* Why the brokering mechanism doesn't work in the SDK while it seems to
work fine in the RCP application? Is it a limitation of the Bridge?

Thank you for your help.

-Fabio
Re: Question about @EventTopic annotations [message #870169 is a reply to message #870134] Mon, 07 May 2012 06:56 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5469
Registered: July 2009
Senior Member
Am 06.05.12 23:38, schrieb Fabio Mancinelli:
> Hi everybody,
>
> I am playing with the IEventBroker service and @EventTopic injections
> but I have some unexpected behaviors that I don't understand, so I am
> asking for some help.
>
> I am using Eclipse Juno M6 + Eclipse E4 Tools + Eclipse E4 Tools Bridge
> for 3.x
>
> Basically I have two POJOs (PublishView and SubscribeView) that define
> two views, one with a button for posting events, and the other one which
> defines a handler.
>
> I also have two DIViewPart for displaying these views inside an instance
> of the SDK.
>
> The code is pretty straighforward and it's here:
> http://pastebin.com/dTTq4Knw
>
> The PublishView has an injected IEventBroker field so that I can do a
> eventBroker.send("foo", "Hello") when the button is pressed.
>
> The SubscribeView has the following method for handling the events
> posted on the "foo" topic:
>
> @Inject
> public void handleFoo(@EventTopic("foo") Object data) {
> System.out.format("Received foo: %s\n", data);
> }
>
> Now, what I expected was to see on the console a "Received foo: hello"
> message each time I press the button. But, instead, I have the following
> behavior:
>
> 1) If I run the plugin in the SDK, at startup I see on the console a
> message like this one:
>
> Received foo:
> org.eclipse.equinox.console.command.adapter.CommandProviderAdapter@217a26f4
>
> 1.1) When I click the button, eventBroker.send("foo", "hello") is called
> but nothing is received by the handler
>
> 2) If I run the plugin as an E4 RCP application, at startup I see on the
> console the following exception:
>
> org.eclipse.e4.core.di.InjectionException: Unable to process
> "SubscribeView#handleFoo()": no actual value was found for the argument
> "Object[@org.eclipse.e4.ui.di.UIEventTopic(value=foo)]".
>

You should put a @Optional in there and the message will go away.

> 2.1) If I click the button everything works. I correctly see "Received
> foo: Hello" messages on the console every time I press the button.
>
> Now the questions are:
>
> * What are the two "spurious" events that I receive at startup? I mean,
> "foo" is not a topic that should be used anywhere in the platform, so
> why do I receive events from the platform on that topic?

It looks like the event injection code is not stepping in correctly

>
> * Why the brokering mechanism doesn't work in the SDK while it seems to
> work fine in the RCP application? Is it a limitation of the Bridge?
>

Need to check this but there should not be a difference. I'll come back
once I tried this my own.

Tom
Re: Question about @EventTopic annotations [message #870292 is a reply to message #870169] Mon, 07 May 2012 15:10 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5469
Registered: July 2009
Senior Member
[...]

> Need to check this but there should not be a difference. I'll come back
> once I tried this my own.
>

Ok 2 observations:
a) One needs to use @Optional
b) One should not use Object (to me this looks like a bug because it
looks like if there's a key stored in the IEclipseContext things
break the event system injection!)

Tom
Re: Question about @EventTopic annotations [message #870293 is a reply to message #870292] Mon, 07 May 2012 15:12 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5469
Registered: July 2009
Senior Member
Here the method for reference
> @Inject
> @Optional
> void eventReceived(@UIEventTopic("foo") String data) {
> if( data != null && viewer != null) {
> viewer.add(data);
> }
> }



Am 07.05.12 17:10, schrieb Tom Schindl:
> [...]
>
>> Need to check this but there should not be a difference. I'll come back
>> once I tried this my own.
>>
>
> Ok 2 observations:
> a) One needs to use @Optional
> b) One should not use Object (to me this looks like a bug because it
> looks like if there's a key stored in the IEclipseContext things
> break the event system injection!)
>
> Tom
Re: Question about @EventTopic annotations [message #870309 is a reply to message #870292] Mon, 07 May 2012 15:47 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5469
Registered: July 2009
Senior Member
See https://bugs.eclipse.org/bugs/show_bug.cgi?id=378694 my suggested
workaround would be to use @Named("__DUMMY__").

Tom

Am 07.05.12 17:10, schrieb Tom Schindl:
> [...]
>
>> Need to check this but there should not be a difference. I'll come back
>> once I tried this my own.
>>
>
> Ok 2 observations:
> a) One needs to use @Optional
> b) One should not use Object (to me this looks like a bug because it
> looks like if there's a key stored in the IEclipseContext things
> break the event system injection!)
>
> Tom
Re: Question about @EventTopic annotations [message #870367 is a reply to message #870293] Mon, 07 May 2012 20:01 Go to previous messageGo to next message
Fabio Mancinelli is currently offline Fabio MancinelliFriend
Messages: 16
Registered: July 2009
Junior Member
On 05/07/2012 05:12 PM, Tom Schindl wrote:
> Here the method for reference
>> @Inject
>> @Optional
>> void eventReceived(@UIEventTopic("foo") String data) {
>> if( data != null&& viewer != null) {
>> viewer.add(data);
>> }
>> }
>
>
Thanks Tom. It worked perfectly.

I was pretty sure of having also done a test using the String data
parameter but it was not the case.

Thanks again,
Fabio


>
> Am 07.05.12 17:10, schrieb Tom Schindl:
>> [...]
>>
>>> Need to check this but there should not be a difference. I'll come back
>>> once I tried this my own.
>>>
>>
>> Ok 2 observations:
>> a) One needs to use @Optional
>> b) One should not use Object (to me this looks like a bug because it
>> looks like if there's a key stored in the IEclipseContext things
>> break the event system injection!)
>>
>> Tom
>
Re: Question about @EventTopic annotations [message #870373 is a reply to message #870367] Mon, 07 May 2012 20:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5469
Registered: July 2009
Senior Member
If you add @Named() like described in the bug this ensures you don't get
broken if someone pushed something with java.lang.String into the a
parent IEclipseContext!

Not sure this bug gets fixed for 4.2!

Tom

Am 07.05.12 22:01, schrieb Fabio Mancinelli:
> On 05/07/2012 05:12 PM, Tom Schindl wrote:
>> Here the method for reference
>>> @Inject
>>> @Optional
>>> void eventReceived(@UIEventTopic("foo") String data) {
>>> if( data != null&& viewer != null) {
>>> viewer.add(data);
>>> }
>>> }
>>
>>
> Thanks Tom. It worked perfectly.
>
> I was pretty sure of having also done a test using the String data
> parameter but it was not the case.
>
> Thanks again,
> Fabio
>
>
>>
>> Am 07.05.12 17:10, schrieb Tom Schindl:
>>> [...]
>>>
>>>> Need to check this but there should not be a difference. I'll come back
>>>> once I tried this my own.
>>>>
>>>
>>> Ok 2 observations:
>>> a) One needs to use @Optional
>>> b) One should not use Object (to me this looks like a bug because it
>>> looks like if there's a key stored in the IEclipseContext things
>>> break the event system injection!)
>>>
>>> Tom
>>
>
Re: Question about @EventTopic annotations [message #992827 is a reply to message #870373] Sat, 22 December 2012 19:14 Go to previous message
Steven Spungin is currently offline Steven SpunginFriend
Messages: 4
Registered: December 2012
Junior Member
This works:
@Inject
@Optional
void onRemoveTags(@UIEventTopic(Topics.COMMAND_REMOVE_TAGS) String object)

called by:
broker.post(Topics.COMMAND_REMOVE_TAGS, null);

However this code is not called from the broker, but IS called during startup with org.eclipse.equinox.console.command.adapter.CommandProviderAdapter as the object
@Inject
@Optional
void onRemoveTags(@UIEventTopic(Topics.COMMAND_REMOVE_TAGS) Object object)

I would assume that using a specified @UIEventTopic would be on par with using @Named and should be properly resolved, even with Object as the parameter. I am using the latest 4.3 stream build.
Previous Topic:Background image on main shell
Next Topic:E4 to RAP Migration
Goto Forum:
  


Current Time: Fri Nov 28 08:55:52 GMT 2014

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

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