offload start to a thread, display wait page while the tunnel is opening

pull/34/head
Zlatin Balevsky 2019-11-30 14:56:04 +00:00
parent 9151df6816
commit ff0a4661fd
5 changed files with 66 additions and 3 deletions

View File

@ -91,6 +91,7 @@ public class Core {
final EventBus eventBus
final Persona me
final String version;
final File home
final Properties i2pOptions
final MuWireSettings muOptions
@ -123,6 +124,7 @@ public class Core {
public Core(MuWireSettings props, File home, String myVersion) {
this.home = home
this.version = myVersion
this.muOptions = props
i2pOptions = new Properties()

View File

@ -0,0 +1,28 @@
package com.muwire.webui;
import java.io.File;
import com.muwire.core.Core;
import com.muwire.core.MuWireSettings;
class MWStarter extends Thread {
private final MuWireSettings settings;
private final File home;
private final String version;
private final MuWireClient client;
MWStarter(MuWireSettings settings, File home, String version, MuWireClient client) {
this.settings = settings;
this.home = home;
this.version = version;
this.client = client;
setName("MW starter");
setDaemon(true);
}
public void run() {
Core core = new Core(settings, home, version);
core.startServices();
client.setCore(core);
}
}

View File

@ -60,8 +60,8 @@ public class MuWireClient {
reader.close();
MuWireSettings settings = new MuWireSettings(props);
core = new Core(settings, new File(home), version);
core.startServices();
MWStarter starter = new MWStarter(settings, new File(home), version, this);
starter.start();
}
public void stop() throws Throwable {
@ -96,6 +96,10 @@ public class MuWireClient {
return core;
}
void setCore(Core core) {
this.core = core;
}
public String getHome() {
return home;
}

View File

@ -40,7 +40,11 @@ public class MuWireServlet extends HttpServlet {
resp.sendRedirect("/MuWire/MuWire.jsp");
} else {
resp.setContentType("text/html");
resp.getWriter().println("<html>MW is initialized</html>");
if (client.getCore() == null) {
resp.getWriter().println("<html>MW is initializing, please wait</html>");
resp.setIntHeader("Refresh", 5);
} else
resp.sendRedirect("/MuWire/Home.jsp");
}
}

View File

@ -0,0 +1,25 @@
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.io.File" %>
<%@ page import="com.muwire.webui.MuWireClient" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
MuWireClient client = (MuWireClient) session.getAttribute("mwClient");
String persona = client.getCore().getMe().getHumanReadableName();
String version = client.getCore().getVersion();
session.setAttribute("persona", persona);
session.setAttribute("version", version);
%>
<html>
<head>
<title>MuWire ${version}</title>
</head>
<body>
<p>Welcome to MuWire ${persona}</p>
</body>
</html>