KickJava   Java API By Example, From Geeks To Geeks.

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


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 /* TransactionServiceChangeHandler.java
25  * $Id: TransactionServiceChangeHandler.java,v 1.3 2005/12/25 03:43:42 tcfujii Exp $
26  * $Revision: 1.3 $
27  * $Date: 2005/12/25 03:43:42 $
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.Map JavaDoc;
43 import java.util.logging.Logger JavaDoc;
44 import com.sun.enterprise.admin.monitor.registry.MonitoringLevel;
45 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType;
46 import com.sun.enterprise.admin.monitor.registry.StatsHolder;
47 import com.sun.enterprise.admin.monitor.registry.MonitoringLevelListener;
48
49 import com.sun.enterprise.admin.monitor.registry.spi.ValueListMap;
50 import com.sun.enterprise.admin.monitor.registry.spi.MonitoringRegistrationHelper;
51 import com.sun.enterprise.admin.common.constant.AdminConstants;
52
53 /**
54  * Provides for dynamic reconfiguration of transaction subsystem.
55  * This class decides the actions to take when there are
56  * changes to the monitoring level through administrative interfaces.
57  * @author <a HREF="mailto:Kedar.Mhaswade@sun.com">Kedar Mhaswade</a>
58  * @since S1AS8.0
59  * @version $Revision: 1.3 $
60  */

61 class TransactionServiceChangeHandler implements ChangeHandler {
62     
63     private final ChangeHandler successor;
64     private final ValueListMap listeners;
65     
66     private static final Logger JavaDoc logger = Logger.getLogger(AdminConstants.kLoggerName);
67     
68     TransactionServiceChangeHandler(ChangeHandler successor, ValueListMap listeners) {
69         this.successor = successor;
70         this.listeners = listeners;
71     }
72     
73     public void handleChange(MonitoredObjectType t, MonitoringLevel from, MonitoringLevel to) {
74         if (isTransactionServiceType(t)) {
75             handleChange(from, to);
76         }
77         else {
78             successor.handleChange(t, from, to);
79         }
80     }
81     
82     private boolean isTransactionServiceType(MonitoredObjectType t) {
83         return ( t == MonitoredObjectType.TRANSACTION_SERVICE );
84     }
85     
86     private void handleChange(MonitoringLevel from, MonitoringLevel to) {
87         if (off2Low(from, to) || off2High(from, to)) {
88             notifyListeners(from, to);
89             registerMBeans();
90         }
91         if (low2Off(from, to) || high2Off(from, to)) {
92             unregisterMBeans();
93             notifyListeners(from, to);
94         }
95         if (low2High(from, to) || high2Low(from, to)) {
96             //currently do nothing.
97
}
98     }
99     
100     private void notifyListeners(MonitoringLevel from, MonitoringLevel to) {
101         logger.finer("DynamicReconfigurator: Now notifying the listeners for jta stats --- from = " + from.toString() + " to = " + to.toString());
102         final Map JavaDoc l = (Map JavaDoc)listeners.get(MonitoredObjectType.TRANSACTION_SERVICE);
103         if (l == null)
104             return;
105         final Iterator JavaDoc it = l.keySet().iterator();
106         while (it.hasNext()) {
107             final MonitoringLevelListener ml = (MonitoringLevelListener)it.next();
108             ml.changeLevel(from, to, MonitoredObjectType.TRANSACTION_SERVICE);
109         }
110     }
111     
112     private void registerMBeans() {
113         final MonitoringRegistrationHelper registryImpl =
114             (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();
115         //note that the above refers to the actual implementation rather than interface.
116

117         //registers MBeans pertaining to transaction service
118
final Iterator JavaDoc iter = registryImpl.getTransactionServiceNodes().iterator();
119         while (iter.hasNext()) {
120             final StatsHolder c = (StatsHolder) iter.next();
121             c.registerMBean();
122             logger.finer("DynamicReconfigurator: Now Registering MBean for --- " + c.getName());
123         }
124     }
125     
126     private void unregisterMBeans() {
127         final MonitoringRegistrationHelper registryImpl =
128             (MonitoringRegistrationHelper) MonitoringRegistrationHelper.getInstance();
129         //note that the above refers to the actual implementation rather than interface.
130

131         final Iterator JavaDoc iter = registryImpl.getTransactionServiceNodes().iterator();
132         while (iter.hasNext()) {
133             final StatsHolder c = (StatsHolder) iter.next();
134             c.unregisterMBean();
135             logger.finer("DynamicReconfigurator: Now UnRegistering MBean for --- " + c.getName());
136         }
137     }
138
139     private boolean off2Low(MonitoringLevel from, MonitoringLevel to) {
140         return ( from == MonitoringLevel.OFF && to == MonitoringLevel.LOW );
141     }
142     private boolean off2High(MonitoringLevel from, MonitoringLevel to) {
143         return ( from == MonitoringLevel.OFF && to == MonitoringLevel.HIGH );
144     }
145     private boolean low2Off(MonitoringLevel from, MonitoringLevel to) {
146         return ( from == MonitoringLevel.LOW && to == MonitoringLevel.OFF);
147     }
148     private boolean high2Off(MonitoringLevel from, MonitoringLevel to) {
149         return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.OFF );
150     }
151     private boolean low2High(MonitoringLevel from, MonitoringLevel to) {
152         return ( from == MonitoringLevel.LOW && to == MonitoringLevel.HIGH);
153     }
154     private boolean high2Low(MonitoringLevel from, MonitoringLevel to) {
155         return ( from == MonitoringLevel.HIGH && to == MonitoringLevel.LOW );
156     }
157 }
158
Popular Tags