Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating an Event Listener Using Java Threads

 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I need to create an simple Event Listener (in core java using java threads) which consumes the events of same group Id. So, if there are 10 different events of 2 different groups i.e. total 20 events, then it should process for one group.

PLEASE NOTE THAT THE LISTENER SHOULD NOT WAIT FOR CERTAIN NUMBER OF EVENTS TO APPEAR. IT SHOULD CONSUME BASED ON WHAT IS AVAILABLE IN THE QUEUE.

FOR INSTANCE, if following events are published:
eventId GroupId Payload
1 3 first
2 4 second
3 3 third
4 7 fourth
5 3 fifth
6 4 sixth
7 4 seventh

then, it should just take the first event i.e. event with Id = 1 and take all the events that having same group Id i.e events with Id - 1, 3, & 5. It should remove them from the queue, merge the payload to be "first third fifth" and create a GroupEvent with this details.

This is to be used in very high volume environment so you should consider the performance.

AS per my knowledge Observer pattern could be used.

Please do let me know more ideas through which I can start building my event listener as per the requirements.

Thanks and Regards,
Sid

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you set on writing your own, or would an existing solution like Guava's EventBus suffice?

I'm not clear on how you envision threads to fit in, though - what do they have to do with event delivery?
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to write my own as per my requirements mentioned above ... which are different.

Threads are likely to fit in as they could be a situation where listeners are called in a different thread from which they were registered.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see nothing in those requirements that wouldn't be met by EventBus...?

The only use case I can readily think of where it mattered in which thread listeners are called would be desktop apps - where the listener may need to do something with the GUI, so it would have to be the event thread. But it doesn't sound like this would be used in a desktop app, correct?
 
Siddharth Bhargava
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not making this for the GUI (like Swing GUI) ... its just a simple event listener for listening for events for a particular group.....
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that case my comment about not seeing anything that Guava's EventBus couldn't handle stands.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!