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

StatelessSessionBeanMonitorTask

public class StatelessSessionBeanMonitorTask extends BeanMonitorTask

Fields Summary
private final String
displayFormat
Constructors Summary
public StatelessSessionBeanMonitorTask(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.stateless_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 statelessSessionBeanTitle = localStrings.getString("commands.montor.stateless_session_bean_title", new Object[] {this.filter});
        final String title = String.format("%1$50s", statelessSessionBeanTitle);
        CLILogger.getInstance().printMessage(title);
        displayHeader();        
    
Methods Summary
booleancheckIfBeanExists(java.util.Map ejbModuleMap)
returns true if statelesssessionbean 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,StatelessSessionBeanMonitor> beanMap = ejbModuleMonitor.getStatelessSessionBeanMonitorMap();
            if (!beanMap.containsKey(beanName))
                return false;
            else
                return true;
        }
    
private voiddisplayData(StatelessSessionBeanStats stat)

        final String data = String.format(displayFormat,
                                          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",
                                          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.stateless_session_bean_detail");
        CLILogger.getInstance().printMessage(details);
    
private voiddisplayHeader()

        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", methodReadyCount);
        final String subHeader = String.format(displayFormat, low,high,current,create,remove);
        CLILogger.getInstance().printMessage(header);
        CLILogger.getInstance().printMessage(subHeader);        
        if (fileName != null)
        {
            writeToFile(localStrings.getString("commands.montor.stateless_sesson_bean_write_to_file"));
        }
    
java.util.ListgetBeansInEjbModule(java.lang.String appName, java.util.Map ejbModuleMap)

        List<String> possibleStatelessSessionBeans = 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,StatelessSessionBeanMonitor> beanMap = ejbModuleMonitor.getStatelessSessionBeanMonitorMap();
                final String[] statelessBeans = MapUtil.getKeyStrings(beanMap);
                for (String statelessBean : statelessBeans)
                {
                    if (appName == null)
                        possibleStatelessSessionBeans.add(ejbModule+":"+statelessBean);
                    else
                        possibleStatelessSessionBeans.add(appName+":"+ejbModule+":"+statelessBean);
                }
            }
        }
        return possibleStatelessSessionBeans;
    
private StatelessSessionBeanMonitorgetStatelessSessionBeanMonitor(java.util.Map ejbMap)

        final EJBModuleMonitor ejbModuleMonitor = ejbMap.get(ejbName);
        final Map<String,StatelessSessionBeanMonitor> mdbMap = ejbModuleMonitor.getStatelessSessionBeanMonitorMap();
        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 StatelessSessionBeanMonitor monitor = getStatelessSessionBeanMonitor(ejbMap);
        if (monitor == null) {
            cancelMonitorTask();
            return;
        }
            
        final StatelessSessionBeanStats stat = monitor.getStatelessSessionBeanStats();
        
        if (verbose && counter == NUM_ROWS)
        {
            displayHeader();
            counter = 0;  //reset to 0
        }
        displayData(stat);
        if (verbose) counter++;