Mercurial Hosting > luan
comparison src/luan/modules/http/LuanHandler.java @ 1615:38894708bade
better init.luan exception handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 03 Jun 2021 18:00:49 -0600 |
parents | 9303bacae890 |
children | a37ffe2d1b14 |
comparison
equal
deleted
inserted
replaced
1614:557bb90b70d7 | 1615:38894708bade |
---|---|
41 private final Luan luanInit; | 41 private final Luan luanInit; |
42 private final String domain; | 42 private final String domain; |
43 private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); | 43 private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); |
44 private volatile Luan currentLuan; | 44 private volatile Luan currentLuan; |
45 private volatile boolean isDisabled = false; | 45 private volatile boolean isDisabled = false; |
46 private volatile LuanException initErr; | 46 private volatile boolean didInit; |
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; |
82 protected void finalize() throws Throwable { | 82 protected void finalize() throws Throwable { |
83 if( domain != null ) | 83 if( domain != null ) |
84 logger.info("gc "+domain); | 84 logger.info("gc "+domain); |
85 } | 85 } |
86 | 86 |
87 private void init(Luan luan) throws LuanException { | |
88 if( didInit ) | |
89 return; | |
90 PackageLuan.load(luan,"site:/init.luan",null); | |
91 didInit = true; | |
92 } | |
93 | |
87 private void newLuan() { | 94 private void newLuan() { |
88 Luan luan; | 95 Luan luan; |
89 synchronized(luanInit) { | 96 synchronized(luanInit) { |
90 luan = new Luan(luanInit); | 97 luan = new Luan(luanInit); |
91 } | 98 } |
92 initErr = null; | 99 didInit = false; |
93 LuanLogger.startThreadLogging(luan); | 100 LuanLogger.startThreadLogging(luan); |
94 try { | 101 try { |
95 PackageLuan.load(luan,"site:/init.luan",null); | 102 init(luan); |
96 } catch(LuanException e) { | 103 } catch(LuanException e) { |
97 //e.printStackTrace(); | 104 //e.printStackTrace(); |
98 initErr = e; | |
99 String err = e.getLuanStackTraceString(); | 105 String err = e.getLuanStackTraceString(); |
100 logger.error(err); | 106 logger.error(err); |
101 } finally { | 107 } finally { |
102 LuanLogger.endThreadLogging(); | 108 LuanLogger.endThreadLogging(); |
103 } | 109 } |
119 String oldName = thread.getName(); | 125 String oldName = thread.getName(); |
120 thread.setName(request.headers.get("host")+request.path); | 126 thread.setName(request.headers.get("host")+request.path); |
121 rwLock.readLock().lock(); | 127 rwLock.readLock().lock(); |
122 LuanLogger.startThreadLogging(currentLuan); | 128 LuanLogger.startThreadLogging(currentLuan); |
123 try { | 129 try { |
124 if( initErr != null ) | 130 init(currentLuan); |
125 throw initErr; | |
126 return service(request,notFound); | 131 return service(request,notFound); |
127 } catch(LuanException e) { | 132 } catch(LuanException e) { |
128 String err = e.getLuanStackTraceString(); | 133 String err = e.getLuanStackTraceString(); |
134 //System.err.println(err); | |
129 logger.error(err+"\n"+request.rawHead.trim()+"\n"); | 135 logger.error(err+"\n"+request.rawHead.trim()+"\n"); |
130 String msg = "Internel Server Error\n\n" + err; | 136 String msg = "Internel Server Error\n\n" + err; |
131 return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg ); | 137 return Response.errorResponse( Status.INTERNAL_SERVER_ERROR, msg ); |
132 } finally { | 138 } finally { |
133 LuanLogger.endThreadLogging(); | 139 LuanLogger.endThreadLogging(); |