KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > StatefulSessionBean


1 /*
2  * JBoss, Home of Professional Open Source
3  * Copyright 2005, JBoss Inc., and individual contributors as indicated
4  * by the @authors tag. See the copyright.txt in the distribution for a
5  * full listing of individual contributors.
6  *
7  * This is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as
9  * published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this software; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21  */

22 package org.jboss.management.j2ee;
23
24 import org.jboss.logging.Logger;
25 import org.jboss.management.j2ee.statistics.RangeStatisticImpl;
26 import org.jboss.management.j2ee.statistics.StatefulSessionBeanStatsImpl;
27
28 import javax.management.MalformedObjectNameException JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.j2ee.statistics.Stats JavaDoc;
31
32 /**
33  * The JBoss JSR-77.3.14 implementation of the StatefulSessionBean model
34  *
35  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>
36  * @author <a HREF="mailto:thomas.diesler@jboss.org">Thomas Diesler</a>
37  * @version $Revision: 40550 $
38  */

39 public class StatefulSessionBean extends SessionBean
40    implements StatefulSessionBeanMBean
41 {
42    private static Logger log = Logger.getLogger(StatefulSessionBean.class);
43
44    private StatefulSessionBeanStatsImpl stats;
45
46    // Constants -----------------------------------------------------
47

48    // Attributes ----------------------------------------------------
49

50    // Static --------------------------------------------------------
51

52    // Constructors --------------------------------------------------
53

54    public StatefulSessionBean(String JavaDoc name, ObjectName JavaDoc ejbModuleName,
55                               ObjectName JavaDoc ejbContainerName)
56            throws MalformedObjectNameException JavaDoc,
57            InvalidParentException
58    {
59       this(name, ejbModuleName, ejbContainerName, null, null);
60    }
61    /**
62     * Create a StatelessSessionBean model
63     *
64     * @param name the ejb-name from the deployment
65     * @param ejbModuleName the JSR-77 EJBModule name for this bean
66     * @param ejbContainerName the JMX name of the JBoss ejb container MBean
67     * @param jndiName the jndi name of the remote home binding is one exists,
68     * null if there is no remote home.
69     * @param localJndiName the jndi name of the local home binding is one exists,
70     * null if there is no local home.
71     * @throws MalformedObjectNameException
72     * @throws InvalidParentException
73     */

74    public StatefulSessionBean(String JavaDoc name, ObjectName JavaDoc ejbModuleName,
75       ObjectName JavaDoc ejbContainerName, String JavaDoc jndiName, String JavaDoc localJndiName)
76            throws MalformedObjectNameException JavaDoc,
77            InvalidParentException
78    {
79       super(J2EETypeConstants.StatefulSessionBean, name, ejbModuleName,
80          ejbContainerName, jndiName, localJndiName);
81       stats = new StatefulSessionBeanStatsImpl();
82    }
83
84 // Begin StatisticsProvider interface methods
85

86    /**
87     * Query the ejb container and its mbeans for the bean stats:
88     * CreateCount,
89     * RemoveCount,
90     * MethodReadyCount,
91     * PassiveCount
92     *
93     * @return the StatefulSessionBeanStats for this bean
94     */

95    public Stats JavaDoc getstats()
96    {
97       try
98       {
99          updateCommonStats(stats);
100
101          ObjectName JavaDoc poolName = getContainerPoolName();
102          RangeStatisticImpl readyCount = (RangeStatisticImpl) stats.getMethodReadyCount();
103          Integer JavaDoc poolSize = (Integer JavaDoc) server.getAttribute(poolName, "CurrentSize");
104          readyCount.set(poolSize.longValue());
105
106          ObjectName JavaDoc cacheName = getContainerCacheName();
107          RangeStatisticImpl passiveCount = (RangeStatisticImpl) stats.getPassiveCount();
108          Long JavaDoc passive = (Long JavaDoc) server.getAttribute(cacheName, "PassivatedCount");
109          passiveCount.set(passive.longValue());
110       }
111       catch (Exception JavaDoc e)
112       {
113          log.debug("Failed to retrieve stats", e);
114       }
115       return stats;
116    }
117
118    public void resetStats()
119    {
120       stats.reset();
121    }
122 // End StatisticsProvider interface methods
123

124    // Object overrides ---------------------------------------------------
125

126    public String JavaDoc toString()
127    {
128       return "StatefulSessionBean { " + super.toString() + " } []";
129    }
130
131 }
132
Popular Tags