Methods Summary |
---|
public static boolean | getState()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 getState(null);
|
public static boolean | getState(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.
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.File | getStateFile(java.lang.String instanceRoot)Returns the state file handle.
// 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 void | main(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 void | removeStateFile()Removes the restart required state file.
File state = getStateFile(null);
if (state.exists()) {
FileUtils.liquidate(state);
}
|
public static void | saveState(boolean state)Saves the restart required state of the server instance.
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) {}
}
}
|