comparison src/luan/modules/http/LuanHandler.java @ 1319:f7355714742f

add Http.disable_luan()
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 04 Feb 2019 02:04:54 -0700
parents 503bde9a7c80
children 307e76ccd0d6
comparison
equal deleted inserted replaced
1318:35a6a195819f 1319:f7355714742f
35 private final LuanState luanInit; 35 private final LuanState luanInit;
36 private final Logger logger; 36 private final Logger logger;
37 private final ReadWriteLock lock = new ReentrantReadWriteLock(); 37 private final ReadWriteLock lock = new ReentrantReadWriteLock();
38 private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>(); 38 private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>();
39 private volatile LuanState currentLuan; 39 private volatile LuanState currentLuan;
40 private volatile boolean isDisabled = false;
40 41
41 private static final Method resetLuanMethod; 42 private static final Method resetLuanMethod;
42 private static final Method evalInRootMethod; 43 private static final Method evalInRootMethod;
44 private static final Method disableLuanMethod;
43 static { 45 static {
44 try { 46 try {
45 resetLuanMethod = LuanHandler.class.getMethod( "reset_luan" ); 47 resetLuanMethod = LuanHandler.class.getMethod( "reset_luan" );
46 evalInRootMethod = LuanHandler.class.getMethod( "eval_in_root", String.class ); 48 evalInRootMethod = LuanHandler.class.getMethod( "eval_in_root", String.class );
49 disableLuanMethod = LuanHandler.class.getMethod( "disable_luan" );
47 } catch(NoSuchMethodException e) { 50 } catch(NoSuchMethodException e) {
48 throw new RuntimeException(e); 51 throw new RuntimeException(e);
49 } 52 }
50 } 53 }
51 54
56 logger = LoggerFactory.getLogger(loggerRoot+LuanHandler.class.getName()); 59 logger = LoggerFactory.getLogger(loggerRoot+LuanHandler.class.getName());
57 try { 60 try {
58 LuanTable Http = (LuanTable)luanInit.require("luan:http/Http.luan"); 61 LuanTable Http = (LuanTable)luanInit.require("luan:http/Http.luan");
59 Http.put( "reset_luan", new LuanJavaFunction(resetLuanMethod,this) ); 62 Http.put( "reset_luan", new LuanJavaFunction(resetLuanMethod,this) );
60 Http.put( "eval_in_root", new LuanJavaFunction(evalInRootMethod,this) ); 63 Http.put( "eval_in_root", new LuanJavaFunction(evalInRootMethod,this) );
64 Http.put( "disable_luan", new LuanJavaFunction(disableLuanMethod,this) );
61 } catch(LuanException e) { 65 } catch(LuanException e) {
62 throw new RuntimeException(e); 66 throw new RuntimeException(e);
63 } 67 }
64 currentLuan = newLuan(); 68 currentLuan = newLuan();
65 } 69 }
81 public LuanState getLuan() { 85 public LuanState getLuan() {
82 return luan; 86 return luan;
83 } 87 }
84 */ 88 */
85 @Override public Response handle(Request request) { 89 @Override public Response handle(Request request) {
90 if( isDisabled )
91 return null;
86 if( request.path.endsWith("/") ) 92 if( request.path.endsWith("/") )
87 return null; 93 return null;
88 String modName = "site:" + request.path +".luan"; 94 String modName = "site:" + request.path +".luan";
89 return handle(request,modName); 95 return handle(request,modName);
90 } 96 }
163 } 169 }
164 } 170 }
165 }.start(); 171 }.start();
166 } 172 }
167 173
174 public void disable_luan() {
175 isDisabled = true;
176 }
177
168 public Object runLuan(String sourceText,String sourceName) throws LuanException { 178 public Object runLuan(String sourceText,String sourceName) throws LuanException {
169 lock.readLock().lock(); 179 lock.readLock().lock();
170 try { 180 try {
171 LuanFunction fn = Luan.load(sourceText,sourceName); 181 LuanFunction fn = Luan.load(sourceText,sourceName);
172 LuanState luan = currentLuan; 182 LuanState luan = currentLuan;