The following example demonstrates how to install a ShutdownListener object for the ServerContext instance:
class MyShutdownListener implements ShutdownListener {
FileOutputStream _outFile;
public MyShutdownListener(FileOutputStream outFile) {
_outFile = outFile;
}
public void shutdownPerformed(ServerContext sc) {
// Add shutdown code
try {
_outFile.write(("Shutting Down" + "\n").getBytes());
_outFile.flush();
}
catch(Exception e) {
// Print some error output to the MobiLink log.
e.printStackTrace();
}
// ...
}
}
The following code registers a MyShutdownListener object. Call this code from anywhere that has access to the ServerContext such as a class constructor or synchronization script.