1 17 package org.apache.geronimo.system.main; 18 19 import java.io.PrintStream ; 20 21 import org.apache.geronimo.kernel.Kernel; 22 import org.apache.geronimo.kernel.repository.Artifact; 23 import java.text.DateFormat ; 24 import java.text.SimpleDateFormat ; 25 import java.util.TimeZone ; 26 import java.util.Date ; 27 28 44 public class LongStartupMonitor implements StartupMonitor { 45 46 49 private PrintStream out; 50 51 54 private int numModules; 55 56 59 private int numModulesDigits; 60 61 64 private int moduleNum; 65 66 69 private int longestModuleNameLength; 70 71 74 private long started; 75 76 79 private long moduleStarted; 80 81 84 private Kernel kernel; 85 86 public synchronized void systemStarting(long startTime) { 87 out = System.out; 88 started = startTime; 89 } 90 91 public synchronized void systemStarted(Kernel kernel) { 92 this.kernel = kernel; 93 } 94 95 public synchronized void foundModules(Artifact[] modules) { 96 numModules = modules.length; 97 numModulesDigits = Integer.toString(numModules).length(); 98 99 for (int i = 0, len= 0; i < modules.length; i++) { 100 len = modules[i].toString().length(); 101 if (len > longestModuleNameLength) 102 longestModuleNameLength = len; 103 } 104 } 105 106 public synchronized void moduleLoading(Artifact module) { 107 StringBuffer buf = new StringBuffer ("Module "); 108 int configIndexDigits = Integer.toString(++moduleNum).length(); 110 for (; configIndexDigits < numModulesDigits; configIndexDigits++) { 111 buf.append(' '); 112 } 113 buf.append(moduleNum).append('/').append(numModules).append(' '); 115 buf.append(module); 117 int len = module.toString().length(); 119 for (; len < longestModuleNameLength; len++) { 120 buf.append(' '); 121 } 122 out.print(buf); 123 } 124 125 public synchronized void moduleLoaded(Artifact module) { 126 } 127 128 public synchronized void moduleStarting(Artifact module) { 129 moduleStarted = System.currentTimeMillis(); 130 } 131 132 public synchronized void moduleStarted(Artifact module) { 133 long time = System.currentTimeMillis() - moduleStarted; 134 StringBuffer buf = new StringBuffer (); 135 buf.append(" started in "); 136 137 String formattedTime = getFormattedTime(time); 138 if (formattedTime.startsWith("0.")) { 139 formattedTime = " " +formattedTime.substring(1); 141 } 142 143 int index = formattedTime.indexOf(':'); if (index == -1) 147 index = formattedTime.indexOf('.'); 148 149 if (index == 1) 150 buf.append(' '); 151 152 buf.append(formattedTime); 153 154 out.println(buf.toString()); 155 } 156 157 public synchronized void startupFinished() { 158 int time = Math.round((float) (System.currentTimeMillis() - started) / 1000f); 159 160 out.println("Startup completed in " + time + " seconds"); 161 StartupMonitorUtil.wrapUp(out, kernel); 162 } 163 164 public synchronized void serverStartFailed(Exception problem) { 165 out.println("Server Startup failed"); 166 out.println(); 167 problem.printStackTrace(out); 168 } 169 170 private static String getFormattedTime( long time ) 172 { 173 String pattern = "s.SSS's'"; 174 if ( time / 60000L > 0 ) 175 { 176 pattern = "m:s" + pattern; 177 if ( time / 3600000L > 0 ) 178 { 179 pattern = "H:m" + pattern; 180 } 181 } 182 DateFormat fmt = new SimpleDateFormat ( pattern ); 183 fmt.setTimeZone( TimeZone.getTimeZone( "UTC" ) ); 184 return fmt.format( new Date ( time ) ); 185 } 186 } 187 | Popular Tags |