001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.management.j2ee;
023:
024: import org.jboss.logging.Logger;
025: import org.jboss.management.j2ee.statistics.EntityBeanStatsImpl;
026: import org.jboss.management.j2ee.statistics.RangeStatisticImpl;
027:
028: import javax.management.MalformedObjectNameException;
029: import javax.management.ObjectName;
030: import javax.management.j2ee.statistics.Stats;
031:
032: /**
033: * The JBoss JSR-77.3.12 implementation of the StatelessSessionBean model
034: *
035: * @author <a href="mailto:andreas@jboss.org">Andreas Schaefer</a>
036: * @author <a href="mailto:thomas.diesler@jboss.org">Thomas Diesler</a>
037: * @version $Revision: 57197 $
038: */
039: public class EntityBean extends EJB implements EntityBeanMBean {
040:
041: // Attributes ----------------------------------------------------
042:
043: private EntityBeanStatsImpl stats;
044:
045: // Static --------------------------------------------------------
046:
047: private static Logger log = Logger.getLogger(EntityBean.class);
048:
049: // Constructors --------------------------------------------------
050:
051: public EntityBean(String name, ObjectName ejbModuleName,
052: ObjectName ejbContainerName)
053: throws MalformedObjectNameException, InvalidParentException {
054: this (name, ejbModuleName, ejbContainerName, null, null);
055: }
056:
057: /**
058: * Create an EntityBean model
059: *
060: * @param name the ejb name, currently the JNDI name
061: * @param ejbModuleName the JSR-77 EJBModule name for this bean
062: * @param ejbContainerName the JMX name of the JBoss ejb container MBean
063: * @param jndiName the jndi name of the remote home binding is one exists,
064: * null if there is no remote home.
065: * @param localJndiName the jndi name of the local home binding is one exists,
066: * null if there is no local home.
067: * @throws MalformedObjectNameException
068: * @throws InvalidParentException
069: */
070: public EntityBean(String name, ObjectName ejbModuleName,
071: ObjectName ejbContainerName, String jndiName,
072: String localJndiName) throws MalformedObjectNameException,
073: InvalidParentException {
074: super (J2EETypeConstants.EntityBean, name, ejbModuleName,
075: ejbContainerName, jndiName, localJndiName);
076: stats = new EntityBeanStatsImpl();
077: }
078:
079: // Begin StatisticsProvider interface methods
080: public Stats getstats() {
081: try {
082: updateCommonStats(stats);
083:
084: ObjectName poolName = getContainerPoolName();
085: RangeStatisticImpl pooledCount = (RangeStatisticImpl) stats
086: .getReadyCount();
087: Integer poolSize = (Integer) server.getAttribute(poolName,
088: "CurrentSize");
089: pooledCount.set(poolSize.longValue());
090:
091: ObjectName cacheName = getContainerCacheName();
092: RangeStatisticImpl readyCount = (RangeStatisticImpl) stats
093: .getReadyCount();
094: Long count = (Long) server.getAttribute(cacheName,
095: "CacheSize");
096: readyCount.set(count.longValue());
097: } catch (Exception e) {
098: log.debug("Failed to retrieve stats", e);
099: }
100: return stats;
101: }
102:
103: public void resetStats() {
104: stats.reset();
105: }
106:
107: // End StatisticsProvider interface methods
108:
109: // Object overrides ---------------------------------------------------
110:
111: public String toString() {
112: return "EntityBean { " + super .toString() + " } []";
113: }
114: }
|