1 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 ; 38 import javax.management.MBeanServer ; 39 import javax.management.MBeanServerFactory ; 40 import javax.management.MBeanException ; 42 import java.util.ArrayList ; 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 46 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 public void freeze(String serverName) throws Exception { 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 e) { 71 throw new MBeanException (e, _strMgr.getString("admin.mbeans.server_not_running", new Object [] {serverName})); 72 } 73 } 74 75 public void unfreeze(String serverName) throws Exception { 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 e) { 81 throw new MBeanException (e, _strMgr.getString("admin.mbeans.server_not_running", new Object [] {serverName})); 82 } 83 } 84 public void rollback(String [] txids, String serverName) 85 throws Exception { 86 finest("rollback called for target: " + serverName); 87 validateServerName(serverName); 88 try { 89 getMBS().invoke(getTransactionServiceObjectName(serverName), 90 "rollback", 91 new Object [] {txids}, 92 new String [] {"[Ljava.lang.String;"}); 93 } catch(javax.management.InstanceNotFoundException e) { 94 throw new MBeanException (e, _strMgr.getString("admin.mbeans.server_not_running", new Object [] {serverName})); 95 } 96 } 97 98 99 101 private MBeanServer getMBS() { 102 return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer(); 103 } 104 105 private ObjectName getTransactionServiceObjectName(String server) 106 throws Exception { 107 return new ObjectName ( 108 getDomainName() + 109 ":type=TransactionService,J2EEServer=" 110 + server 111 + ",category=runtime"); 112 } 113 114 private void validateServerName(String server) throws Exception { 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 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 s) { 135 _logger.finest("TransactionServiceManagerMBean: " + s); 136 } 137 138 140 private static final StringManager _strMgr = 141 StringManager.getManager(TransactionServiceManagerMBean.class); 142 public static final Logger _logger = Logger.getLogger(AdminConstants.kLoggerName); 143 144 146 } 147 | Popular Tags |