FileDocCategorySizeDatePackage
RRStateFactory.javaAPI DocGlassfish v2 API5806Fri May 04 22:33:46 BST 2007com.sun.enterprise.admin.server.core.channel

RRStateFactory

public class RRStateFactory extends Object
Responsible for persisting restart required state.
author
Nazrul Islam
since
JDK1.4

Fields Summary
private static final String
STATE_FILE_NM
private static final String
DEF_LOCATION
Constructors Summary
Methods Summary
public static booleangetState()
Reads the persisted server instance's restart required state. If the state file is not present, it returns false, i.e., server instance does not require a restart. This uses current server's instance root.

return
restart required state

        return getState(null);
    
public static booleangetState(java.lang.String instanceRoot)
Reads the persisted server instance's restart required state. If the state file is not present, it returns false, i.e., server instance does not require a restart.

param
instanceRoot server instance root
return
restart required state


        boolean restartNeeded = false;
        File f = getStateFile(instanceRoot);

        if (f.exists()) {
            BufferedReader br = null;
            try {
                br = new BufferedReader(new FileReader(f));
                String state = br.readLine();
                restartNeeded = new Boolean(state.trim()).booleanValue();
            } catch (IOException ioe) {
            } finally {
                if (br != null) {
                    try {
                        br.close();
                    } catch (IOException e) {}
                }
            }
        }

        return restartNeeded;
    
private static java.io.FilegetStateFile(java.lang.String instanceRoot)
Returns the state file handle.

param
iRoot instance root
return
the state file


        // instance root
        if (instanceRoot == null) {
            instanceRoot = System.getProperty(
                SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, DEF_LOCATION);
        }

        // state file
        File f = new File(instanceRoot + File.separator + STATE_FILE_NM);

        return f;
    
public static voidmain(java.lang.String[] args)

        try {
            System.setProperty(
                SystemPropertyConstants.INSTANCE_ROOT_PROPERTY, "/tmp");
            saveState(true);
            boolean state = getState();
            System.out.println(state);
            removeStateFile();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
public static voidremoveStateFile()
Removes the restart required state file.

        File state = getStateFile(null);
        if (state.exists()) {
            FileUtils.liquidate(state);
        }
    
public static voidsaveState(boolean state)
Saves the restart required state of the server instance.

param
state restart required state
throws
IOException if an i/o error


        File stateFile  = getStateFile(null);
        FileWriter fw   = new FileWriter(stateFile);
        try {
            fw.write(Boolean.toString(state));
            fw.flush();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {}
            }
        }