浏览代码

BETA: Adding more server shutdown log messages and a nice feature that tracks down methods' execution time and overall server shutdown time.

Nik 13 年之前
父节点
当前提交
07bc6ec10b
共有 1 个文件被更改,包括 66 次插入9 次删除
  1. 66 9
      L2J_Server_BETA/java/com/l2jserver/gameserver/Shutdown.java

+ 66 - 9
L2J_Server_BETA/java/com/l2jserver/gameserver/Shutdown.java

@@ -210,10 +210,15 @@ public class Shutdown extends Thread
 	{
 		if (this == SingletonHolder._instance)
 		{
+			TimeCounter tc = new TimeCounter();
+			TimeCounter tc1 = new TimeCounter();
 			try
 			{
 				if ((Config.OFFLINE_TRADE_ENABLE || Config.OFFLINE_CRAFT_ENABLE) && Config.RESTORE_OFFLINERS)
+				{
 					OfflineTradersTable.storeOffliners();
+					_log.info("Offline Traders Table: Offline shops stored("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
+				}
 			}
 			catch (Throwable t)
 			{
@@ -223,7 +228,7 @@ public class Shutdown extends Thread
 			try
 			{
 				disconnectAllCharacters();
-				_log.info("All players disconnected.");
+				_log.info("All players disconnected and saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			}
 			catch (Throwable t)
 			{
@@ -234,6 +239,7 @@ public class Shutdown extends Thread
 			try
 			{
 				GameTimeController.getInstance().stopTimer();
+				_log.info("Game Time Controller: Timer stopped("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			}
 			catch (Throwable t)
 			{
@@ -244,6 +250,7 @@ public class Shutdown extends Thread
 			try
 			{
 				ThreadPoolManager.getInstance().shutdown();
+				_log.info("Thread Pool Manager: Manager has been shut down("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			}
 			catch (Throwable t)
 			{
@@ -253,6 +260,7 @@ public class Shutdown extends Thread
 			try
 			{
 				CommunityServerThread.getInstance().interrupt();
+				_log.info("Community Server Thread: Thread interruped("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			}
 			catch (Throwable t)
 			{
@@ -262,6 +270,7 @@ public class Shutdown extends Thread
 			try
 			{
 				LoginServerThread.getInstance().interrupt();
+				_log.info("Login Server Thread: Thread interruped("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			}
 			catch (Throwable t)
 			{
@@ -270,11 +279,13 @@ public class Shutdown extends Thread
 			
 			// last byebye, save all data and quit this server
 			saveData();
+			tc.restartCounter();
 			
 			// saveData sends messages to exit players, so shutdown selector after it
 			try
 			{
 				GameServer.gameServer.getSelectorThread().shutdown();
+				_log.info("Game Server: Selector thread has been shut down("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			}
 			catch (Throwable t)
 			{
@@ -285,6 +296,7 @@ public class Shutdown extends Thread
 			try
 			{
 				L2DatabaseFactory.getInstance().shutdown();
+				_log.info("L2Database Factory: Database connection has been shut down("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			}
 			catch (Throwable t)
 			{
@@ -300,6 +312,8 @@ public class Shutdown extends Thread
 			{
 				Runtime.getRuntime().halt(0);
 			}
+			
+			_log.info("The server has been successfully shut down in "+tc1.getEstimatedTime()/1000+"seconds.");
 		}
 		else
 		{
@@ -515,49 +529,60 @@ public class Shutdown extends Thread
 		
 		/*if (Config.ACTIVATE_POSITION_RECORDER)
 			Universe.getInstance().implode(true);*/
-		
+		TimeCounter tc = new TimeCounter();
 		// Seven Signs data is now saved along with Festival data.
 		if (!SevenSigns.getInstance().isSealValidationPeriod())
+		{
 			SevenSignsFestival.getInstance().saveFestivalData(false);
+			_log.info("SevenSignsFestival: Festival data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
+		}
 		
 		// Save Seven Signs data before closing. :)
 		SevenSigns.getInstance().saveSevenSignsData();
+		_log.info("SevenSigns: Seven Signs data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		SevenSigns.getInstance().saveSevenSignsStatus();
+		_log.info("SevenSigns: Seven Signs status saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		
 		// Save all raidboss and GrandBoss status ^_^
 		RaidBossSpawnManager.getInstance().cleanUp();
-		_log.info("RaidBossSpawnManager: All raidboss info saved!!");
+		_log.info("RaidBossSpawnManager: All raidboss info saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		GrandBossManager.getInstance().cleanUp();
-		_log.info("GrandBossManager: All Grand Boss info saved!!");
+		_log.info("GrandBossManager: All Grand Boss info saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		_log.info("TradeController saving data.. This action may take some minutes! Please wait until completed!");
 		TradeController.getInstance().dataCountStore();
-		_log.info("TradeController: All count Item Saved");
+		_log.info("TradeController: All count Item saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		ItemAuctionManager.getInstance().shutdown();
+		_log.info("Item Auction Manager: All tasks stopped("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		Olympiad.getInstance().saveOlympiadStatus();
-		_log.info("Olympiad System: Data saved!!");
+		_log.info("Olympiad System: Data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		Hero.getInstance().shutdown();
-		_log.info("Hero System: Data saved!!");
+		_log.info("Hero System: Data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		ClanTable.getInstance().storeClanScore();
-		_log.info("Clan System: Data saved!!");
+		_log.info("Clan System: Data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		
 		// Save Cursed Weapons data before closing.
 		CursedWeaponsManager.getInstance().saveData();
+		_log.info("Cursed Weapons Manager: Data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		
 		// Save all manor data
 		CastleManorManager.getInstance().save();
+		_log.info("Castle Manor Manager: Data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		
 		// Save all global (non-player specific) Quest data that needs to persist after reboot
 		QuestManager.getInstance().save();
+		_log.info("Quest Manager: Data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		
 		// Save all global variables data
 		GlobalVariablesManager.getInstance().saveVars();
+		_log.info("Global Variables Manager: Variables saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		
 		//Save items on ground before closing
 		if (Config.SAVE_DROPPED_ITEM)
 		{
 			ItemsOnGroundManager.getInstance().saveInDb();
+			_log.info("Items On Ground Manager: Data saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 			ItemsOnGroundManager.getInstance().cleanUp();
-			_log.info("ItemsOnGroundManager: All items on ground saved!!");
+			_log.info("Items On Ground Manager: Cleaned up("+tc.getEstimatedTimeAndRestartCounter()+"ms).");
 		}
 		
 		try
@@ -608,6 +633,38 @@ public class Shutdown extends Thread
 		}
 	}
 	
+	/**
+	 * A simple class used to track down the estimated time of method executions.
+	 * Once this class is created, it saves the start time, and when you want to get
+	 * the estimated time, use the getEstimatedTime() method.
+	 */
+	private static final class TimeCounter
+	{
+		private long _startTime;
+		
+		private TimeCounter()
+		{
+			restartCounter();
+		}
+		
+		private void restartCounter()
+		{
+			_startTime = System.currentTimeMillis();
+		}
+		
+		private long getEstimatedTimeAndRestartCounter()
+		{
+			final long toReturn = System.currentTimeMillis() - _startTime;
+			restartCounter();
+			return toReturn;
+		}
+		
+		private long getEstimatedTime()
+		{
+			return System.currentTimeMillis() - _startTime;
+		}
+	}
+	
 	@SuppressWarnings("synthetic-access")
 	private static class SingletonHolder
 	{