Event Notification Made Easy - GlassFish V3

Tired of writing the complex event notifiers and the event listeners, you should no longer be.

GlassFish v3, HK2 kernel has a clean and easy way to implement the event notification mechanism. Lets start with a simple Application Event Listener. This Listener will listen to any application deployed, changed or undeployed events.

The object which we are listening should be marked as @Configured :-

@Configured

public interface SomeInterface ...{

}

Now the Listener Should implement the ConfigListener Interface.

The Listener for Application Events will look like:

@Service
public class Listener implements ConfigListener {

The object for which we are implementing the listener.
    @Inject
    private Applications allApplications; 

The Following function provides the notifications of the Event.

public UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
    final UnprocessedChangeEvents unprocessed = ConfigSupport.sortAndDispatch(events, new Changed() {

    public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> changedType, T changedInstance) {
                switch (type) {
                    case ADD: //
changedInstance was added to the parent
                        break;
                    case CHANGE: //
changedInstance has mutated
                        break;
                    case REMOVE: //
changedInstance was removed from the parent
                        break;
                    default:
                        break;
                }
            }
}

Whenever some Application Event Occurs all the implementors of ConfigListener which are injecting the Applications interface are notified.

Comments:

I have a simple question: how is this class, Listener, run. I mean, it must be a MBean and deployed on the Mbean server, or it is run as a standalone application?

Posted by anca on September 15, 2010 at 11:04 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Mohit Gupta

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today