KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > JmsHostEventListener


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.server;
25
26 import com.sun.enterprise.admin.event.AdminEventListener;
27 import com.sun.enterprise.admin.event.AdminEventListenerException;
28 import com.sun.enterprise.admin.event.jms.*;
29 import com.sun.enterprise.config.serverbeans.*;
30 import com.sun.enterprise.config.*;
31 import com.sun.enterprise.connectors.*;
32 import com.sun.enterprise.connectors.system.*;
33
34
35
36 /**
37  * Listener class to handle jms-host element events.
38  *
39  * @author: Binod
40  */

41 public class JmsHostEventListener implements
42              com.sun.enterprise.admin.event.jms.JmsHostEventListener {
43
44     private ConnectorRegistry registry = ConnectorRegistry.getInstance();
45
46     /**
47      * Handles jms-host element removal.
48      * It is called whenever a JmsHostEvent is received.
49      *
50      * @param event Event to be processed.
51      *
52      * @throws AdminEventListenerException when the listener is unable to
53      * process the event.
54      */

55     public void handleDelete(JmsHostEvent event)
56              throws AdminEventListenerException {
57         reloadRA(event);
58         //getAdapter().deleteJmsHost(host);
59
}
60
61     /**
62      * Handles jms-host element modification
63      * (attributes/properties values changed).
64      * It is called whenever a JmsHostEvent is received.
65      *
66      * @param event Event to be processed.
67      *
68      * @throws AdminEventListenerException when the listener is unable to
69      * process the event.
70      */

71     public void handleUpdate(JmsHostEvent event)
72              throws AdminEventListenerException {
73         reloadRA(event);
74         //getAdapter().updateJmsHost(host);
75
}
76
77     /**
78      * Handles element additions.
79      * It is called whenever a JmsHostEvent is received.
80      *
81      * @param event Event to be processed.
82      *
83      * @throws AdminEventListenerException when the listener is unable to
84      * process the event.
85      */

86     public void handleCreate(JmsHostEvent event)
87              throws AdminEventListenerException {
88          reloadRA(event);
89         //getAdapter().addJmsHost(host);
90
}
91
92     private void reloadRA(JmsHostEvent event) throws AdminEventListenerException {
93         try {
94             JmsService service = (JmsService) getJmsService(event);
95             ActiveJmsResourceAdapter aja = getAdapter();
96             if (aja != null) {
97                getAdapter().reloadRA(service);
98             }
99         } catch (ConnectorRuntimeException cre) {
100             AdminEventListenerException ale =
101                 new AdminEventListenerException(cre.getMessage());
102             ale.initCause(cre);
103             throw ale;
104         } catch (ConfigException ce) {
105             AdminEventListenerException ale =
106                 new AdminEventListenerException(ce.getMessage());
107             ale.initCause(ce);
108             throw ale;
109         }
110     }
111
112     private ActiveJmsResourceAdapter getAdapter(){
113         return (ActiveJmsResourceAdapter)
114         registry.getActiveResourceAdapter(ConnectorRuntime.DEFAULT_JMS_ADAPTER);
115     }
116
117     private JmsService getJmsService(JmsHostEvent event) throws ConfigException{
118         ConfigContext context = event.getConfigContext();
119         return ServerBeansFactory.getJmsServiceBean(context);
120     }
121 }
122
Popular Tags