I want to write an Event based notification system in java,have no idea where to start with though have gone through some study materials regarding Event handling, but could not find any thing worth while for me.
I want to write my own custom events. These custom events will be triggered when a method executes. I am pasting a small code...
Now when ever the method display gets called, a custom event gets triggered saying the display method is called.
Just one last thing the custom event is not a window based event,it should rather be a console based..
will be really thankful if any one of you can help, a small example would be of really great help. Hope i make sense and is asking for something which is not against ranch policy...
Event handling is nothing magic, just ordinary Java method calls in an interesting decoupled design. The two main parts of the problem are keeping track of who is interested in which events and then notifying them when something happens.
Java comes with the Observable and Observer framework for both parts. I found them a bit clunky and wrote my own more flexible scheme. I use an "intermediary" which is optional in some publish subscribe pattern discussions. See if this looks useful:
I actually hand-code a new intermediary for every new set of related event messages. The base class handles the subscriber lists and the hand made one forwards the event to all listeners. Here's a complete example. It's some years old; I'm sure I'd do it a bit differently nowdays ...
See more background (sales pitch about why I like this) HERE
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
F is for finger. Can you stick your finger in your nose? Doesn't that feel nice? Now try this tiny ad:
Create Edit Print & Convert PDF Using Free API with Java