Mercurial Hosting > luan
comparison src/luan/host/WebHandler.java @ 1264:d41997776788
fix onClose issues
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 25 Sep 2018 17:03:57 -0600 |
parents | 382c444a6c77 |
children | 51a1987b55a3 |
comparison
equal
deleted
inserted
replaced
1263:382c444a6c77 | 1264:d41997776788 |
---|---|
30 | 30 |
31 public class WebHandler implements Handler { | 31 public class WebHandler implements Handler { |
32 private static final Logger logger = LoggerFactory.getLogger(WebHandler.class); | 32 private static final Logger logger = LoggerFactory.getLogger(WebHandler.class); |
33 | 33 |
34 private static class LuanRef { | 34 private static class LuanRef { |
35 private final LuanState luan; | |
36 private final Handler handler; | 35 private final Handler handler; |
37 private final LuanHandler luanHandler; | 36 private final LuanHandler luanHandler; |
38 | 37 |
39 private LuanRef(LuanState luan,Handler handler,LuanHandler luanHandler) { | 38 private LuanRef(Handler handler,LuanHandler luanHandler) { |
40 this.luan = luan; | |
41 this.handler = handler; | 39 this.handler = handler; |
42 this.luanHandler = luanHandler; | 40 this.luanHandler = luanHandler; |
43 } | 41 } |
44 } | 42 } |
45 | 43 |
46 private static final ReferenceQueue<LuanRef> queue = new ReferenceQueue<LuanRef>(); | 44 private static final ReferenceQueue<LuanRef> queue = new ReferenceQueue<LuanRef>(); |
47 | 45 |
48 private static class MyReference extends SoftReference<LuanRef> { | 46 private static class MyReference extends SoftReference<LuanRef> { |
49 private LuanState luan; | 47 private LuanHandler luanHandler; |
50 | 48 |
51 private MyReference(LuanRef lr) { | 49 private MyReference(LuanRef lr) { |
52 super(lr,queue); | 50 super(lr,queue); |
53 this.luan = lr.luan; | 51 this.luanHandler = lr.luanHandler; |
54 } | 52 } |
55 } | 53 } |
56 | 54 |
57 private static void sweep() { | 55 private static void sweep() { |
58 while(true) { | 56 while(true) { |
59 MyReference ref = (MyReference)queue.poll(); | 57 MyReference ref = (MyReference)queue.poll(); |
60 if( ref == null ) | 58 if( ref == null ) |
61 return; | 59 return; |
62 //logger.info("sweep"); | 60 //logger.info("sweep"); |
63 ref.luan.close(); | 61 ref.luanHandler.close(); |
64 ref.luan = null; | 62 ref.luanHandler = null; |
65 } | 63 } |
66 } | 64 } |
67 | 65 |
68 | 66 |
69 public static String allowJavaFileName = "allow_java"; // change for security | 67 public static String allowJavaFileName = "allow_java"; // change for security |
173 handler = new ListHandler( handler, notFoundHandler ); | 171 handler = new ListHandler( handler, notFoundHandler ); |
174 | 172 |
175 String logDir = dir + "/site/private/local/logs/web"; | 173 String logDir = dir + "/site/private/local/logs/web"; |
176 new File(logDir).mkdirs(); | 174 new File(logDir).mkdirs(); |
177 | 175 |
178 return new LuanRef(luan,handler,luanHandler); | 176 return new LuanRef(handler,luanHandler); |
179 } | 177 } |
180 | 178 |
181 public static void removeHandler(String domain) throws Exception { | 179 public static void removeHandler(String domain) throws Exception { |
182 synchronized(siteMap) { | 180 synchronized(siteMap) { |
183 Reference<LuanRef> ref = siteMap.remove(domain); | 181 Reference<LuanRef> ref = siteMap.remove(domain); |
184 LuanRef lr = ref==null ? null : ref.get(); | 182 LuanRef lr = ref==null ? null : ref.get(); |
185 if( lr != null ) { | 183 if( lr != null ) { |
186 lr.luan.close(); | 184 lr.luanHandler.close(); |
187 } | 185 } |
188 } | 186 } |
189 } | 187 } |
190 | 188 |
191 public static void loadHandler(String domain) { | 189 public static void loadHandler(String domain) { |