Mercurial Hosting > luan
comparison src/luan/modules/http/LuanDomainHandler.java @ 1685:46cf5137cb6b
misc fixes
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 08 Jun 2022 20:13:54 -0600 |
parents | c922446f53aa |
children | 357daf580951 |
comparison
equal
deleted
inserted
replaced
1684:cfbecf7af56f | 1685:46cf5137cb6b |
---|---|
6 import goodjava.webserver.handlers.DomainHandler; | 6 import goodjava.webserver.handlers.DomainHandler; |
7 import luan.Luan; | 7 import luan.Luan; |
8 import luan.LuanTable; | 8 import luan.LuanTable; |
9 import luan.LuanFunction; | 9 import luan.LuanFunction; |
10 import luan.LuanException; | 10 import luan.LuanException; |
11 import luan.LuanRuntimeException; | |
11 import luan.modules.logging.LuanLogger; | 12 import luan.modules.logging.LuanLogger; |
12 | 13 |
13 | 14 |
14 public class LuanDomainHandler implements Handler, DomainHandler.Factory { | 15 public class LuanDomainHandler implements Handler, DomainHandler.Factory { |
16 private final DomainHandler domainHandler = new DomainHandler(this); | |
17 private final LuanFunction init; | |
15 | 18 |
16 private final Luan luanInit; | 19 public LuanDomainHandler(LuanFunction init) throws LuanException { |
17 private final DomainHandler domainHandler = new DomainHandler(this); | 20 if(init==null) throw new NullPointerException("init required"); |
18 | |
19 public LuanDomainHandler(Luan luanInit) { | |
20 LuanLogger.initThreadLogging(); | 21 LuanLogger.initThreadLogging(); |
21 this.luanInit = new Luan(luanInit); | 22 this.init = init; |
22 } | 23 } |
23 | 24 |
24 @Override public Handler newHandler(String domain) { | 25 @Override public Handler newHandler(String domain) { |
25 Luan luan = newLuan(domain); | 26 Luan luan = newLuan(domain); |
26 return new LuanHandler(luan,domain); | 27 return new LuanHandler(luan,domain); |
27 } | 28 } |
28 | 29 |
29 protected Luan newLuan(final String domain) { | 30 protected Luan newLuan(final String domain) { |
30 Luan luan = new Luan(luanInit); | |
31 LuanFunction reset_luan = new LuanFunction() { | |
32 @Override public Object call(Luan luan,Object[] args) { | |
33 domainHandler.removeHandler(domain); | |
34 return LuanFunction.NOTHING; | |
35 } | |
36 }; | |
37 try { | 31 try { |
32 Luan luan = new Luan(); | |
33 init.call(luan); | |
34 LuanFunction reset_luan = new LuanFunction() { | |
35 @Override public Object call(Luan luan,Object[] args) { | |
36 domainHandler.removeHandler(domain); | |
37 return LuanFunction.NOTHING; | |
38 } | |
39 }; | |
38 LuanTable Http = (LuanTable)luan.require("luan:http/Http.luan"); | 40 LuanTable Http = (LuanTable)luan.require("luan:http/Http.luan"); |
39 Http.put( luan, "domain", domain ); | 41 Http.put( luan, "domain", domain ); |
40 Http.put( luan, "reset_luan", reset_luan ); | 42 Http.put( luan, "reset_luan", reset_luan ); |
43 return luan; | |
41 } catch(LuanException e) { | 44 } catch(LuanException e) { |
42 throw new RuntimeException(e); | 45 throw new LuanRuntimeException(e); |
43 } | 46 } |
44 return luan; | |
45 } | 47 } |
46 | 48 |
47 @Override public Response handle(Request request) { | 49 @Override public Response handle(Request request) { |
48 return domainHandler.handle(request); | 50 return domainHandler.handle(request); |
49 } | 51 } |