1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 import org.jboss.management.j2ee.statistics.ServletStatsImpl; 26 import org.jboss.management.j2ee.statistics.TimeStatisticImpl; 27 28 import javax.management.MBeanServer ; 29 import javax.management.MalformedObjectNameException ; 30 import javax.management.ObjectName ; 31 import javax.management.j2ee.statistics.Stats ; 32 import java.util.Hashtable ; 33 34 42 public class Servlet extends J2EEManagedObject 43 implements ServletMBean 44 { 45 46 private static Logger log = Logger.getLogger(Servlet.class); 48 49 private ObjectName servletServiceName; 50 private ServletStatsImpl stats; 51 52 62 public static ObjectName create(MBeanServer mbeanServer, ObjectName webModuleName, 63 ObjectName webContainerName, ObjectName servletServiceName) 64 { 65 try 66 { 67 Servlet servlet = new Servlet(servletServiceName, webModuleName, webContainerName); 68 ObjectName jsr77Name = servlet.getObjectName(); 69 mbeanServer.registerMBean(servlet, jsr77Name); 70 log.debug("Created JSR-77 Servlet: " + jsr77Name); 71 return jsr77Name; 72 } 73 catch (Exception e) 74 { 75 log.debug("Could not create JSR-77 Servlet: " + servletServiceName, e); 76 return null; 77 } 78 } 79 80 public static void destroy(MBeanServer mbeanServer, ObjectName jsr77Name) 81 { 82 try 83 { 84 mbeanServer.unregisterMBean(jsr77Name); 85 log.debug("Destroyed JSR-77 Servlet: " + jsr77Name); 86 } 87 catch (javax.management.InstanceNotFoundException ignore) 88 { 89 } 90 catch (Exception e) 91 { 92 log.debug("Could not destroy JSR-77 Servlet: " + jsr77Name, e); 93 } 94 } 95 96 98 102 public Servlet(ObjectName servletServiceName, ObjectName webModuleName, 103 ObjectName webContainerName) 104 throws MalformedObjectNameException , 105 InvalidParentException 106 { 107 super(J2EETypeConstants.Servlet, servletServiceName.getKeyProperty("name"), webModuleName); 108 this.servletServiceName = servletServiceName; 109 this.stats = new ServletStatsImpl(); 110 } 111 112 118 public Stats getstats() 119 { 120 try 121 { 122 TimeStatisticImpl serviceTime = (TimeStatisticImpl) stats.getServiceTime(); 123 Integer count = (Integer ) server.getAttribute(servletServiceName, "requestCount"); 124 Long totalTime = (Long ) server.getAttribute(servletServiceName, "processingTime"); 125 Long minTime = (Long ) server.getAttribute(servletServiceName, "minTime"); 126 Long maxTime = (Long ) server.getAttribute(servletServiceName, "maxTime"); 127 serviceTime.set(count.longValue(), minTime.longValue(), 128 maxTime.longValue(), totalTime.longValue()); 129 } 130 catch (Exception e) 131 { 132 log.debug("Failed to retrieve stats", e); 133 } 134 return stats; 135 } 136 137 public void resetStats() 138 { 139 stats.reset(); 140 } 141 143 public String toString() 144 { 145 return "Servlet { " + super.toString() + " } []"; 146 } 147 148 150 152 155 protected Hashtable getParentKeys(ObjectName pParent) 156 { 157 Hashtable lReturn = new Hashtable (); 158 Hashtable lProperties = pParent.getKeyPropertyList(); 159 lReturn.put(J2EETypeConstants.WebModule, lProperties.get("name")); 160 lReturn.put(J2EETypeConstants.J2EEApplication, lProperties.get(J2EETypeConstants.J2EEApplication)); 163 lReturn.put(J2EETypeConstants.J2EEServer, lProperties.get(J2EETypeConstants.J2EEServer)); 164 165 return lReturn; 166 } 167 168 } 169 | Popular Tags |