Mercurial Hosting > luan
comparison src/luan/modules/http/LuanHandler.java @ 1592:9303bacae890
remember init.luan exception
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 18 Mar 2021 23:52:49 -0600 |
parents | 2975c932864d |
children | 38894708bade |
comparison
equal
deleted
inserted
replaced
1591:85cd316f0cdb | 1592:9303bacae890 |
---|---|
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 | 47 |
47 private static final Method resetLuanMethod; | 48 private static final Method resetLuanMethod; |
48 private static final Method evalInRootMethod; | 49 private static final Method evalInRootMethod; |
49 private static final Method disableLuanMethod; | 50 private static final Method disableLuanMethod; |
50 private static final Method dontGcMethod; | 51 private static final Method dontGcMethod; |
73 } catch(LuanException e) { | 74 } catch(LuanException e) { |
74 throw new RuntimeException(e); | 75 throw new RuntimeException(e); |
75 } | 76 } |
76 if( domain != null ) | 77 if( domain != null ) |
77 logger.info("new "+domain); | 78 logger.info("new "+domain); |
78 currentLuan = newLuan(); | 79 newLuan(); |
79 } | 80 } |
80 | 81 |
81 protected void finalize() throws Throwable { | 82 protected void finalize() throws Throwable { |
82 if( domain != null ) | 83 if( domain != null ) |
83 logger.info("gc "+domain); | 84 logger.info("gc "+domain); |
84 } | 85 } |
85 | 86 |
86 private Luan newLuan() { | 87 private void newLuan() { |
87 Luan luan; | 88 Luan luan; |
88 synchronized(luanInit) { | 89 synchronized(luanInit) { |
89 luan = new Luan(luanInit); | 90 luan = new Luan(luanInit); |
90 } | 91 } |
92 initErr = null; | |
91 LuanLogger.startThreadLogging(luan); | 93 LuanLogger.startThreadLogging(luan); |
92 try { | 94 try { |
93 PackageLuan.load(luan,"site:/init.luan",null); | 95 PackageLuan.load(luan,"site:/init.luan",null); |
94 } catch(LuanException e) { | 96 } catch(LuanException e) { |
95 //e.printStackTrace(); | 97 //e.printStackTrace(); |
98 initErr = e; | |
96 String err = e.getLuanStackTraceString(); | 99 String err = e.getLuanStackTraceString(); |
97 logger.error(err); | 100 logger.error(err); |
98 } finally { | 101 } finally { |
99 LuanLogger.endThreadLogging(); | 102 LuanLogger.endThreadLogging(); |
100 } | 103 } |
101 return luan; | 104 currentLuan = luan; |
102 } | 105 } |
103 | 106 |
104 static final String NOT_FOUND = "luan-not-found"; | 107 static final String NOT_FOUND = "luan-not-found"; |
105 | 108 |
106 @Override public Response handle(Request request) { | 109 @Override public Response handle(Request request) { |
116 String oldName = thread.getName(); | 119 String oldName = thread.getName(); |
117 thread.setName(request.headers.get("host")+request.path); | 120 thread.setName(request.headers.get("host")+request.path); |
118 rwLock.readLock().lock(); | 121 rwLock.readLock().lock(); |
119 LuanLogger.startThreadLogging(currentLuan); | 122 LuanLogger.startThreadLogging(currentLuan); |
120 try { | 123 try { |
124 if( initErr != null ) | |
125 throw initErr; | |
121 return service(request,notFound); | 126 return service(request,notFound); |
122 } catch(LuanException e) { | 127 } catch(LuanException e) { |
123 String err = e.getLuanStackTraceString(); | 128 String err = e.getLuanStackTraceString(); |
124 logger.error(err+"\n"+request.rawHead.trim()+"\n"); | 129 logger.error(err+"\n"+request.rawHead.trim()+"\n"); |
125 String msg = "Internel Server Error\n\n" + err; | 130 String msg = "Internel Server Error\n\n" + err; |
168 private void reset_luan() { | 173 private void reset_luan() { |
169 new Thread() {public void run(){ | 174 new Thread() {public void run(){ |
170 rwLock.writeLock().lock(); | 175 rwLock.writeLock().lock(); |
171 try { | 176 try { |
172 close(); | 177 close(); |
173 currentLuan = newLuan(); | 178 newLuan(); |
174 } finally { | 179 } finally { |
175 rwLock.writeLock().unlock(); | 180 rwLock.writeLock().unlock(); |
176 } | 181 } |
177 }}.start(); | 182 }}.start(); |
178 } | 183 } |