提交 4b31585a 编写于 作者: K kohsuke

initialization is now performed outside the main thread to provide better UI...

initialization is now performed outside the main thread to provide better UI feedback during the initialization (#756)


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@4783 71c3de6d-444a-0410-be80-ed276b4c234a
上级 9151c497
...@@ -222,7 +222,7 @@ ...@@ -222,7 +222,7 @@
<dependency> <dependency>
<groupId>org.kohsuke.stapler</groupId> <groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler</artifactId> <artifactId>stapler</artifactId>
<version>1.42</version> <version>1.43</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.kohsuke</groupId> <groupId>org.kohsuke</groupId>
......
...@@ -6,11 +6,7 @@ import hudson.model.Hudson; ...@@ -6,11 +6,7 @@ import hudson.model.Hudson;
import hudson.model.User; import hudson.model.User;
import hudson.triggers.Trigger; import hudson.triggers.Trigger;
import hudson.triggers.SafeTimerTask; import hudson.triggers.SafeTimerTask;
import hudson.util.IncompatibleServletVersionDetected; import hudson.util.*;
import hudson.util.IncompatibleVMDetected;
import hudson.util.RingBufferLogHandler;
import hudson.util.NoHomeDir;
import hudson.util.InsufficientPermissionDetected;
import javax.naming.Context; import javax.naming.Context;
import javax.naming.InitialContext; import javax.naming.InitialContext;
...@@ -42,7 +38,7 @@ public class WebAppMain implements ServletContextListener { ...@@ -42,7 +38,7 @@ public class WebAppMain implements ServletContextListener {
* Creates the sole instance of {@link Hudson} and register it to the {@link ServletContext}. * Creates the sole instance of {@link Hudson} and register it to the {@link ServletContext}.
*/ */
public void contextInitialized(ServletContextEvent event) { public void contextInitialized(ServletContextEvent event) {
ServletContext context = event.getServletContext(); final ServletContext context = event.getServletContext();
// quick check to see if we (seem to) have enough permissions to run. (see #719) // quick check to see if we (seem to) have enough permissions to run. (see #719)
JVM jvm; JVM jvm;
...@@ -56,7 +52,7 @@ public class WebAppMain implements ServletContextListener { ...@@ -56,7 +52,7 @@ public class WebAppMain implements ServletContextListener {
installLogger(); installLogger();
File home = getHomeDir(event).getAbsoluteFile(); final File home = getHomeDir(event).getAbsoluteFile();
home.mkdirs(); home.mkdirs();
System.out.println("hudson home directory: "+home); System.out.println("hudson home directory: "+home);
...@@ -100,43 +96,47 @@ public class WebAppMain implements ServletContextListener { ...@@ -100,43 +96,47 @@ public class WebAppMain implements ServletContextListener {
} }
} }
context.setAttribute("app",new HudsonIsLoading());
try {
context.setAttribute("app",new Hudson(home,context)); new Thread("hudson initialization thread") {
} catch( IOException e ) { public void run() {
throw new Error(e); try {
} context.setAttribute("app",new Hudson(home,context));
} catch( IOException e ) {
// set the version throw new Error(e);
Properties props = new Properties(); }
try {
InputStream is = getClass().getResourceAsStream("hudson-version.properties"); // set the version
if(is!=null) Properties props = new Properties();
props.load(is); try {
} catch (IOException e) { InputStream is = getClass().getResourceAsStream("hudson-version.properties");
e.printStackTrace(); // if the version properties is missing, that's OK. if(is!=null)
} props.load(is);
String ver = props.getProperty("version"); } catch (IOException e) {
if(ver==null) ver="?"; e.printStackTrace(); // if the version properties is missing, that's OK.
Hudson.VERSION = ver; }
context.setAttribute("version",ver); String ver = props.getProperty("version");
if(ver==null) ver="?";
if(ver.equals("?")) Hudson.VERSION = ver;
Hudson.RESOURCE_PATH = ""; context.setAttribute("version",ver);
else
Hudson.RESOURCE_PATH = "/static/"+Util.getDigestOf(ver).substring(0,8); if(ver.equals("?"))
Hudson.RESOURCE_PATH = "";
Trigger.init(); // start running trigger else
Hudson.RESOURCE_PATH = "/static/"+Util.getDigestOf(ver).substring(0,8);
// trigger the loading of changelogs in the background,
// but give the system 10 seconds so that the first page Trigger.init(); // start running trigger
// can be served quickly
Trigger.timer.schedule(new SafeTimerTask() { // trigger the loading of changelogs in the background,
public void doRun() { // but give the system 10 seconds so that the first page
User.get("nobody").getBuilds(); // can be served quickly
Trigger.timer.schedule(new SafeTimerTask() {
public void doRun() {
User.get("nobody").getBuilds();
}
}, 1000*10);
} }
}, 1000*10); }.start();
} }
/** /**
......
...@@ -41,13 +41,7 @@ import hudson.tasks.Publisher; ...@@ -41,13 +41,7 @@ import hudson.tasks.Publisher;
import hudson.triggers.Trigger; import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor; import hudson.triggers.TriggerDescriptor;
import hudson.triggers.Triggers; import hudson.triggers.Triggers;
import hudson.util.ClockDifference; import hudson.util.*;
import hudson.util.CopyOnWriteList;
import hudson.util.CopyOnWriteMap;
import hudson.util.DaemonThreadFactory;
import hudson.util.FormFieldValidator;
import hudson.util.MultipartFormDataParser;
import hudson.util.XStream2;
import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
...@@ -1476,9 +1470,23 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node ...@@ -1476,9 +1470,23 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
if(!Hudson.adminCheck(req,rsp)) if(!Hudson.adminCheck(req,rsp))
return; return;
load(); // engage "loading ..." UI and then run the actual task in a separate thread
User.reload(); final ServletContext context = req.getServletContext();
context.setAttribute("app",new HudsonIsLoading());
rsp.sendRedirect2(req.getContextPath()+"/"); rsp.sendRedirect2(req.getContextPath()+"/");
new Thread("Hudson config reload thread") {
public void run() {
try {
load();
User.reload();
context.setAttribute("app",Hudson.this);
} catch (IOException e) {
LOGGER.log(Level.SEVERE,"Failed to reload Hudson config",e);
}
}
}.start();
} }
public boolean isPluginUploaded() { public boolean isPluginUploaded() {
......
package hudson.util;
import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import java.io.IOException;
/**
* Model object used to display "Hudson is loading data"
* @author Kohsuke Kawaguchi
*/
public class HudsonIsLoading {
public void doDynamic(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, InterruptedException {
rsp.setStatus(SC_SERVICE_UNAVAILABLE);
req.getView(this,"index.jelly").forward(req,rsp);
}
}
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout>
<l:header title="Hudson">
<!--meta http-equiv="refresh" content="5" /-->
</l:header>
<l:side-panel />
<l:main-panel>
<h1 style="margin-top:4em">Please wait while Hudson is getting ready to work<span id="progress">...</span></h1>
<p style="color:grey">
Your browser will reload automatically when Hudson is ready.
</p>
<script><![CDATA[
var i=0;
new PeriodicalExecuter(function() {
i = (i+1)%4;
var s = "";
for( var j=0; j<i; j++ )
s+='.';
$('progress').innerHTML = s;
},1000);
window.setTimeout(function() {
var statusChecker = arguments.callee;
new Ajax.Request(".", {
method: "get",
onFailure: function(rsp) {
if(transport.status==503) {
// redirect as long as we are still loading
window.setTimeout(statusChecker,5000);
} else {
window.location.reload();
}
},
onSuccess: function(rsp) {
window.location.reload();
}
});
}, 5000);
]]></script>
</l:main-panel>
</l:layout>
</j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册