changeset 1187:83c8a5a47f70

fixes for luanhost
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 22 Feb 2018 18:38:45 -0700
parents ef8cd42e23d5
children 9f5edbef3f55
files src/luan/host/Backup.java src/luan/host/WebHandler.java src/luan/host/run.luan src/luan/webserver/Server.java
diffstat 4 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/host/Backup.java	Wed Feb 21 21:50:20 2018 -0700
+++ b/src/luan/host/Backup.java	Thu Feb 22 18:38:45 2018 -0700
@@ -69,7 +69,7 @@
 				luceneInstances = (LuanTable)luan.eval(getLucenes);
 			}
 		} catch(LuanException e) {
-			throw new RuntimeException(e);
+			throw new RuntimeException(from.getName(),e);
 		}
 		for( Map.Entry entry : luceneInstances.rawIterable() ) {
 			LuanTable tbl = (LuanTable)entry.getKey();
@@ -106,6 +106,7 @@
 
 	public static void main(String[] args) throws Exception {
 		Log4j.initForConsole();
+		WebHandler.allowJavaFileName = args[2];
 		backup( new File(args[0]), new File(args[1]) );
 		System.exit(0);
 	}
--- a/src/luan/host/WebHandler.java	Wed Feb 21 21:50:20 2018 -0700
+++ b/src/luan/host/WebHandler.java	Thu Feb 22 18:38:45 2018 -0700
@@ -40,7 +40,6 @@
 	public static String allowJavaFileName = "allow_java";  // change for security
 	private static final Map<String,Site> siteMap = new HashMap<String,Site>();
 	private static String sitesDir = null;
-	public static Server server;
 
 	public static boolean isServing() {
 		return sitesDir != null;
--- a/src/luan/host/run.luan	Wed Feb 21 21:50:20 2018 -0700
+++ b/src/luan/host/run.luan	Thu Feb 22 18:38:45 2018 -0700
@@ -30,5 +30,4 @@
 handler = ContentTypeHandler.new(handler)
 handler = SafeHandler.new(handler)
 local server = Server.ForAddress.new("127.0.0.1",8080,handler)
-webHandler.server = server
 server.start()
--- a/src/luan/webserver/Server.java	Wed Feb 21 21:50:20 2018 -0700
+++ b/src/luan/webserver/Server.java	Thu Feb 22 18:38:45 2018 -0700
@@ -5,7 +5,7 @@
 import java.net.ServerSocket;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import org.slf4j.Logger;
@@ -17,7 +17,7 @@
 
 	public final int port;
 	public final Handler handler;
-	private static final ExecutorService exec = Executors.newCachedThreadPool();
+	public static final ThreadPoolExecutor threadPool = (ThreadPoolExecutor)Executors.newCachedThreadPool();
 
 	public Server(int port,Handler handler) {
 		this.port = port;
@@ -30,11 +30,11 @@
 
 	public synchronized void start() throws IOException {
 		final ServerSocket ss = newServerSocket();
-		exec.execute(new Runnable(){public void run() {
+		threadPool.execute(new Runnable(){public void run() {
 			try {
-				while(!exec.isShutdown()) {
+				while(!threadPool.isShutdown()) {
 					final Socket socket = ss.accept();
-					exec.execute(new Runnable(){public void run() {
+					threadPool.execute(new Runnable(){public void run() {
 						Connection.handle(Server.this,socket);
 					}});
 				}
@@ -47,8 +47,8 @@
 
 	public synchronized boolean stop(long timeoutSeconds) {
 		try {
-			exec.shutdownNow();
-			boolean stopped = exec.awaitTermination(timeoutSeconds,TimeUnit.SECONDS);
+			threadPool.shutdownNow();
+			boolean stopped = threadPool.awaitTermination(timeoutSeconds,TimeUnit.SECONDS);
 			if(stopped)
 				logger.info("stopped server on port "+port);
 			else