FileDocCategorySizeDatePackage
CallflowCommand.javaAPI DocGlassfish v2 API8773Fri May 04 22:25:08 BST 2007com.sun.enterprise.cli.commands

CallflowCommand

public class CallflowCommand extends S1ASCommand
This class is the implementation for start-callflow-monitoring and start-callflow-monitoring command.
author
Jane Young
version
$Revision: 1.7 $

Fields Summary
private static final String
FILTER_TYPE_OPTION
private static final String
CALLER_IPFILTER
private static final String
CALLER_PRINCIPALFILTER
private static final String
ENABLED
private static final String
FILTER_TYPE_USER
private static final String
FILTER_TYPE_IP
private static final String
START_CALL_FLOW
private String
sFilterIP
private String
sFilterUserID
Constructors Summary
Methods Summary
private com.sun.appserv.management.monitor.CallFlowMonitorgetCallFlowMonitor(javax.management.MBeanServerConnection mbsc, java.lang.String instanceName)

        DomainRoot domainRoot = 
                ProxyFactory.getInstance(mbsc).getDomainRoot();
        Map<String,ServerRootMonitor> serverRootMonitorMap = 
                domainRoot.getMonitoringRoot().getServerRootMonitorMap();
        ServerRootMonitor serverRootMonitor = serverRootMonitorMap.get(instanceName);
        //IF the instance is not running or when no monitoring on, just return;
        if (serverRootMonitor == null)
            return null;
        CallFlowMonitor cfm = serverRootMonitor.getCallFlowMonitor();
        return cfm;
    
public voidrunCommand()
An abstract method that Executes the command

throws
CommandException


    
                    
         
    
        if (!validateOptions())
            throw new CommandValidationException("Validation is false");
        
        //use http connector
        MBeanServerConnection mbsc = getMBeanServerConnection(getHost(), getPort(), 
                                                              getUser(), getPassword());
        final String instanceName = (String) getOperands().get(0);
        
        //Set the Enabled Attribute
        try
        {
            verifyTargetInstance(mbsc, instanceName);
            CallFlowMonitor cfm = getCallFlowMonitor(mbsc, instanceName);
            setCallFlowConfig(cfm);
        }
        catch(Exception e)
        {
            displayExceptionMessage(e);
        }

        CLILogger.getInstance().printDetailMessage(getLocalizedString(
                                                   "CommandSuccessful",
                                                   new Object[] {name}));
    
private voidsetCallFlowConfig(com.sun.appserv.management.monitor.CallFlowMonitor cfm)
This method sets the callflow attributes for a given instance

throws
CommandException, CommandValidationException

        validateFilterType();
        final Boolean bEnable = Boolean.valueOf(name.equals(START_CALL_FLOW)?true:false);
        
        if (cfm != null){
            cfm.setEnabled(bEnable);
            if (sFilterIP != null)
               cfm.setCallerIPFilter(sFilterIP);
            if (sFilterUserID != null)
                cfm.setCallerPrincipalFilter(sFilterUserID);
        }
    
private voidvalidateFilterType()
This method validates filtertype. There are currently two filtertype. They are user and ip. If type user, the attribute to set is CALLER_PRINCIPALFILTER. If type ip, the attribute to set is CALLER_IPFILTER. If type other than user or ip then throw a CommandValidationException If type is not in the correct format, then an exception is thrown. filterypte should be in the format of name=value with : as the delimiter.

throws
CommandException and CommandValidationException

        if (getOption(FILTER_TYPE_OPTION) != null) {
            final String filterType = getOption(FILTER_TYPE_OPTION);
            
            final CLITokenizer filterTypeTok = new CLITokenizer(filterType, PROPERTY_DELIMITER);
            while (filterTypeTok.hasMoreTokens()) {
                final String nameAndvalue = filterTypeTok.nextToken();
                final CLITokenizer nameTok = new CLITokenizer(nameAndvalue, PARAM_VALUE_DELIMITER);
                if (nameTok.countTokens() == 2)
                {
                    final String sName = nameTok.nextTokenWithoutEscapeAndQuoteChars();
                    final String sValue = nameTok.nextTokenWithoutEscapeAndQuoteChars();
                    if (sName.equals(FILTER_TYPE_IP))
                        sFilterIP = sValue;
                    else if (sName.equals(FILTER_TYPE_USER))
                        sFilterUserID = sValue;
                    else
                        throw new CommandValidationException(getLocalizedString("InvalidFilterName", new Object[] {sName}));
                } else {
                        throw new CommandValidationException(getLocalizedString("InvalidFilterType", new Object[] {filterType}));
                }
                
            }
        }
    
private voidverifyTargetInstance(javax.management.MBeanServerConnection mbsc, java.lang.String instanceName)

        DomainRoot domainRoot = 
                ProxyFactory.getInstance(mbsc).getDomainRoot();
        boolean isServer=false;
        isServer = domainRoot.getDomainConfig().getServerConfigMap().keySet().contains(instanceName);
        if ( ! isServer ) 
        {
            throw new CommandException(getLocalizedString("TargetNotAnInstance", 
                                                 new Object[] {instanceName}));
        }
        else
        {
            final Map<String,J2EEServer> servers =
                domainRoot.getJ2EEDomain().getJ2EEServerMap();
            J2EEServer server = servers.get( instanceName );

            boolean running = server != null &&
                                server.getstate() == server.STATE_RUNNING || 
                                server.getstate() == server.STATE_STARTING;
            if (!running)
                throw new CommandException(getLocalizedString("InstanceNotRunning",
                                                  new Object[] {instanceName}));
        }