KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ShutDownThread


1
2 /** This thread is run when Whisper IM is shutdown unintenionally.
3 * Eg. The user shutsdown down the compute without quitting Whisper IM first.
4 * The thread attempts to wipe the keypair from memory and close the connection to the server.*/

5 public final class ShutDownThread extends Thread JavaDoc{
6     
7     private static final int ONE_MINUTE=1000;
8     
9     /** Creates a new ShutDownThread, which is run by the VM in case of shutdown.*/
10     public ShutDownThread(){
11         super("Shut Down Thread");
12     }
13     
14     public void run(){
15         try{
16             if(WhisperIM.MainWindow.intentionalQuit){
17                 return; // don't need to do anything
18
}
19             if(WhisperIM.KEYPAIR!=null){
20                 try{
21                     WhisperIM.KEYPAIR.privateKey().wipe();
22                     WhisperIM.KEYPAIR=null;
23                 }
24                 catch(Exception JavaDoc e1){
25                     //swallow
26
}
27             }
28             if(WhisperIM.MainWindow.keycachekey!=null){
29                 try{
30                     whisper.Util.wipe(WhisperIM.MainWindow.keycachekey);
31                 }
32                 catch(Exception JavaDoc e2){
33                     //swallow
34
}
35             }
36             if(WhisperIM.MainWindow.Conn!=null && WhisperIM.MainWindow.Conn.isConnected()){
37                 try{
38                     WhisperIM.MainWindow.Conn.close();
39                 }
40                 catch(Exception JavaDoc e3){
41                     //swallow
42
}
43             }
44             // try and sleep for 2 seconds to allow any file i/o to finish
45
try{
46                 sleep(2000);
47             }
48             catch(Exception JavaDoc e4){
49                 return;
50             }
51         }
52         catch(Throwable JavaDoc t){
53             return;
54         }
55     }
56 }
Popular Tags