KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > TransactionServiceManagerMBean


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.admin.mbeans;
25
26 import com.sun.enterprise.config.ConfigContext;
27 import com.sun.enterprise.admin.config.BaseConfigMBean;
28 import com.sun.enterprise.admin.config.MBeanConfigException;
29 import com.sun.enterprise.admin.common.constant.AdminConstants;
30 import com.sun.enterprise.admin.target.Target;
31 import com.sun.enterprise.admin.target.TargetType;
32 import com.sun.enterprise.admin.target.TargetBuilder;
33 import com.sun.enterprise.util.i18n.StringManager;
34 import com.sun.enterprise.admin.AdminContext;
35 import com.sun.enterprise.admin.server.core.AdminService;
36  
37 import javax.management.ObjectName JavaDoc;
38 import javax.management.MBeanServer JavaDoc;
39 import javax.management.MBeanServerFactory JavaDoc;
40 //import javax.management.InstanceNotFoundException;
41
import javax.management.MBeanException JavaDoc;
42 import java.util.ArrayList JavaDoc;
43 import java.util.logging.Level JavaDoc;
44 import java.util.logging.Logger JavaDoc;
45
46 /**
47  * object name for this mbean:
48  * <domainName>:type=transaction-service-manager,category=config
49  * Based on the target calls the appropriate mbean
50  *
51  * @author sridatta
52  *
53  */

54 public class TransactionServiceManagerMBean extends BaseConfigMBean
55 {
56     private static final TargetType[] VALID_TARGET_TYPES = new TargetType[] {
57         TargetType.UNCLUSTERED_SERVER, TargetType.DAS, TargetType.SERVER};
58         
59     public TransactionServiceManagerMBean()
60     {
61         super();
62     }
63     
64     ///////////////////////////////////////////////////////////////////////////
65
public void freeze(String JavaDoc serverName) throws Exception JavaDoc {
66           finest("freeze called for target: " + serverName);
67           validateServerName(serverName);
68           try {
69                   getMBS().invoke(getTransactionServiceObjectName(serverName), "freeze", null, null);
70           } catch(javax.management.InstanceNotFoundException JavaDoc e) {
71                  throw new MBeanException JavaDoc(e, _strMgr.getString("admin.mbeans.server_not_running", new Object JavaDoc[] {serverName}));
72           }
73       }
74       
75       public void unfreeze(String JavaDoc serverName) throws Exception JavaDoc {
76           finest("unfreeze called for target: " + serverName);
77           validateServerName(serverName);
78           try {
79               getMBS().invoke(getTransactionServiceObjectName(serverName), "unfreeze", null, null);
80           } catch(javax.management.InstanceNotFoundException JavaDoc e) {
81                  throw new MBeanException JavaDoc(e, _strMgr.getString("admin.mbeans.server_not_running", new Object JavaDoc[] {serverName}));
82           }
83       }
84       public void rollback(String JavaDoc[] txids, String JavaDoc serverName)
85                             throws Exception JavaDoc {
86           finest("rollback called for target: " + serverName);
87           validateServerName(serverName);
88           try {
89               getMBS().invoke(getTransactionServiceObjectName(serverName),
90                         "rollback",
91                         new Object JavaDoc[] {txids},
92                         new String JavaDoc[] {"[Ljava.lang.String;"});
93           } catch(javax.management.InstanceNotFoundException JavaDoc e) {
94                  throw new MBeanException JavaDoc(e, _strMgr.getString("admin.mbeans.server_not_running", new Object JavaDoc[] {serverName}));
95           }
96       }
97       
98       
99       ///////////////////////////////////////////////////////////////////////////
100

101       private MBeanServer JavaDoc getMBS() {
102          return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer();
103       }
104       
105       private ObjectName JavaDoc getTransactionServiceObjectName(String JavaDoc server)
106                                                 throws Exception JavaDoc {
107           return new ObjectName JavaDoc(
108                 getDomainName() +
109                 ":type=TransactionService,J2EEServer="
110                 + server
111                 + ",category=runtime");
112       }
113      
114    private void validateServerName(String JavaDoc server) throws Exception JavaDoc {
115        finest("validating the target " + server);
116          final Target target = TargetBuilder.INSTANCE.createTarget(
117                 VALID_TARGET_TYPES,
118                 server, getConfigContext());
119          finest("Target is valid: " + server);
120    }
121    
122    //We must subclass this method, because the base case seems to return a null config context if
123
//the mbean does not have a corresponding xpath (or something). The properties MBean seems
124
//to have this problem.
125
protected ConfigContext getConfigContext()
126     {
127         ConfigContext result = super.getConfigContext();
128         if (result == null) {
129             result = AdminService.getAdminService().getAdminContext().getAdminConfigContext();
130         }
131         return result;
132     }
133
134    private void finest(String JavaDoc s) {
135        _logger.finest("TransactionServiceManagerMBean: " + s);
136    }
137      
138     ///////////////////////////////////////////////////////////////////////////
139

140     private static final StringManager _strMgr =
141                StringManager.getManager(TransactionServiceManagerMBean.class);
142        public static final Logger JavaDoc _logger = Logger.getLogger(AdminConstants.kLoggerName);
143
144     ///////////////////////////////////////////////////////////////////////////
145

146 }
147
Popular Tags