1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.management.j2ee.statistics.BoundedRangeStatisticImpl; 26 import org.jboss.management.j2ee.statistics.CountStatisticImpl; 27 import org.jboss.management.j2ee.statistics.JCAConnectionPoolStatsImpl; 28 import org.jboss.management.j2ee.statistics.RangeStatisticImpl; 29 import org.jboss.management.j2ee.statistics.TimeStatisticImpl; 30 31 import javax.management.MBeanServer ; 32 import javax.management.MalformedObjectNameException ; 33 import javax.management.ObjectName ; 34 import java.util.Hashtable ; 35 36 43 public class JCAConnectionFactory extends J2EEManagedObject 44 implements JCAConnectionFactoryMBean 45 { 46 private static Logger log = Logger.getLogger(JCAConnectionFactory.class); 48 49 51 54 private ObjectName cmServiceName; 55 56 59 private ObjectName mcfServiceName; 60 private String jsr77MCFName; 61 private JCAConnectionPoolStatsImpl poolStats; 62 63 65 public static ObjectName create(MBeanServer mbeanServer, String resName, 66 ObjectName jsr77ParentName, ObjectName ccmServiceNameName, 67 ObjectName mcfServiceName) 68 { 69 ObjectName jsr77Name = null; 70 try 71 { 72 JCAConnectionFactory jcaFactory = new JCAConnectionFactory(resName, 73 jsr77ParentName, ccmServiceNameName, mcfServiceName); 74 jsr77Name = jcaFactory.getObjectName(); 75 mbeanServer.registerMBean(jcaFactory, jsr77Name); 76 log.debug("Created JSR-77 JCAConnectionFactory: " + resName); 77 ObjectName jsr77MCFName = JCAManagedConnectionFactory.create(mbeanServer, 78 resName, jsr77Name); 79 jcaFactory.setmanagedConnectionFactory(jsr77MCFName.getCanonicalName()); 80 } 81 catch (Exception e) 82 { 83 log.debug("Could not create JSR-77 JCAConnectionFactory: " + resName, e); 84 } 85 return jsr77Name; 86 } 87 88 public static void destroy(MBeanServer mbeanServer, String resName) 89 { 90 try 91 { 92 String connName = J2EEDomain.getDomainName() + ":" 94 + J2EEManagedObject.TYPE + "=" + J2EETypeConstants.JCAConnectionFactory 95 + ",name=" + resName + ",*"; 96 J2EEManagedObject.removeObject(mbeanServer, connName); 97 } 98 catch (javax.management.InstanceNotFoundException infe) 99 { 100 } 101 catch (Exception e) 102 { 103 log.debug("Could not destroy JSR-77 JCAConnectionFactory: " + resName, e); 104 } 105 } 106 107 109 110 public JCAConnectionFactory(String resName, ObjectName jsr77ParentName, 111 ObjectName ccmServiceNameName, ObjectName mcfServiceName) 112 throws MalformedObjectNameException , InvalidParentException 113 { 114 super(J2EETypeConstants.JCAConnectionFactory, resName, jsr77ParentName); 115 this.cmServiceName = ccmServiceNameName; 116 this.mcfServiceName = mcfServiceName; 117 } 118 119 121 123 126 public String getmanagedConnectionFactory() 127 { 128 return jsr77MCFName; 129 } 130 131 void setmanagedConnectionFactory(String jsr77MCFName) 132 { 133 this.jsr77MCFName = jsr77MCFName; 134 } 135 136 139 public JCAConnectionPoolStatsImpl getPoolStats(ObjectName poolServiceName) 140 { 141 TimeStatisticImpl waitTime = null; 142 TimeStatisticImpl useTime = null; 143 CountStatisticImpl closeCount = null; 144 CountStatisticImpl createCount = null; 145 BoundedRangeStatisticImpl freePoolSize = null; 146 BoundedRangeStatisticImpl poolSize = null; 147 RangeStatisticImpl waitingThreadCount = null; 148 try 149 { 150 if (poolStats == null) 151 { 152 Integer max = (Integer ) server.getAttribute(poolServiceName, "MaxSize"); 153 freePoolSize = new BoundedRangeStatisticImpl("FreePoolSize", "1", 154 "The free connection count", 0, max.longValue()); 155 poolSize = new BoundedRangeStatisticImpl("PoolSize", "1", 156 "The connection count", 0, max.longValue()); 157 poolStats = new JCAConnectionPoolStatsImpl(getobjectName(), jsr77MCFName, 158 waitTime, useTime, closeCount, createCount, freePoolSize, poolSize, 159 waitingThreadCount); 160 } 161 createCount = (CountStatisticImpl) poolStats.getCreateCount(); 162 closeCount = (CountStatisticImpl) poolStats.getCloseCount(); 163 freePoolSize = (BoundedRangeStatisticImpl) poolStats.getFreePoolSize(); 164 poolSize = (BoundedRangeStatisticImpl) poolStats.getPoolSize(); 165 166 Integer isize = (Integer ) server.getAttribute(poolServiceName, "ConnectionCreatedCount"); 168 createCount.set(isize.longValue()); 169 isize = (Integer ) server.getAttribute(poolServiceName, "ConnectionDestroyedCount"); 170 closeCount.set(isize.longValue()); 171 isize = (Integer ) server.getAttribute(poolServiceName, "ConnectionCount"); 172 poolSize.set(isize.longValue()); 173 Long lsize = (Long ) server.getAttribute(poolServiceName, "AvailableConnectionCount"); 174 freePoolSize.set(lsize.longValue()); 175 } 176 catch (Exception e) 177 { 178 log.debug("Failed to update JCAConnectionPoolStats", e); 179 } 180 181 return poolStats; 182 } 183 184 186 public String toString() 187 { 188 return "JCAConnectionFactory { " + super.toString() + " } [ " + 189 " ]"; 190 } 191 192 194 196 199 protected Hashtable getParentKeys(ObjectName parentName) 200 { 201 Hashtable keys = new Hashtable (); 202 Hashtable nameProps = parentName.getKeyPropertyList(); 203 String factoryName = (String ) nameProps.get("name"); 204 String serverName = (String ) nameProps.get(J2EETypeConstants.J2EEServer); 205 keys.put(J2EETypeConstants.J2EEServer, serverName); 206 keys.put(J2EETypeConstants.JCAResource, factoryName); 207 return keys; 208 } 209 210 } 211 | Popular Tags |