提交 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 @@
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler</artifactId>
<version>1.42</version>
<version>1.43</version>
</dependency>
<dependency>
<groupId>org.kohsuke</groupId>
......
......@@ -6,11 +6,7 @@ import hudson.model.Hudson;
import hudson.model.User;
import hudson.triggers.Trigger;
import hudson.triggers.SafeTimerTask;
import hudson.util.IncompatibleServletVersionDetected;
import hudson.util.IncompatibleVMDetected;
import hudson.util.RingBufferLogHandler;
import hudson.util.NoHomeDir;
import hudson.util.InsufficientPermissionDetected;
import hudson.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
......@@ -42,7 +38,7 @@ public class WebAppMain implements ServletContextListener {
* Creates the sole instance of {@link Hudson} and register it to the {@link ServletContext}.
*/
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)
JVM jvm;
......@@ -56,7 +52,7 @@ public class WebAppMain implements ServletContextListener {
installLogger();
File home = getHomeDir(event).getAbsoluteFile();
final File home = getHomeDir(event).getAbsoluteFile();
home.mkdirs();
System.out.println("hudson home directory: "+home);
......@@ -100,7 +96,10 @@ public class WebAppMain implements ServletContextListener {
}
}
context.setAttribute("app",new HudsonIsLoading());
new Thread("hudson initialization thread") {
public void run() {
try {
context.setAttribute("app",new Hudson(home,context));
} catch( IOException e ) {
......@@ -136,7 +135,8 @@ public class WebAppMain implements ServletContextListener {
User.get("nobody").getBuilds();
}
}, 1000*10);
}
}.start();
}
/**
......
......@@ -41,13 +41,7 @@ import hudson.tasks.Publisher;
import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import hudson.triggers.Triggers;
import hudson.util.ClockDifference;
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 hudson.util.*;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
......@@ -1476,9 +1470,23 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
if(!Hudson.adminCheck(req,rsp))
return;
// engage "loading ..." UI and then run the actual task in a separate thread
final ServletContext context = req.getServletContext();
context.setAttribute("app",new HudsonIsLoading());
rsp.sendRedirect2(req.getContextPath()+"/");
new Thread("Hudson config reload thread") {
public void run() {
try {
load();
User.reload();
rsp.sendRedirect2(req.getContextPath()+"/");
context.setAttribute("app",Hudson.this);
} catch (IOException e) {
LOGGER.log(Level.SEVERE,"Failed to reload Hudson config",e);
}
}
}.start();
}
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.
先完成此消息的编辑!
想要评论请 注册