E. UWS Tools-Box

The class UWSToolBox gathers several usefull functions. All of them are static, so you don't need to create an instance of this class. Some of them have already been used in the previous sections of this tutorial:

Error tools

The both error publication functions use actually writeErrorFile(Exception error, String dirPath, String fileName, boolean overwrite) which only writes the stack trace of the given exception in the specified file. The second writeErrorFile function calls this one but with true as last parameter which means that if the specified file exists, it will be overwritten.

URL tools

In addition to the printURL methods, this class provides the following functions to manipulate more easily URLs:

Saving & Restoring a UWS

At each stop (or even during a simple restart) of Tomcat, the value of all class attributes are lost. Consequently all pending/running/stopped jobs are destroyed. To avoid this effect you can save the UWS in the destroy() function, by using saveUWS(AbstractUWs, File, boolean). Below is an example:

public void destroy() {
	// Save the current state of this UWS:
	UWSToolBox.saveUWS(uws, restoreFile, true);
	super.destroy();
}

To restore a UWS you just have to call restoreUWS(File, boolean) in the init(ServletConfig) function:

public void init(ServletConfig config) throws ServletException {
	// Restore the last saved UWS:
	restoreFile = new File(config.getServletContext().getRealPath("/"), "uwsRestore");
	uws = (BasicUWS<JobChrono>) UWSToolBox.restoreUWS(restoreFile, true);
	super.init(config);
}

Notes: