FileDocCategorySizeDatePackage
InstanceTask.javaAPI DocGlassfish v2 API22578Fri May 04 22:32:42 BST 2007org.apache.tools.ant.taskdefs.optional.sun.appserv

InstanceTask

public class InstanceTask extends AppServerAdmin
This task controls Sun ONE Application Server 7 instances. It supports starting, stopping, restarting, creating, and removing application server instances. In addition to the server-based attributes, this task introduces one attribute:
  • action -- The control command for the application server. Valid values are "start", "stop", "restart", "create" and "delete". A restart will first send the stop command and subsequently send the start command

see
AppServerAdmin
author
Greg Nelson gn@sun.com

Fields Summary
private String
action
private static final String
ACTION_START
private static final String
ACTION_STOP
private static final String
ACTION_RESTART
private static final String
ACTION_CREATE
private static final String
ACTION_DELETE
private static final Map
ACTION_MAP
LocalStringsManager
lsm
Constructors Summary
Methods Summary
protected voidcheckConfiguration()

            if (action == null) {
                final String msg = lsm.getString("ActionCommandMustBeSpecified");
                throw new BuildException(msg, getLocation());
            }

            if (!ACTION_MAP.containsKey(action)) {
                final String msg = lsm.getString("InvalidActionCommand", new Object[] {action});
                throw new BuildException(msg, getLocation());
            }
            super.checkConfiguration();
        
protected voidcheckConfiguration(Server aServer)

            if (aServer.getInstance() == null) {
                final String msg = lsm.getString("InstanceAttributeRequired");
                throw new BuildException(msg, getLocation());
            }
            InstanceServer instanceSvr = (InstanceServer) aServer;
/*
		if (instanceSvr.isLocal() || (instanceSvr.getDomain() != null)) {
			if (instanceSvr.getHost() != null) {
                final String msg = lsm.getString("HostAttributeIgnored");
				log(msg, Project.MSG_WARN);
			}
			if (instanceSvr.getPort() != 0) {
                final String msg = lsm.getString("PortAttributeIgnored");
				log(msg, Project.MSG_WARN);
			}
			if ((instanceSvr.getUser() != null) && (!instanceSvr.getUser().equals("admin"))) {
                final String msg = lsm.getString("UserAttributeIgnored");
				log(msg, Project.MSG_WARN);
			}
			if (instanceSvr.hasPassword()) {
                final String msg = lsm.getString("PasswordAttributeIgnored");
				log(msg, Project.MSG_WARN);
			}
		} else {
			if (!instanceSvr.hasPassword()) {
                final String msg = lsm.getString("PasswordAttributeNotSpecified");
				throw new BuildException(msg, getLocation());
			}
		}

		if ((instanceSvr.getDomain() != null) && !instanceSvr.isLocal()) {
            final String msg = lsm.getString("DomainAttributeIgnored");
			log(msg, Project.MSG_WARN);
		}
*/
            if (!instanceSvr.hasPassword()) {
                final String msg = lsm.getString("PasswordAttributeNotSpecified");
                throw new BuildException(msg, getLocation());
            }
            if (action.equals(ACTION_CREATE)) {
                if (instanceSvr.getNodeagent() == null) {
                    final String msg = lsm.getString("AttributeMustBeSpecified", new Object[] {"nodeagent"});
                    throw new BuildException(msg, getLocation());
                }
            }
	
protected voidexecute(Server aServer)

		InstanceServer instanceSvr = (InstanceServer) aServer;
        
        if ( instanceSvr.getConfig() != null &&
             instanceSvr.getCluster() != null ) {
            final String msg = lsm.getString("MutuallyExclusivelyAttribute",
                                             new Object[] {"config", "cluster"});
            throw new BuildException(msg, getLocation());
        }

		StringBuffer cmd = new StringBuffer((String) ACTION_MAP.get(action));
                cmd.append(instanceSvr.getCommandParameters(false));
		if (action.equals(ACTION_CREATE)) {
			//cmd.append(" --instanceport " + instanceSvr.getInstanceport());
                    cmd.append(" --nodeagent " + instanceSvr.getNodeagent());
                    if (instanceSvr.getConfig() != null)
                        cmd.append(" --config " + instanceSvr.getConfig());
                    if (instanceSvr.getCluster() != null)
                        cmd.append(" --cluster " + instanceSvr.getCluster());
                    if (instanceSvr.getProperty() != null)
                        cmd.append(" --systemproperties " + instanceSvr.getProperty());
		} else if (action.equals(ACTION_START)) {
			//cmd.append(" --debug=" + instanceSvr.isDebug());
		}
/*
		if (instanceSvr.isLocal()) {
			if (instanceSvr.getDomain() != null) {
				cmd.append(" --domain ").append(instanceSvr.getDomain());
			}
			cmd.append(" --local=true");			
		} else {
			cmd.append(instanceSvr.getCommandParameters(false));
		}
*/
		cmd.append(' ").append(instanceSvr.getInstance());

		execAdminCommand(cmd.toString());

/*		String cmdString = (String) ACTION_MAP.get(action);
		cmdString += aServer.getCommandParameters(false);
		if (action.equals(ACTION_CREATE)) {
			cmdString += " --instanceport " + aServer.getInstanceport();
		}
		if (aServer.getInstance() != null) {
			cmdString += " " + aServer.getInstance();
		}
		execAdminCommand(cmdString);
 */
	
protected ServergetNewServer()

		return new InstanceServer(server);
	
public voidsetAction(java.lang.String action)
Sets the action for the instance command.

param
action The action for the instance command.



	               	 
	    
		this.action = action;
	
public voidsetCluster(java.lang.String cluster)
Sets the cluster to be used by a new application server instance.

param
cluster The cluster of the new application server instance

            ((InstanceServer)server).setCluster(cluster);  // Delegates to server object
        
public voidsetConfig(java.lang.String config)
Sets the config to be used by a new application server instance.

param
config The config of the new application server instance

            ((InstanceServer)server).setConfig(config);  // Delegates to server object
        
public voidsetDebug(boolean debug)
Set if the instance should be started in debug mode. Defaults to false.

param
debug If set to true, the instance will be in debug mode.

            final String msg = lsm.getString("AttributeNotSupported", 
                                                new Object[] {"debug"});
            log(msg, Project.MSG_WARN);
            //((InstanceServer)server).setDebug(debug);  // Delegates to server object
	
public voidsetDomain(java.lang.String domain)
Sets the domain for the administrative command -- some commands allow the domain to be set for "local" commands instead of username, password, host and password.

param
domain The domain name for the administrative command.

            final String msg = lsm.getString("AttributeNotSupported", 
                                                new Object[] {"domain"});
            log(msg, Project.MSG_WARN);
            //((InstanceServer)server).setDomain(domain);  // Delegates to server object
	
public voidsetInstanceport(int instanceport)
Sets the port number to be used by a new application server instance.

param
instanceport The port number of the new application server instance

            final String msg = lsm.getString("AttributeNotSupported", 
                                                new Object[] {"instanceport"});
            log(msg, Project.MSG_WARN);
            //((InstanceServer)server).setInstanceport(instanceport);
	
public voidsetLocal(boolean local)
Set if the instance should be started without an admin server running.

param
local If set to true, the instance will be started without the need for an admin server.

            final String msg = lsm.getString("AttributeNotSupported", 
                                                new Object[] {"local"});
            log(msg, Project.MSG_WARN);
            //((InstanceServer)server).setLocal(local);  // Delegates to server object
	
public voidsetNodeagent(java.lang.String nodeagent)
Sets the nodeagent to be used by a new application server instance.

param
nodeagent The nodeagent of the new application server instance

            ((InstanceServer)server).setNodeagent(nodeagent);  // Delegates to server object
        
public voidsetProperty(java.lang.String property)
Sets the property to be used by a new application server instance.

param
property The nodeagent of the new application server instance

            ((InstanceServer)server).setProperty(property);  // Delegates to server object