Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » IEventBroker without data(possible to send no data?)
IEventBroker without data [message #822222] Fri, 16 March 2012 10:16 Go to next message
Beat Schaller is currently offline Beat SchallerFriend
Messages: 42
Registered: July 2009
Member
Hi

I am working heavily with IEventBroker and have some difficulties with it.

If I send, the structure is always:
eventBroker.post(Events.PRODUCER_INITIALIZED, new Oject());
Why do I have to post always an object, if I just want to notify? Sad

On the other hand to receive:
@Inject
void eventReceived(@Optional @UIEventTopic(Events.PRODUCER_INITIALIZED) final Object object) {
if (object!= null) {
...
}
}
If I have this method in a part, I always habe to check if the object is not null, because it always is injected when the part isr created. Even if no Event ist posted!!

Wouldn't it be nice to send Events without arguments? like:
eventBroker.post(Events.PRODUCER_INITIALIZED);

and to get this messages like:
@Inject
void eventReceived(@Optional @UIEventTopic(Events.PRODUCER_INITIALIZED)) {
// i am in this method only if I get an event!
}

regards
Beat
Re: IEventBroker without data [message #822324 is a reply to message #822222] Fri, 16 March 2012 13:22 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Beat

I use the service like this. Note that I use "@Optional" on the function and not on the parameter. This will only be called if a new event is created.

@Inject @Optional
private void openNewSchreibauftrag(@UIEventTopic(SaConstants.TOPIC_INPUT) ISchreibauftrag data) {
	logger.trace("openNewSchreibauftrag called with Event: {}", data);
	...
}


To send an event:

eventBroker.send(SaConstants.TOPIC_INPUT, sa);

Where sa is an instance of ISchreibauftrag

Greetings
Christoph
Re: IEventBroker without data [message #822344 is a reply to message #822324] Fri, 16 March 2012 13:51 Go to previous messageGo to next message
Beat Schaller is currently offline Beat SchallerFriend
Messages: 42
Registered: July 2009
Member
Thx, yes indeed. Works better in the case of the creation of a part. Only when a message is posted I receive one.

There is still left the "not so beautiful" definition of the interface with an object.
So if I want to send just a notification I have to define:

    eventBroker.post(Events.SAMPLE_EVENT, null);
    // have to send a null-Object


and receiving
    @Inject
    @Optional
    void eventReceived(@UIEventTopic(Events.SAMPLE_EVENT) final Object data) {
        // have to define Object, but can ignore it
    }


Greetings
Beat
Re: IEventBroker without data [message #822825 is a reply to message #822222] Sat, 17 March 2012 10:18 Go to previous messageGo to next message
Eclipse UserFriend
Beat Schaller wrote on Fri, 16 March 2012 12:16
Hi


and to get this messages like:
@Inject
void eventReceived(@Optional @UIEventTopic(Events.PRODUCER_INITIALIZED)) {
// i am in this method only if I get an event!
}


You HAVE to have a parameter because that parameter is actually being annotated. In the snippet above the annotations do not annotate anything. One way would be to move those annotations to the method itself and to overload the post and send methods of the event broker to support just one argument. Also if I remember correctly the annotation itself (uieventtopic) doesn't support method annotation.

If I got you correctly than I believe it is too much of a change just avoid a null check, however tedious it might be.

Sopot
Re: IEventBroker without data [message #824225 is a reply to message #822825] Mon, 19 March 2012 12:10 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 242
Registered: July 2009
Senior Member
Rather than pass null or a dummy object when sending/posting your event, why don't you pass your actual consumer instance? It could be helpful for debugging later. And ignore it otherwise. Remember that the IEventBroker/EventAdmin is global across your OSGi framework instance. This could be important if you have multiple producers.

Oh and if the arg type is org.osgi.services.event.Event (from memory), the UIEventTopic/EventTopic injected value will be the actual Event object too, which might be useful.
Previous Topic:The parent Shell problem in XWT
Next Topic:Screen flash before app starts
Goto Forum:
  


Current Time: Thu Apr 25 00:19:23 GMT 2024

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

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

Back to the top