FileDocCategorySizeDatePackage
ChangeStateAction.javaAPI DocGlassfish v2 API6958Fri May 04 22:34:36 BST 2007com.sun.enterprise.deployment.client

ChangeStateAction

public class ChangeStateAction extends com.sun.enterprise.deployapi.ProgressObjectImpl

Fields Summary
private static final Set
unchangeableStateModuleTypes
Constructors Summary
public ChangeStateAction(com.sun.enterprise.deployapi.SunTarget[] targets)

        super(targets);
    
Methods Summary
private static java.util.SetinitUnchangeableStateModuleTypes()


        
        Set<ModuleType> result = new HashSet<ModuleType>();
        result.add(ModuleType.CAR);
        return result;
    
public voidrun()

        ConnectionSource dasConnection= (ConnectionSource) args[0];
        SunTarget[] targets = (SunTarget[]) args[1];
        moduleID = (String) args[2];
        CommandType newState = (CommandType) args[3];
        SunTarget domain = (SunTarget) args[4];
        StringManager localStrings = StringManager.getManager(getClass());

        ModuleType moduleType;
        try {
            moduleType = DeploymentClientUtils.getModuleType(
                dasConnection.getExistingMBeanServerConnection(), moduleID);
        } catch (Throwable ioex) {
            finalDeploymentStatus.setStageException(ioex);
            setupForAbnormalExit(localStrings.getString("enterprise.deployment.client.unrecognized_module_type", moduleID ,ioex.getMessage()),
                        domain);
            return;
        }
        
        boolean state = false;
        String action = "Disable";
        if (CommandType.START.equals(newState)) {
            state = true;
            action = "Enable";
        }

        // the target module ids in which the operation was successful
        ArrayList resultTargetModuleIDs = new ArrayList();             

        for(int i=0; i<targets.length; i++) {
            DeploymentStatus stat = new DeploymentStatus();
            stat.setStageDescription(
                localStrings.getString("enterprise.deployment.client.state_change_desc", action, moduleID));
            try {
                /*
                 *If the module type supports state changes, change the state.
                 *Otherwise prepare a warning status with a "no-op" message.
                 */
                String messageKey;
                int deplStatus;
                if (! unchangeableStateModuleTypes.contains(moduleType)) {
                    messageKey = "enterprise.deployment.client.state_change_success";
                    deplStatus = DeploymentStatus.SUCCESS;
                    
                    DeploymentClientUtils.changeStateOfModule(dasConnection.getExistingMBeanServerConnection(), moduleID,
                                    ((moduleType == null) ? null : moduleType.toString()), targets[i], state);
                } else {
                    messageKey = "enterprise.deployment.client.state_change_noop";
                    deplStatus = DeploymentStatus.SUCCESS;
                }
                stat.setStageStatus(deplStatus);
                stat.setStageStatusMessage(localStrings.getString(messageKey, action, moduleID));
            } catch (Throwable ex) {
                String msg;
                if (CommandType.START.equals(newState)) {
                    msg = localStrings.getString(
                        "enterprise.deployment.client.start.failed");
                } else {
                    msg = localStrings.getString(
                        "enterprise.deployment.client.stop.failed");
                }
                stat.setStageException(ex);
                stat.setStageStatus(DeploymentStatus.FAILURE);
                stat.setStageStatusMessage(msg + ex.getMessage());
            }
            if(!checkStatusAndAddStage(targets[i], null, 
                            localStrings.getString("enterprise.deployment.client.change_state", action, moduleID, targets[i].getName()), dasConnection, stat, state)) {
                return;
            }
            resultTargetModuleIDs.add(new SunTargetModuleID(moduleID, targets[i]));
        }

        // initialize the instance variable targetModuleIDs using 
        // the successful module ids
        this.targetModuleIDs = new TargetModuleID[resultTargetModuleIDs.size()];
        this.targetModuleIDs = 
            (TargetModuleID[])resultTargetModuleIDs.toArray(this.targetModuleIDs);

        setupForNormalExit(localStrings.getString("enterprise.deployment.client.change_state_all", action), domain);