changeset 527:ef0336efe33c

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 27 May 2015 03:29:04 -0600
parents f24d824e9fe5
children a24abf172f8f
files core/src/luan/LuanState.java lucene/src/luan/modules/lucene/LuceneIndex.java
diffstat 2 files changed, 13 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
diff -r f24d824e9fe5 -r ef0336efe33c core/src/luan/LuanState.java
--- a/core/src/luan/LuanState.java	Wed May 27 03:20:38 2015 -0600
+++ b/core/src/luan/LuanState.java	Wed May 27 03:29:04 2015 -0600
@@ -1,5 +1,7 @@
 package luan;
 
+import java.io.Closeable;
+import java.io.IOException;
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
 import java.util.List;
@@ -15,7 +17,7 @@
 	final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>();
 
 	private Map registry;
-	private final List<Reference<Runnable>> onClose = new ArrayList<Reference<Runnable>>();
+	private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>();
 
 	protected LuanState() {
 		registry = new HashMap();
@@ -35,15 +37,15 @@
 		return registry;
 	}
 
-	public void onClose(Runnable fn) {
-		onClose.add(new WeakReference<Runnable>(fn));
+	public void onClose(Closeable c) {
+		onClose.add(new WeakReference<Closeable>(c));
 	}
 
-	public void close() {
-		for( Reference<Runnable> ref : onClose ) {
-			Runnable r = ref.get();
-			if( r != null )
-				r.run();
+	public void close() throws IOException {
+		for( Reference<Closeable> ref : onClose ) {
+			Closeable c = ref.get();
+			if( c != null )
+				c.close();
 		}
 		onClose.clear();
 	}
diff -r f24d824e9fe5 -r ef0336efe33c lucene/src/luan/modules/lucene/LuceneIndex.java
--- a/lucene/src/luan/modules/lucene/LuceneIndex.java	Wed May 27 03:20:38 2015 -0600
+++ b/lucene/src/luan/modules/lucene/LuceneIndex.java	Wed May 27 03:29:04 2015 -0600
@@ -1,5 +1,6 @@
 package luan.modules.lucene;
 
+import java.io.Closeable;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileInputStream;
@@ -35,7 +36,7 @@
 import org.slf4j.LoggerFactory;
 
 
-public final class LuceneIndex {
+public final class LuceneIndex implements Closeable {
 	private static final Logger logger = LoggerFactory.getLogger(LuceneIndex.class);
 
 	private static final String FLD_NEXT_ID = "nextId";
@@ -48,7 +49,6 @@
 	private LuceneSearcher searcher;
 	public final FieldTable fields = new FieldTable();
 	private boolean isClosed = false;
-	private final Runnable closer;
 
 	public LuceneIndex(LuanState luan,String indexDirStr) throws LuanException, IOException {
 		File indexDir = new File(indexDirStr);
@@ -62,14 +62,7 @@
 		writer = new IndexWriter(dir,conf);
 		writer.commit();  // commit index creation
 		reader = DirectoryReader.open(dir);
-		closer = new Runnable(){public void run(){
-			try {
-				close();
-			} catch(IOException e) {
-				logger.error("",e);
-			}
-		}};
-		luan.onClose(closer);
+		luan.onClose(this);
 		searcher = new LuceneSearcher(this,reader);
 		initId(luan);
 	}