KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > monitor > registry > spi > reconfig > MonitoringConfigChangeListener


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 /*
25  * ConfigChangeListener.java
26  * $Id: MonitoringConfigChangeListener.java,v 1.3 2005/12/25 03:43:40 tcfujii Exp $
27  * $Date: 2005/12/25 03:43:40 $
28  * $Revision: 1.3 $
29  */

30
31
32 package com.sun.enterprise.admin.monitor.registry.spi.reconfig;
33 import com.sun.enterprise.admin.event.MonitoringLevelChangeEvent;
34 import com.sun.enterprise.admin.event.MonitoringLevelChangeEventListener;
35 import com.sun.enterprise.admin.event.AdminEventListenerException;
36
37 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel;
38 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType;
39 /** Provides for the listener that listens for changes done by administrative interface and
40  * notifies them dynamically to core systems.
41  * This is the bridge between the notification subsystem and monitoring subsystem.
42  * @author <a HREF="mailto:Kedar.Mhaswade@sun.com">Kedar Mhaswade</a>
43  * @since S1AS8.0
44  * @version $Revision: 1.3 $
45  */

46 public class MonitoringConfigChangeListener implements MonitoringLevelChangeEventListener {
47     
48     private final ChangeHandler delegate;
49     public MonitoringConfigChangeListener(ChangeHandler delegate) {
50         this.delegate = delegate;
51     }
52     public synchronized void monitoringLevelChanged(
53             MonitoringLevelChangeEvent event)
54             throws AdminEventListenerException {
55
56         //This will be done soon once I start receiving these events. These events have all info.
57
//delegate.handleChange (type, from, to);
58
final String JavaDoc component = event.getComponentName();
59         final String JavaDoc from = event.getOldMonitoringLevel();
60         final String JavaDoc to = event.getNewMonitoringLevel();
61         
62         // sets the event to thread context
63
MonitoringThreadContext.setEventToThreadLocal(event);
64
65         handleAllAffectedTypes(component, from, to);
66
67         // removes the event from thread context
68
MonitoringThreadContext.removeEventFromThreadLocal();
69     }
70     
71     private void handleAllAffectedTypes(String JavaDoc component, String JavaDoc from, String JavaDoc to) {
72         final MonitoredObjectType[] types = name2Types(component);
73         final MonitoringLevel oLevel = MonitoringLevel.instance(from);
74         final MonitoringLevel nLevel = MonitoringLevel.instance(to);
75         for (int i = 0 ; i < types.length ; i++) {
76             delegate.handleChange(types[i], oLevel, nLevel);
77         }
78     }
79     
80     private MonitoredObjectType[] name2Types(String JavaDoc component) {
81         MonitoredObjectType[] types = new MonitoredObjectType[0]; //empty array
82
if (EJB_CONTAINER.equals(component)) {
83             types = MonitoredObjectType.EJB_TYPES;
84         }
85         else if (WEB_CONTAINER.equals(component)) {
86             types = new MonitoredObjectType[1];
87             types[0] = MonitoredObjectType.SERVLET;
88         }
89         else if (THREAD_POOL.equals(component)) {
90             types = new MonitoredObjectType[1];
91             types[0] = MonitoredObjectType.THREAD_POOL;
92         }
93         else if (ORB.equals(component)) {
94             types = new MonitoredObjectType[1];
95             types[0] = MonitoredObjectType.ORB;
96         }
97         else if (HTTP_SERVICE.equals(component)) {
98             types = MonitoredObjectType.HTTP_SERVICE_TYPES;
99         }
100         else if (TRANSACTION_SERVICE.equals(component)) {
101             types = new MonitoredObjectType[1];
102             types[0] = MonitoredObjectType.TRANSACTION_SERVICE;
103         }
104         else if (JDBC_CONN_POOL.equals(component)) {
105             types = new MonitoredObjectType[1];
106             types[0] = MonitoredObjectType.JDBC_CONN_POOL;
107         }
108         else if (CONNECTOR_SERVICE.equals(component)) {
109             types = new MonitoredObjectType[1];
110             types[0] = MonitoredObjectType.CONNECTOR_SERVICE;
111         }
112         else if (JVM.equals(component)) {
113             types = new MonitoredObjectType[1];
114             types[0] = MonitoredObjectType.JVM;
115         } else if (WEBSERVICE_ENDPOINT.equals(component)) {
116             types = new MonitoredObjectType[1];
117             types[0] = MonitoredObjectType.WEBSERVICE_ENDPOINT;
118         }
119         /**
120          * connector-service level will be modified whenever
121          * the connector-connection-pool or jms-service is
122          * modified, in addition to changes made directly to the
123          * connector-service. It therefore makes sense to handle the
124          * event only once i.e for connector-service and let the
125          * others go unhandled.
126         else if (CONNECTOR_CONN_POOL.equals(component)) {
127             types = new MonitoredObjectType[1];
128             types[0] = MonitoredObjectType.CONNECTOR_SERVICE;
129         }
130         else if (JMS_SERVICE.equals(component)) {
131             types = new MonitoredObjectType[1];
132             types[0] = MonitoredObjectType.CONNECTOR_SERVICE;
133         }
134          */

135         return ( types );
136     }
137     
138     /**
139      * All fields actually refer to their counterparts in domain.xml. Actually
140      * the ServerTags class is to be reused, but it is auto-generated and
141      * there are some optimizations made to it, hence this repetition.
142      */

143     public static final String JavaDoc EJB_CONTAINER = "ejb-container";
144     public static final String JavaDoc WEB_CONTAINER = "web-container";
145     public static final String JavaDoc THREAD_POOL = "thread-pool";
146     public static final String JavaDoc ORB = "orb";
147     public static final String JavaDoc TRANSACTION_SERVICE = "transaction-service";
148     public static final String JavaDoc HTTP_SERVICE = "http-service";
149     public static final String JavaDoc JDBC_CONN_POOL = "jdbc-connection-pool";
150     public static final String JavaDoc CONNECTOR_CONN_POOL = "connector-connection-pool";
151     public static final String JavaDoc CONNECTOR_SERVICE = "connector-service";
152     public static final String JavaDoc JMS_SERVICE = "jms-service";
153     public static final String JavaDoc JNDI = "jndi";
154     public static final String JavaDoc JVM = "jvm";
155     public static final String JavaDoc WEBSERVICE_ENDPOINT = "webservice_endpoint";
156
157 }
158
Popular Tags