KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > transaction > JTSConfigChangeEventListener


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

24 package com.sun.enterprise.transaction;
25
26 import com.sun.enterprise.admin.event.*;
27 import com.sun.enterprise.admin.event.tx.JTSEvent;
28 import com.sun.enterprise.admin.event.tx.JTSEventListener;
29 import java.util.*;
30 import com.sun.enterprise.config.*;
31 import com.sun.enterprise.Switch;
32 //import com.sun.enterprise.config.serverbeans.*;
33
import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
34 import com.sun.enterprise.config.serverbeans.ServerTags;
35 import com.sun.enterprise.distributedtx.J2EETransactionManagerImpl;
36 import com.sun.jts.CosTransactions.Configuration;
37 import java.util.logging.Logger JavaDoc;
38 import java.util.logging.Level JavaDoc;
39 import com.sun.logging.LogDomains;
40
41 import com.sun.enterprise.util.i18n.StringManager;
42
43 /*
44  * Listener for JTS dynamic configuration.
45  */

46
47 public class JTSConfigChangeEventListener implements JTSEventListener
48 {
49     // Sting Manager for Localization
50
private static StringManager sm = StringManager.getManager(JTSConfigChangeEventListener.class);
51
52     // Logger to log transaction messages
53
static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.JTA_LOGGER);
54     public String JavaDoc xPath = ServerXPathHelper.XPATH_TRANSACTION_SERVICE;
55
56     private static ConfigChangeCategory category = new ConfigChangeCategory(
57             "jts", ServerXPathHelper.REGEX_XPATH_CONFIG
58                     + ServerXPathHelper.XPATH_SEPARATOR
59                     + ServerXPathHelper.REGEX_ONE_PLUS
60                     + ServerTags.TRANSACTION_SERVICE + ".*");
61     public static ConfigChangeCategory getCategory() {
62         return category;
63     }
64
65     public void handleCreate(JTSEvent event) throws AdminEventListenerException {
66         throw new AdminEventListenerException("handleCreate is not valid for JTSEvent");
67     }
68
69     public void handleDelete(JTSEvent event) throws AdminEventListenerException {
70         throw new AdminEventListenerException("handleDelete is not valid for JTSEvent");
71     }
72
73     public void handleUpdate(JTSEvent event) throws AdminEventListenerException {
74         //Bug Id: 4666390 Handle no event in event list case
75
if(event==null){
76             //do nothing
77
return;
78         }
79         ArrayList configChangeList = event.getConfigChangeList();
80         if(configChangeList==null){
81             //do nothing
82
return;
83         }
84         //Bug Id: 4666390 End
85

86         ConfigUpdate configUpdate = null;
87         boolean match = false;
88         for (int i = 0; i < configChangeList.size(); i++) {
89             configUpdate = (ConfigUpdate) configChangeList.get(i);
90              if (configUpdate.getXPath() != null &&
91                 configUpdate.getXPath().endsWith(ServerTags.TRANSACTION_SERVICE)) {
92                 if (xPath.equals(configUpdate.getXPath())) {
93                     match = true;
94                     break;
95                 }
96              }
97         }
98         if (match) { // TransactionService has been changed
99
Set attributeSet = configUpdate.getAttributeSet();
100             String JavaDoc next = null;
101             for (Iterator iter = attributeSet.iterator(); iter.hasNext();) {
102                 next = (String JavaDoc) iter.next();
103                 if (next.equals(ServerTags.TIMEOUT_IN_SECONDS)) {
104                     _logger.log(Level.FINE," Transaction Timeout interval event occurred");
105                     String JavaDoc oldTimeout = configUpdate.getOldValue(ServerTags.TIMEOUT_IN_SECONDS);
106                     String JavaDoc newTimeout = configUpdate.getNewValue(ServerTags.TIMEOUT_IN_SECONDS);
107                     if (oldTimeout.equals(newTimeout)) {
108                     }
109                     else {
110                         try {
111                             Switch.getSwitch().getTransactionManager().setDefaultTransactionTimeout(
112                                                                         Integer.parseInt(newTimeout,10));
113                         } catch (Exception JavaDoc ex) {
114                             _logger.log(Level.WARNING,"transaction.reconfig_txn_timeout_failed",ex);
115                         }
116                     } // timeout-in-seconds
117
}else if (next.equals(ServerTags.KEYPOINT_INTERVAL)) {
118                     _logger.log(Level.FINE,"Keypoint interval event occurred");
119                     String JavaDoc oldKeyPoint = configUpdate.getOldValue(ServerTags.KEYPOINT_INTERVAL);
120                     String JavaDoc newKeyPoint = configUpdate.getNewValue(ServerTags.KEYPOINT_INTERVAL);
121                     if (oldKeyPoint.equals(newKeyPoint)) {
122                     }
123                     else {
124                         Configuration.setKeypointTrigger(Integer.parseInt(newKeyPoint,10));
125                     }
126                 }else if (next.equals(ServerTags.RETRY_TIMEOUT_IN_SECONDS)) {
127                     String JavaDoc oldRetryTiemout = configUpdate.getOldValue(ServerTags.RETRY_TIMEOUT_IN_SECONDS);
128                     String JavaDoc newRetryTiemout = configUpdate.getNewValue(ServerTags.RETRY_TIMEOUT_IN_SECONDS);
129                     _logger.log(Level.FINE,"retry_timeout_in_seconds reconfig event occurred " + newRetryTiemout);
130                     if (oldRetryTiemout.equals(newRetryTiemout)) {
131                     }
132                     else {
133                         Configuration.setCommitRetryVar(newRetryTiemout);
134                     }
135                 }
136                 else {
137                     // Not handled dynamically. Restart is required.
138
AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED);
139                 }
140                 
141                 /*
142         //This feature is currently dropped as it's not implemented totally
143         else if (next.equals("commit-retries")) {
144                     String oldCommitRetries = configUpdate.getOldValue("commit-retries");
145                     String newCommitRetries = configUpdate.getNewValue("commit-retries");
146                     if (oldCommitRetries.equals(newCommitRetries)) {
147                     }
148                     else {
149                         Configuration.setCommitRetryVar(newCommitRetries);
150                     }
151                 } // commit-retries
152                 */

153
154             }
155         }
156
157     }
158 }
159
Popular Tags