FileDocCategorySizeDatePackage
StopDomainCommand.javaAPI DocGlassfish v2 API7083Thu May 31 23:11:26 BST 2007com.sun.enterprise.cli.commands

StopDomainCommand

public class StopDomainCommand extends BaseLifeCycleCommand
This command class stops the domain
version
$Revision: 1.8 $

Fields Summary
Constructors Summary
Methods Summary
public voidrunCommand()
An abstract method that Executes the command

throws
CommandException

        validateOptions();
        String domainName = null;
        try {
            domainName = getDomainName();
        } catch(Exception e) {
            CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());
            domainName = domainName==null?getLocalizedString("Undefined"):domainName;
            throw new CommandException(getLocalizedString("CannotStopDomain",
                                                          new Object[] {domainName} ), e);
        }
        stopDomain(domainName);
    
public voidstopDomain(java.lang.String domainName)

        try {            
            final ClientPluggableFeatureFactory fac     = getFeatureFactory();
            final DomainsManager                mgr     = fac.getDomainsManager();
            final DomainConfig                  cfg     = getDomainConfig(domainName);
            final InstancesManager              im      = mgr.getInstancesManager(cfg);
            final int                           state   = im.getInstanceStatus();
            final String[]			domains = mgr.listDomains(cfg);
            boolean				exists	= false;
			
            for(int i = 0; domains != null && i < domains.length; i++)
     	    {
                if(domains[i].equals(domainName))
                {
                    exists = true;
                    break;
                }
            }

            if(!exists)
            {
                // it doesn't exist -- let the existing code throw an Exception with
		// the correct error message
               stopDomain(mgr, cfg);
            }

            // check if the Domain is running
            else if (state == Status.kInstanceRunningCode)
            {
                stopDomain(mgr, cfg);
            
                CLILogger.getInstance().printDetailMessage(getLocalizedString("DomainStopped",
                                                           new Object[] {domainName}));
            }
            else if (state == Status.kInstanceStartingCode)
            {
                stopDomain(mgr, cfg);
            
                CLILogger.getInstance().printDetailMessage(getLocalizedString("DomainStoppedWasStarting",
                                                           new Object[] {domainName}));
            }
            else
            {
                //print the message if domain already stopped
                CLILogger.getInstance().printDetailMessage(getLocalizedString("CannotStopDomainAlreadyStopped",
                                                                              new Object[] {domainName}));
            }
            unconfigureAddons();
        }
        catch(Exception e) {
            CLILogger.getInstance().printDetailMessage(e.getLocalizedMessage());         
            throw new CommandException(getLocalizedString("CannotStopDomain",
                                                           new Object[] {domainName} ), e);
        }
    
private voidstopDomain(com.sun.enterprise.admin.servermgmt.DomainsManager mgr, com.sun.enterprise.admin.servermgmt.DomainConfig cfg)

        String forceOption = getCLOption(KILL);
        if (forceOption == null) {
            mgr.stopDomain(cfg);
        } else {
            int timeout = getIntegerOption(KILL);
            mgr.stopDomainForcibly(cfg, timeout);
        }
    
private voidunconfigureAddons()

        try {
            AddonControl ac = new AddonControl();
            String domainInstanceRoot = getDomainsRoot() + File.separator + getDomainName();
            ac.unconfigureDAS(new File(domainInstanceRoot));
        }catch(Throwable t) {
            CLILogger.getInstance().printDetailMessage(t.getLocalizedMessage());
        }

    
public booleanvalidateOptions()
An abstract method that validates the options on the specification in the xml properties file This method verifies for the correctness of number of operands and if all the required options are supplied by the client.

return
boolean returns true if success else returns false

        return super.validateOptions();