FileDocCategorySizeDatePackage
RuntimeStatus.javaAPI DocGlassfish v2 API11614Tue May 22 17:02:24 BST 2007com.sun.enterprise.admin.servermgmt

RuntimeStatus

public class RuntimeStatus extends Object implements Serializable
author
kebbs

Fields Summary
private boolean
_restartNeeded
private com.sun.enterprise.admin.common.Status
_status
private Vector
_recentErrorMessages
private String
_name
private boolean
stopCluster
private boolean
startCluster
private RuntimeStatus
beforeRTStatus
Constructors Summary
public RuntimeStatus()

         
        this ("", true, new Status(Status.kInstanceNotRunningCode, 
            Status.kInstanceNotRunningMsg), new Vector());
    
public RuntimeStatus(String name)

         
        this();
        _name = name;
    
public RuntimeStatus(String name, boolean restartNeeded, com.sun.enterprise.admin.common.Status status, Vector recentErrors)

        _name = name;
        _restartNeeded = restartNeeded;
        _status = status;
        _recentErrorMessages = recentErrors;
    
Methods Summary
public static voidclearRuntimeStatus()

        FileandSyslogHandler.clearRecentErrorMessages();
    
public java.lang.StringgetName()

        return _name;
    
public java.util.VectorgetRecentErrorMessages()

        return _recentErrorMessages;
    
public static com.sun.enterprise.admin.servermgmt.RuntimeStatusgetRuntimeStatus(java.lang.String name, com.sun.enterprise.admin.servermgmt.InstancesManager manager)

    
       
         
            
                    
        int status = manager.getInstanceStatus();          
        return new RuntimeStatus(name, manager.isRestartNeeded(),
            new Status(status, Status.getStatusString(status)),
            FileandSyslogHandler.getRecentErrorMessages());        
    
public com.sun.enterprise.admin.common.StatusgetStatus()

        return _status;
    
public booleanisRestartNeeded()

        return _restartNeeded;
    
public booleanisRunning()

        return getStatus().getStatusCode() == Status.kInstanceRunningCode ? true : false;        
    
public booleanisStopped()

        return getStatus().getStatusCode() == Status.kInstanceNotRunningCode ? true : false;
    
public voidresetRecentErrorMessages()

        // used by start-cluster when the instances are all running already.
        // we don't need to show these old messages to them now.
        _recentErrorMessages = new Vector();
    
public voidsetStartClusterFlag(com.sun.enterprise.admin.servermgmt.RuntimeStatus before)

		startCluster = true;
        beforeRTStatus = before;
	
public voidsetStatus(com.sun.enterprise.admin.common.Status status)

        _status = status;
    
public voidsetStopClusterFlag(com.sun.enterprise.admin.servermgmt.RuntimeStatus before)

		stopCluster = true;
        beforeRTStatus = before;
	
public java.lang.StringtoShortString()

        String result = getStatus().getStatusString();
        if (isRunning()) {
            if (isRestartNeeded()) {
                result = LocalStrings.get("requiresRestartYes");
            } 
        } 
        return result;
    
public java.lang.StringtoString()

		if(stopCluster)
			return toStringStopCluster();

        if(startCluster)
			return toStringStartCluster();
		
		return toStringRegular();
	
private java.lang.StringtoStringRegular()

        LocalStringsImpl stringy = new LocalStringsImpl();
        String result = stringy.get("runtimeStatusToString", getName(), getStatus().getStatusString());
        if (isRestartNeeded()) {
            result += ", " + stringy.get("requiresRestartYes");
        } else {
            result += ", " + stringy.get("requiresRestartNo");
        }
        
        Vector messages = getRecentErrorMessages();
        for (int i = 0; i < messages.size(); i++) {
            result += "\n" + stringy.get("error") + " " + i + " " + (String)messages.get(i);
        }

        return result;
    
public java.lang.StringtoStringStartCluster()

        /* 
         * WBN May 2007
         * These are impossible states:
         * (1) ANY instances are still running in the cluster
         * (2) ALL instances are already stopped (beforeRTStatus)
         * (3) The before-status==stopped && after-status==!stopped
         */

        if(beforeRTStatus == null)
        {
            // this is a programming error!
            return toStringRegular();
        }
        
        // by my definition, "started" == kInstanceRunningCode
        //  "not-started" == !kInstanceRunningCode
        final int afterCode = getStatus().getStatusCode();
        final int beforeCode = beforeRTStatus.getStatus().getStatusCode();
        final boolean beforeStarted =  (beforeCode == Status.kInstanceRunningCode);
        final boolean afterStarted  =  (afterCode == Status.kInstanceRunningCode);
        LocalStringsImpl stringy = new LocalStringsImpl();
        final String name = getName();
        final String beforeString = beforeRTStatus.getStatus().getStatusString();
        final String afterString = getStatus().getStatusString();
        String result = "";

        if(beforeStarted && afterStarted)
        {
            // normal -- instance was already running
            result = stringy.get("runtimeStatusToStringStartCluster.alreadyStarted", name);
        }
        
        else if(!beforeStarted && afterStarted)
        {
            // normal -- instance was stopped and is now running
            result = stringy.get("runtimeStatusToStringStartCluster.success", name);
        }
        else if(beforeStarted && !afterStarted)
        {
            // this can't happen...
            result = stringy.get("runtimeStatusToStringStartCluster.startedToStopped", 
                    name, afterString);
            
            // there is no logger available in this file
            System.err.println(result);
        }
        else if(!beforeStarted && !afterStarted)
        {
            // a "normal" error -- the instance could not be Started.
            
            result = stringy.get("runtimeStatusToStringStartCluster.error", name, 
                    beforeString, afterString);
        }
        
		Vector messages = getRecentErrorMessages();
        for (int i = 0; i < messages.size(); i++) {
            result += "\n" + stringy.get("error") + " " + i + " " + (String)messages.get(i);
        }

        return result;
    
public java.lang.StringtoStringStopCluster()

        /* 
         * WBN Feb 2007
         * These are impossible states:
         * (1) ANY instances are still running in the cluster
         * (2) ALL instances are already stopped (beforeRTStatus)
         * (3) The before-status==stopped && after-status==!stopped
         */

        if(beforeRTStatus == null)
        {
            // this is a programming error!
            return toStringRegular();
        }
        
        // by my definition, "stopped" == kInstanceNotRunningCode
        //  "not-stopped" == !kInstanceNotRunningCode
        final int afterCode = getStatus().getStatusCode();
        final int beforeCode = beforeRTStatus.getStatus().getStatusCode();
        final boolean beforeStopped =  (beforeCode == Status.kInstanceNotRunningCode);
        final boolean afterStopped  =  (afterCode == Status.kInstanceNotRunningCode);
        LocalStringsImpl stringy = new LocalStringsImpl();
        final String name = getName();
        final String beforeString = beforeRTStatus.getStatus().getStatusString();
        final String afterString = getStatus().getStatusString();
        String result = "";

        if(beforeStopped && afterStopped)
        {
            // normal -- instance was already stopped
            result = stringy.get("runtimeStatusToStringStopCluster.alreadyStopped", name);
        }
        
        else if(!beforeStopped && afterStopped)
        {
            // normal -- instance was running and was stopped.
            result = stringy.get("runtimeStatusToStringStopCluster.success", name);
        }
        else if(beforeStopped && !afterStopped)
        {
            // this can't happen...
            result = stringy.get("runtimeStatusToStringStopCluster.stoppedToRunning", 
                    name, afterString);
            
            // there is no logger available in this file
            System.err.println(result);
        }
        else if(!beforeStopped && !afterStopped)
        {
            // a "normal" error -- the instance could not be stopped.
            
            result = stringy.get("runtimeStatusToStringStopCluster.error", name, 
                    beforeString, afterString);
        }
        
		Vector messages = getRecentErrorMessages();
        for (int i = 0; i < messages.size(); i++) {
            result += "\n" + stringy.get("error") + " " + i + " " + (String)messages.get(i);
        }

        return result;