diff src/luan/modules/http/LuanHandler.java @ 1400:221eedb0f54e

fix inner class gc bug
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 13 Sep 2019 05:05:51 -0600
parents 0dc9837c16be
children ef1620aa99cb
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java	Wed Sep 11 16:28:38 2019 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Fri Sep 13 05:05:51 2019 -0600
@@ -13,6 +13,7 @@
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import luan.lib.logging.Logger;
+import luan.lib.logging.LoggerFactory;
 import luan.lib.webserver.Request;
 import luan.lib.webserver.Response;
 import luan.lib.webserver.Status;
@@ -31,8 +32,11 @@
 
 
 public final class LuanHandler implements Handler, Luan.OnClose {
+	private static final Logger sysLogger = LoggerFactory.getLogger(LuanHandler.class);
+
 	private final Luan luanInit;
-	private final Logger logger;
+	private final String domain;
+	private final Logger luanLogger;
 	private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
 	private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>();
 	private volatile Luan currentLuan;
@@ -51,9 +55,10 @@
 		}
 	}
 
-	public LuanHandler(Luan luanInit) {
+	public LuanHandler(Luan luanInit,String domain) {
 		this.luanInit = luanInit;
-		this.logger = LuanLogger.getLogger(luanInit,LuanHandler.class.getName());
+		this.domain = domain;
+		this.luanLogger = luanInit.getLogger(LuanHandler.class);
 		try {
 			LuanTable Http = (LuanTable)luanInit.require("luan:http/Http.luan");
 			if( Http.get("reset_luan") == null )
@@ -64,6 +69,11 @@
 			throw new RuntimeException(e);
 		}
 		currentLuan = newLuan();
+		sysLogger.info("new "+domain);
+	}
+
+	protected void finalize() throws Throwable {
+		sysLogger.info("gc  "+domain);
 	}
 
 	private Luan newLuan() {
@@ -78,7 +88,7 @@
 		} catch(LuanException e) {
 			//e.printStackTrace();
 			String err = e.getLuanStackTraceString();
-			logger.error(err);
+			luanLogger.error(err);
 		}
 		return luan;
 	}
@@ -107,7 +117,7 @@
 			return service(request,notFound);
 		} catch(LuanException e) {
 			String err = e.getLuanStackTraceString();
-			logger.error(err+"\n"+request.rawHead.trim()+"\n");
+			luanLogger.error(err+"\n"+request.rawHead.trim()+"\n");
 			String msg = "Internel Server Error\n\n" + err;
 			return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg );
 		} finally {
@@ -130,7 +140,7 @@
 					try {
 						c.close();
 					} catch(IOException e) {
-						logger.error(c.toString(),e);
+						luanLogger.error(c.toString(),e);
 					}
 				}
 			}