Mercurial Hosting > luan
diff src/luan/modules/http/LuanHandler.java @ 1578:c922446f53aa
immutable threading
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 08 Feb 2021 14:16:19 -0700 |
parents | 8fbcc4747091 |
children | 2975c932864d |
line wrap: on
line diff
--- a/src/luan/modules/http/LuanHandler.java Sun Jan 31 16:04:39 2021 -0700 +++ b/src/luan/modules/http/LuanHandler.java Mon Feb 08 14:16:19 2021 -0700 @@ -27,7 +27,6 @@ import luan.LuanTable; import luan.LuanFunction; import luan.LuanJavaFunction; -import luan.LuanCloner; import luan.LuanException; import luan.modules.PackageLuan; import luan.modules.BasicLuan; @@ -87,8 +86,7 @@ private Luan newLuan() { Luan luan; synchronized(luanInit) { - LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); - luan = (Luan)cloner.clone(luanInit); + luan = new Luan(luanInit); } LuanLogger.startThreadLogging(luan); try { @@ -138,20 +136,19 @@ //logger.info("close "+domain+" "+(obj!=null)); } - public Object call_rpc(Luan luan,String fnName,Object... args) throws LuanException { + public Object call_rpc(String fnName,Object... args) throws LuanException { rwLock.readLock().lock(); LuanLogger.startThreadLogging(currentLuan); try { LuanFunction fn; - synchronized(luanInit) { - enableLoad("luan:Rpc.luan"); + Luan luan; + synchronized(currentLuan) { LuanTable rpc = (LuanTable)currentLuan.require("luan:Rpc.luan"); - LuanTable fns = (LuanTable)rpc.get(luan,"functions"); - fn = (LuanFunction)fns.get(luan,fnName); + LuanTable fns = (LuanTable)rpc.get(currentLuan,"functions"); + fn = (LuanFunction)fns.get(currentLuan,fnName); if( fn == null ) throw new LuanException( "function not found: " + fnName ); - LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); - fn = (LuanFunction)cloner.get(fn); + luan = new Luan(currentLuan); } return fn.call(luan,args); } finally { @@ -185,13 +182,9 @@ } private void eval_in_root(String text) throws LuanException { - Luan luan; - synchronized(luanInit) { - LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); - luan = (Luan)cloner.clone(currentLuan); + synchronized(currentLuan) { + currentLuan.load(text,"<eval_in_root>",false,null).call(currentLuan); } - luan.load(text,"<eval_in_root>",false,null).call(luan); - currentLuan = luan; } private void dont_gc() { @@ -249,11 +242,10 @@ private Response handleError(Request request,LuanException e) throws LuanException { -//e.printStackTrace(); + //e.printStackTrace(); Luan luan; - synchronized(luanInit) { - LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); - luan = (Luan)cloner.clone(currentLuan); + synchronized(currentLuan) { + luan = new Luan(currentLuan); } LuanTable module = (LuanTable)luan.require("luan:http/Http.luan"); return (Response)module.fn("handle_error").call( luan, request, e.table(luan) ); @@ -265,17 +257,15 @@ String modName = "site:" + request.path +".luan"; LuanFunction fn; Luan luan; - synchronized(luanInit) { - enableLoad("luan:http/Http.luan",modName); + synchronized(currentLuan) { currentLuan.require("luan:http/Http.luan"); Object mod = PackageLuan.load(currentLuan,modName); if( mod.equals(Boolean.FALSE) ) return null; if( !(mod instanceof LuanFunction) ) throw new LuanException( "module '"+modName+"' must return a function" ); - LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); - luan = (Luan)cloner.clone(currentLuan); - fn = (LuanFunction)cloner.get(mod); + luan = new Luan(currentLuan); + fn = (LuanFunction)mod; } LuanTable module = (LuanTable)luan.require("luan:http/Http.luan"); module.fn("new_request").call(luan,request); @@ -289,15 +279,12 @@ { LuanFunction fn; Luan luan; - synchronized(luanInit) { - enableLoad("luan:http/Http.luan"); + synchronized(currentLuan) { LuanTable module = (LuanTable)currentLuan.require("luan:http/Http.luan"); fn = module.fn("not_found_handler"); if( fn == null ) return null; - LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL); - luan = (Luan)cloner.clone(currentLuan); - fn = (LuanFunction)cloner.get(fn); + luan = new Luan(currentLuan); } LuanTable module = (LuanTable)luan.require("luan:http/Http.luan"); module.fn("new_request").call(luan,request); @@ -309,15 +296,4 @@ return handled ? (Response)module.fn("finish").call(luan) : null; } - private void enableLoad(String... mods) throws LuanException { - LuanTable loaded = PackageLuan.loaded(currentLuan); - for( String mod : mods ) { - if( loaded.rawGet(mod) == null ) { - LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); - currentLuan = (Luan)cloner.clone(currentLuan); - break; - } - } - } - }