1 18 package freecs.core; 19 20 import java.util.Iterator ; 21 import freecs.*; 22 23 public class CleanupClass extends Thread { 24 25 public CleanupClass () { 26 } 27 28 public void run () { 29 this.setName("CleanupClass"); 30 Server.log (this, "starting to clean up", Server.MSG_STATE, Server.LVL_MAJOR); 31 Server.srv.startShutdown (); 32 MessageParser mpr = new MessageParser (); 33 mpr.setMessageTemplate ("message.server.shutdown"); 34 Server.log (this, "sending shutdownmessages...", Server.MSG_STATE, Server.LVL_MAJOR); 35 Server.log (this, "Logout users...", Server.MSG_STATE, Server.LVL_MAJOR); 36 UserManager.mgr.sendMessage(mpr); 37 Server.log (this, "Users logged out.", Server.MSG_STATE, Server.LVL_MAJOR); 38 Server.log (this, "Closing all connections...", Server.MSG_STATE, Server.LVL_MAJOR); 39 40 long killTime = System.currentTimeMillis() + 60000; 42 while (!CentralSelector.stopped) try { 43 if (killTime < System.currentTimeMillis()) { 44 Server.log (this, "CentralSelector didn't shutdown within 60000 millis", Server.MSG_STATE, Server.LVL_VERBOSE); 45 break; 46 } 47 System.out.print ("."); 48 Thread.sleep (1000); 49 } catch (InterruptedException ie) {} 50 synchronized (UserManager.mgr.ustr) { 51 for (Iterator i = UserManager.mgr.users (); i.hasNext (); ) try { 52 User u = (User) i.next (); 53 i.remove(); 54 u.removeNow(); 55 } catch (Exception e) { 56 Server.debug (this, "caused Exception while removing user: ", e, Server.MSG_STATE, Server.LVL_MAJOR); 57 } 58 } 59 Server.log (this, "Shutting down authentication", Server.MSG_STATE, Server.LVL_MAJOR); 60 try { 61 Server.srv.auth.shutdown (); 62 } catch (Exception e) { 63 Server.debug (this, "caused Exception while shutting down authentication: ", e, Server.MSG_STATE, Server.LVL_MAJOR); 64 } 65 Server.log (this, "Final cleanup done. Exiting JVM.", Server.MSG_STATE, Server.LVL_MAJOR); 66 } 67 68 public String toString () { 69 return "[CleanupClass]"; 70 } 71 } | Popular Tags |