FileDocCategorySizeDatePackage
StatefulSessionBeanMonitorTask.javaAPI DocGlassfish v2 API10824Fri May 04 22:25:18 BST 2007com.sun.enterprise.cli.commands.monitor

StatefulSessionBeanMonitorTask

public class StatefulSessionBeanMonitorTask extends BeanMonitorTask

Fields Summary
private final String
displayFormat
Constructors Summary
public StatefulSessionBeanMonitorTask(ServerRootMonitor srm, String filter, Timer timer, boolean verbose, File fileName)


             
                                             
         
    
        super(srm, filter, timer, verbose, fileName);
        
        if (this.filter == null)
            getDefaultFilter();
        else
        {
            final StringTokenizer st = new StringTokenizer(this.filter, ":");
            if (st.countTokens() < 2 )
                throw new MonitorTaskException(localStrings.getString("commands.monitor.stateful_session_bean_invalid_filter"));
            else if (st.countTokens() == 2)
            {
                ejbName = st.nextToken();
                beanName = st.nextToken();
            }
            else {
                appName = st.nextToken();
                ejbName = st.nextToken();
                beanName = st.nextToken();
            }
            verifyFilterValue();
        }
        final String statefulSessionBeanTitle = localStrings.getString("commands.monitor.stateful_session_bean_title", new Object[] {this.filter});
        final String title = String.format("%1$50s", statefulSessionBeanTitle);
        CLILogger.getInstance().printMessage(title);
        displayHeader();        
    
Methods Summary
booleancheckIfBeanExists(java.util.Map ejbModuleMap)
returns true if statefulsessionbean exists in ejbmodule

throws
MonitorTaskException if ejbmodule is invalid.

        if (!ejbModuleMap.containsKey(ejbName))
        {
            if (appName == null)
                throw new MonitorTaskException(localStrings.getString("commands.monitor.does_not_exist", new Object[] {ejbName}));
            else
                throw new MonitorTaskException(localStrings.getString("commands.monitor.does_not_exist_in1", new Object[] {ejbName, appName}));
        }
        else {
            final EJBModuleMonitor ejbModuleMonitor = ejbModuleMap.get(ejbName);
            final Map<String,StatefulSessionBeanMonitor> beanMap = ejbModuleMonitor.getStatefulSessionBeanMonitorMap();
            if (!beanMap.containsKey(beanName))
                return false;
            else
                return true;
        }
    
private voiddisplayData(StatefulSessionBeanStats stat)

        final String data = String.format(displayFormat,
                                          stat.getPassiveCount().getLowWaterMark(),
                                          stat.getPassiveCount().getHighWaterMark(),
                                          stat.getPassiveCount().getCurrent(),
                                          stat.getMethodReadyCount().getLowWaterMark(),
                                          stat.getMethodReadyCount().getHighWaterMark(),
                                          stat.getMethodReadyCount().getCurrent(),
                                          stat.getCreateCount().getCount(),
                                          stat.getRemoveCount().getCount());
        CLILogger.getInstance().printMessage(data);
        if (fileName != null)
        {
            final String fileData = String.format("%1$s,%2$s,%3$s,%4$s,%5$s,%6$s,%7$s,%8$s",
                                          stat.getPassiveCount().getLowWaterMark(),
                                          stat.getPassiveCount().getHighWaterMark(),
                                          stat.getPassiveCount().getCurrent(),
                                          stat.getMethodReadyCount().getLowWaterMark(),
                                          stat.getMethodReadyCount().getHighWaterMark(),
                                          stat.getMethodReadyCount().getCurrent(),
                                          stat.getCreateCount().getCount(),
                                          stat.getRemoveCount().getCount());
            writeToFile(fileData);
        }
    
public voiddisplayDetails()

        final String details = localStrings.getString("commands.monitor.stateful_session_detail");
        CLILogger.getInstance().printMessage(details);
    
private voiddisplayHeader()

        final String passiveCount = localStrings.getString("commands.monitor.PassiveCount");
        final String methodReadyCount = localStrings.getString("commands.monitor.MethodReadyCount");
        final String low = localStrings.getString("commands.monitor.low");
        final String high = localStrings.getString("commands.monitor.high");
        final String current = localStrings.getString("commands.monitor.current");
        final String create = localStrings.getString("commands.monitor.create");
        final String remove = localStrings.getString("commands.monitor.remove");
        
        final String header = String.format("%1$20s %2$27s", passiveCount, methodReadyCount);
        final String subHeader = String.format(displayFormat, low,high,current,low,high,
                                               current,create,remove);
        
        CLILogger.getInstance().printMessage(header);
        CLILogger.getInstance().printMessage(subHeader);

        if (fileName != null)
        {
            writeToFile(localStrings.getString("commands.monitor.stateful_session_write_to_file"));
        }
    
java.util.ListgetBeansInEjbModule(java.lang.String appName, java.util.Map ejbModuleMap)

        List<String> possibleStatefulSessionBeans = new Vector<String>();
        final String[] ejbModules = MapUtil.getKeyStrings(ejbModuleMap);
        if (ejbModuleMap != null && ejbModuleMap.size() > 0)
        {
            for (String ejbModule : ejbModules)
            {
                final EJBModuleMonitor ejbModuleMonitor = ejbModuleMap.get(ejbModule);
                final Map<String,StatefulSessionBeanMonitor> beanMap = ejbModuleMonitor.getStatefulSessionBeanMonitorMap();
                final String[] statefulBeans = MapUtil.getKeyStrings(beanMap);
                for (String statefulBean : statefulBeans)
                {
                    if (appName == null)
                        possibleStatefulSessionBeans.add(ejbModule+":"+statefulBean);
                    else
                        possibleStatefulSessionBeans.add(appName+":"+ejbModule+":"+statefulBean);
                }
            }
        }
        return possibleStatefulSessionBeans;
    
private StatefulSessionBeanMonitorgetStatefulSessionBeanMonitor(java.util.Map ejbMap)

        final EJBModuleMonitor ejbModuleMonitor = ejbMap.get(ejbName);
        final Map<String,StatefulSessionBeanMonitor> mdbMap = ejbModuleMonitor.getStatefulSessionBeanMonitorMap();
        return mdbMap.get(beanName);
    
public voidrun()

        if (srm == null) {
            super.cancelMonitorTask();
            return;
        }
        
        Map<String,EJBModuleMonitor> ejbMap = null;
        if (appName == null)
        {
            ejbMap = srm.getEJBModuleMonitorMap();
        }
        else
        {
            final Map<String,ApplicationMonitor> appMap = srm.getApplicationMonitorMap();
            if (appMap == null || appMap.size()<1) {
                cancelMonitorTask();
                return;
            }
            
            final ApplicationMonitor am = appMap.get(appName);
            ejbMap = am.getEJBModuleMonitorMap();
        }
        if (ejbMap == null || ejbMap.size()<1) {
            cancelMonitorTask();
            return;
        }
        
        final StatefulSessionBeanMonitor monitor = getStatefulSessionBeanMonitor(ejbMap);
        if (monitor == null) {
            cancelMonitorTask();
            return;
        }
            
        final StatefulSessionBeanStats stat = monitor.getStatefulSessionBeanStats();
        
        if (verbose && counter == NUM_ROWS)
        {
            displayHeader();
            counter = 0;  //reset to 0
        }
        displayData(stat);
        if (verbose) counter++;