comparison src/luan/modules/http/LuanHandler.java @ 1692:d6ec67fa4a61

tools for config files
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 14 Jun 2022 21:59:39 -0600
parents 5c676385284b
children 8df0b80e715e
comparison
equal deleted inserted replaced
1691:8d4152398825 1692:d6ec67fa4a61
47 47
48 private static final Method resetLuanMethod; 48 private static final Method resetLuanMethod;
49 private static final Method evalInRootMethod; 49 private static final Method evalInRootMethod;
50 private static final Method disableLuanMethod; 50 private static final Method disableLuanMethod;
51 private static final Method dontGcMethod; 51 private static final Method dontGcMethod;
52 private static final Method testAsInitMethod;
52 static { 53 static {
53 try { 54 try {
54 resetLuanMethod = LuanHandler.Fns.class.getMethod( "reset_luan" ); 55 resetLuanMethod = LuanHandler.Fns.class.getMethod( "reset_luan" );
55 evalInRootMethod = LuanHandler.Fns.class.getMethod( "eval_in_root", String.class ); 56 evalInRootMethod = LuanHandler.Fns.class.getMethod( "eval_in_root", String.class );
56 disableLuanMethod = LuanHandler.Fns.class.getMethod( "disable_luan" ); 57 disableLuanMethod = LuanHandler.Fns.class.getMethod( "disable_luan" );
57 dontGcMethod = LuanHandler.Fns.class.getMethod( "dont_gc" ); 58 dontGcMethod = LuanHandler.Fns.class.getMethod( "dont_gc" );
59 testAsInitMethod = LuanHandler.Fns.class.getMethod( "test_as_init", String.class, String.class );
58 } catch(NoSuchMethodException e) { 60 } catch(NoSuchMethodException e) {
59 throw new RuntimeException(e); 61 throw new RuntimeException(e);
60 } 62 }
61 } 63 }
62 64
69 if( Http.get(luanInit,"reset_luan") == null ) 71 if( Http.get(luanInit,"reset_luan") == null )
70 Http.put( luanInit, "reset_luan", new LuanJavaFunction(resetLuanMethod,fns) ); 72 Http.put( luanInit, "reset_luan", new LuanJavaFunction(resetLuanMethod,fns) );
71 Http.put( luanInit, "eval_in_root", new LuanJavaFunction(evalInRootMethod,fns) ); 73 Http.put( luanInit, "eval_in_root", new LuanJavaFunction(evalInRootMethod,fns) );
72 Http.put( luanInit, "disable_luan", new LuanJavaFunction(disableLuanMethod,fns) ); 74 Http.put( luanInit, "disable_luan", new LuanJavaFunction(disableLuanMethod,fns) );
73 Http.put( luanInit, "dont_gc", new LuanJavaFunction(dontGcMethod,fns) ); 75 Http.put( luanInit, "dont_gc", new LuanJavaFunction(dontGcMethod,fns) );
76 Http.put( luanInit, "test_as_init", new LuanJavaFunction(testAsInitMethod,fns) );
74 } catch(LuanException e) { 77 } catch(LuanException e) {
75 throw new RuntimeException(e); 78 throw new RuntimeException(e);
76 } 79 }
77 if( domain != null ) 80 if( domain != null )
78 logger.info("new "+domain); 81 logger.info("new "+domain);
167 LuanLogger.endThreadLogging(); 170 LuanLogger.endThreadLogging();
168 rwLock.readLock().unlock(); 171 rwLock.readLock().unlock();
169 } 172 }
170 } 173 }
171 174
175 private void test_as_init(String text,String sourceName) throws LuanException {
176 Luan luan;
177 synchronized(luanInit) {
178 luan = new Luan(luanInit);
179 }
180 LuanLogger.startThreadLogging(luan);
181 try {
182 luan.load(text,sourceName,false,null).call(luan);
183 } finally {
184 LuanLogger.endThreadLogging();
185 }
186 }
187
172 public static void start(Server server) throws Exception { 188 public static void start(Server server) throws Exception {
173 try { 189 try {
174 server.start(); 190 server.start();
175 } catch(BindException e) { 191 } catch(BindException e) {
176 throw new LuanException(e.toString()); 192 throw new LuanException(e.toString());
231 } 247 }
232 248
233 public void dont_gc() throws LuanException { 249 public void dont_gc() throws LuanException {
234 lh().dont_gc(); 250 lh().dont_gc();
235 } 251 }
252
253 public void test_as_init(String text,String sourceName) throws LuanException {
254 lh().test_as_init(text,sourceName);
255 }
236 } 256 }
237 257
238 258
239 // from HttpServicer 259 // from HttpServicer
240 260