Interface RollbackHandler
-
public interface RollbackHandler
This interface allows a rollback behaviors to be defined for custom code action.. Rollback handler must attempt to roll back the system to a previous state, and it must only try to roll back those items that have been installed by the associated custom code action. However, there might be cases in which one custom code action is implemented with the only purpose of providing a handler that will roll back all the custom code actions that will follow during the install. That would be the case when there is no source code available to change a custom code action in order to make it support its own rollback.
When an custom code action implements
RollbackHandler
interface, the action will be automatically registered and will be called when rollback is triggered. This is an example of howRollbackHandler
is implemented:
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.zerog.ia.api.pub.CustomCodeAction;
import com.zerog.ia.api.pub.FatalInstallException;
import com.zerog.ia.api.pub.InstallException;
import com.zerog.ia.api.pub.InstallerProxy;
import com.zerog.ia.api.pub.RollbackHandler;
import com.zerog.ia.api.pub.RollbackRegister;
import com.zerog.ia.api.pub.UninstallerProxy;
public class RollbackAction extends CustomCodeAction implements RollbackHandler{
private static final String FILE_NAME = "installed-file.txt";
public void install(InstallerProxy proxy) throws InstallException {
installFile(proxy);
}
private void installFile(InstallerProxy proxy) throws FatalInstallException {
String installDir = proxy.substitute("$USER_INSTALL_DIR$");
try {
FileOutputStream stream = new FileOutputStream(new File(installDir,
FILE_NAME));
try {
stream.write("contents".getBytes("UTF-8"));
} finally {
stream.close();
}
} catch (IOException e) {
throw new FatalInstallException(e.getMessage());
}
}
public void rollBack(InstallerProxy proxy) throws InstallException {
String installDir = proxy.substitute("$USER_INSTALL_DIR$");
File installedFile = new File(installDir, FILE_NAME);
if (installedFile.exists()) {
installedFile.delete();
}
}
// TODO Add other required methods
}
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
rollBack(InstallerProxy installer)
This method is called when rollback of the installer is trigger.
-
-
-
Method Detail
-
rollBack
void rollBack(InstallerProxy installer) throws InstallException
This method is called when rollback of the installer is trigger. Custom code author needs to define this method to undo changes that were made during the install of the custom code action.- Parameters:
installer
- The installer proxy which contains public installer services.- Throws:
InstallException
-
-