This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Event handling

 
Ranadhir Nag
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone point me to a sample involving non-component based event handling?
All the samples that i find are event handlers being tied to AWT components?
I just wish to write a simple server which calls back on registered listeners(clients),by programmatically raising an event from one of the clients.
Any help will be appreciated.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you taken a look to the java.util.Observer and java.util.Observable?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not a fan of Observer and Observable in the library. Before I even found them I made my own pub-sub with an intermediary. The flow is described HERE. I make an interface with methods for the events, implement it once in the intermediary and again in each subscriber. Here's an example with two events:

The abstract Publisher has (dead simple) methods to subscribe and unsubscribe. Some may be offended that I have to copy-paste that little loop for every event. But the flexibility I have here is pretty cool. I can pass parameters and get return types. I could let all the listeners vote on what to do next or let one of them signal that it has consumed the event and stop looping. I can have multiple publishers for the same event. Publishers can come and go while the subscription persists. Good fun.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic