comparison src/luan/modules/http/LuanHandler.java @ 1767:9157e0d5936e

minor fix
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 06 Jun 2023 20:31:19 -0600
parents 8df0b80e715e
children
comparison
equal deleted inserted replaced
1766:8df0b80e715e 1767:9157e0d5936e
33 33
34 public final class LuanHandler implements Handler, Closeable { 34 public final class LuanHandler implements Handler, Closeable {
35 private static final Logger logger = LoggerFactory.getLogger(LuanHandler.class); 35 private static final Logger logger = LoggerFactory.getLogger(LuanHandler.class);
36 36
37 private final Luan luanInit; 37 private final Luan luanInit;
38 private final String domain; 38 public final String domain;
39 private final ReadWriteLock rwLock = new ReentrantReadWriteLock(); 39 private final ReadWriteLock rwLock = new ReentrantReadWriteLock();
40 private volatile Luan currentLuan; 40 private volatile Luan currentLuan;
41 private volatile boolean isDisabled = false; 41 private volatile boolean isDisabled = false;
42 private volatile boolean didInit; 42 private volatile boolean didInit;
43 private final List<Closeable> closeables = new ArrayList<Closeable>(); 43 private final List<Closeable> closeables = new ArrayList<Closeable>();
142 thread.setName(oldName); 142 thread.setName(oldName);
143 } 143 }
144 } 144 }
145 145
146 @Override public void close() { 146 @Override public void close() {
147 synchronized(currentLuan) { 147 synchronized(closeables) {
148 for( Closeable c : closeables ) { 148 for( Closeable c : closeables ) {
149 try { 149 try {
150 c.close(); 150 c.close();
151 } catch(IOException e) { 151 } catch(IOException e) {
152 logger.error(c.toString(),e); 152 logger.error(c.toString(),e);
153 } 153 }
154 } 154 }
155 closeables.clear();
155 } 156 }
156 } 157 }
157 158
158 public Object call_rpc(String fnName,Object... args) throws LuanException { 159 public Object call_rpc(String fnName,Object... args) throws LuanException {
159 rwLock.readLock().lock(); 160 rwLock.readLock().lock();
232 throw new LuanException("HTTP handler has been garbage collected"); 233 throw new LuanException("HTTP handler has been garbage collected");
233 return lh; 234 return lh;
234 } 235 }
235 236
236 @Override public void addCloseable(Closeable c) throws LuanException { 237 @Override public void addCloseable(Closeable c) throws LuanException {
237 lh().closeables.add(c); 238 List<Closeable> closeables = lh().closeables;
239 synchronized(closeables) {
240 closeables.add(c);
241 }
238 } 242 }
239 243
240 public void reset_luan() throws LuanException { 244 public void reset_luan() throws LuanException {
241 lh().reset_luan(); 245 lh().reset_luan();
242 } 246 }