KickJava   Java API By Example, From Geeks To Geeks.

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


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 /* ThreadPoolChangeHandler.java
25  * $Id: ThreadPoolChangeHandler.java,v 1.3 2005/12/25 03:43:41 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:43:41 $
28  * Indentation Information:
29  * 0. Please (try to) preserve these settings.
30  * 1. Tabs are preferred over spaces.
31  * 2. In vi/vim -
32  * :set tabstop=4 :set shiftwidth=4 :set softtabstop=4
33  * 3. In S1 Studio -
34  * 1. Tools->Options->Editor Settings->Java Editor->Tab Size = 4
35  * 2. Tools->Options->Indentation Engines->Java Indentation Engine->Expand Tabs to Spaces = False.
36  * 3. Tools->Options->Indentation Engines->Java Indentation Engine->Number of Spaces per Tab = 4.
37  */

38
39 package com.sun.enterprise.admin.monitor.registry.spi.reconfig;
40
41 import java.util.Iterator JavaDoc;
42 import java.util.logging.Logger JavaDoc;
43 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel;
44 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType;
45 import com.sun.enterprise.admin.monitor.registry.StatsHolder;
46
47 import com.sun.enterprise.admin.monitor.registry.spi.ValueListMap;
48 import com.sun.enterprise.admin.monitor.registry.spi.MonitoringRegistrationHelper;
49 import com.sun.enterprise.admin.common.constant.AdminConstants;
50
51 /**
52  * Provides for dynamic reconfiguration of all the Thread Pool.
53  * This class decides the actions to take when there are
54  * changes to the monitoring level through administrative interfaces.
55  * @author <a HREF="mailto:Kedar.Mhaswade@sun.com">Kedar Mhaswade</a>
56  * @since S1AS8.0
57  * @version $Revision: 1.3 $
58  */

59 class ThreadPoolChangeHandler implements ChangeHandler {
60     
61     private final ChangeHandler successor;
62     private final ValueListMap listeners;
63     
64     private static final Logger JavaDoc logger = Logger.getLogger(AdminConstants.kLoggerName);
65     
66     ThreadPoolChangeHandler(ChangeHandler successor, ValueListMap listeners) {
67         this.successor = successor;
68         this.listeners = listeners;
69     }
70     
71     public void handleChange(MonitoredObjectType t, MonitoringLevel from, MonitoringLevel to) {
72         if (isThreadPoolType(t)) {
73             handleChange(from, to);
74         }
75         else {
76             successor.handleChange(t, from, to);
77         }
78     }
79     
80     private boolean isThreadPoolType(MonitoredObjectType t) {
81         return ( t == MonitoredObjectType.THREAD_POOL );
82     }
83     
84     private void handleChange(MonitoringLevel from, MonitoringLevel to) {
85         if (off2Low(from, to) || off2High(from, to)) {
86             notifyListeners(from, to);
87             registerMBeans();
88         }
89         if (low2Off(from, to) || high2Off(from, to)) {
90             unregisterMBeans();
91             notifyListeners(from, to);
92         }
93         if (low2High(from, to) || high2Low(from, to)) {
94             //currently do nothing.
95
}
96     }
97     
98     private void notifyListeners(MonitoringLevel from, MonitoringLevel to) {
99         logger.finer("DynamicReconfigurator: Now notifying the listeners for Thread Pool stats --- from = " + from.toString() + " to = " + to.toString());
100     }
101     
102     private void registerMBeans() {
103         final MonitoringRegistrationHelper registryImpl =
104             (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();
105         //note that the above refers to the actual implementation rather than interface.
106

107         //registers MBeans pertaining to thread pools
108
final Iterator JavaDoc iter = registryImpl.getThreadPoolNodes().iterator();
109         while (iter.hasNext()) {
110             final StatsHolder c = (StatsHolder) iter.next();
111             c.registerMBean();
112             logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName());
113         }
114     }
115     
116     private void unregisterMBeans() {
117         final MonitoringRegistrationHelper registryImpl =
118             (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();
119         //note that the above refers to the actual implementation rather than interface.
120

121         final Iterator JavaDoc iter = registryImpl.getThreadPoolNodes().iterator();
122         while (iter.hasNext()) {
123             final StatsHolder c = (StatsHolder) iter.next();
124             c.unregisterMBean();
125             logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName());
126         }
127     }
128
129     private boolean off2Low(MonitoringLevel from, MonitoringLevel to) {
130         return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW );
131     }
132     private boolean off2High(MonitoringLevel from, MonitoringLevel to) {
133         return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH );
134     }
135     private boolean low2Off(MonitoringLevel from, MonitoringLevel to) {
136         return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF);
137     }
138     private boolean high2Off(MonitoringLevel from, MonitoringLevel to) {
139         return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF );
140     }
141     private boolean low2High(MonitoringLevel from, MonitoringLevel to) {
142         return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH);
143     }
144     private boolean high2Low(MonitoringLevel from, MonitoringLevel to) {
145         return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW );
146     }
147 }
148
Popular Tags