changeset 1375:5c3702f60200

cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 11 Jul 2019 23:19:11 -0600
parents 72b699bad1a4
children ba1b4583c2d5
files src/luan/host/Backup.java src/luan/host/Log4j.java src/luan/host/WebHandler.java src/luan/modules/http/LuanHandler.java src/luan/modules/lucene/Lucene.luan
diffstat 5 files changed, 2 insertions(+), 187 deletions(-) [+]
line wrap: on
line diff
diff -r 72b699bad1a4 -r 5c3702f60200 src/luan/host/Backup.java
--- a/src/luan/host/Backup.java	Sun Jul 07 22:49:36 2019 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,134 +0,0 @@
-package luan.host;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-import luan.lib.logging.Logger;
-import luan.lib.logging.LoggerFactory;
-import org.apache.lucene.index.SnapshotDeletionPolicy;
-import org.apache.lucene.index.IndexCommit;
-import org.apache.lucene.store.FSDirectory;
-import luan.Luan;
-import luan.LuanTable;
-import luan.LuanException;
-import luan.modules.PackageLuan;
-import luan.modules.lucene.LuceneIndex;
-import luan.host.Log4j;
-
-
-public final class Backup {
-	private static final Logger logger = LoggerFactory.getLogger(Backup.class);
-
-	private Backup() {}  // never
-
-	private static void mkdir(File dir) {
-		if( !dir.mkdirs() )
-			throw new RuntimeException("couldn't make "+dir);
-	}
-
-	private static void link(File from,File to) throws IOException {
-		Files.createLink( to.toPath(), from.toPath() );
-	}
-
-	private static void backupNonlocal(File from,File to) throws IOException {
-		mkdir(to);
-		for( File fromChild : from.listFiles() ) {
-			File toChild = new File( to, fromChild.getName() );
-			if( fromChild.isDirectory() ) {
-				if( !fromChild.getName().equals("local") )
-					backupNonlocal( fromChild, toChild );
-			} else if( fromChild.isFile() ) {
-				link( fromChild, toChild );
-			} else {
-				throw new RuntimeException(fromChild+" isn't dir or file");
-			}
-		}
-	}
-
-	private static final String getLucenes =
-		"local Lucene = require 'luan:lucene/Lucene.luan'\n"
-		+"local Table = require 'luan:Table.luan'\n"
-		+"return Table.copy(Lucene.instances)\n"
-	;
-
-	private static void backupLucene(File from,File to) throws IOException {
-		if( !new File(from,"site/init.luan").exists() ) {
-			return;
-		}
-		String fromPath = from.getCanonicalPath() + "/";
-		LuanTable luceneInstances;
-		Luan luan = null;
-		try {
-			if( WebHandler.isServing() ) {
-				luceneInstances = (LuanTable)WebHandler.runLuan( from.getName(), getLucenes, "getLucenes" );
-			} else {
-				luan = new Luan();
-				luan.onClose = new Luan.OnClose() {
-					private final List<Closeable> onClose = new ArrayList<Closeable>();
-
-					public void onClose(Closeable c) {
-						onClose.add(c);
-					}
-				
-					public void close() {
-						for( Closeable c : onClose ) {
-							try {
-								c.close();
-							} catch(IOException e) {
-								logger.error(c.toString(),e);
-							}
-						}
-						onClose.clear();
-					}
-				};
-				WebHandler.initLuan( luan, from.toString(), from.getName(), false );
-				PackageLuan.load(luan,"site:/init.luan");
-				luceneInstances = (LuanTable)luan.eval(getLucenes);
-			}
-		} catch(LuanException e) {
-			throw new RuntimeException(from.getName(),e);
-		}
-		for( Map.Entry entry : luceneInstances.rawIterable() ) {
-			LuanTable tbl = (LuanTable)entry.getKey();
-			LuceneIndex li = (LuceneIndex)tbl.rawGet("java");
-			SnapshotDeletionPolicy snapshotDeletionPolicy = li.snapshotDeletionPolicy();
-			IndexCommit ic = snapshotDeletionPolicy.snapshot();
-			try {
-				FSDirectory fsdir = (FSDirectory)ic.getDirectory();
-				File dir = fsdir.getDirectory();
-				String dirPath = dir.toString();
-				if( !dirPath.startsWith(fromPath) )
-					throw new RuntimeException(fromPath+" "+dirPath);
-				File toDir = new File( to, dirPath.substring(fromPath.length()) );
-				mkdir(toDir);
-				for( String name : ic.getFileNames() ) {
-					link( new File(dir,name), new File(toDir,name) );
-				}
-			} finally {
-				snapshotDeletionPolicy.release(ic);
-			}
-		}
-		if( luan != null )
-			luan.onClose.close();
-	}
-
-	public static void backup(File sitesDir,File backupDir) throws IOException {
-		mkdir(backupDir);
-		for( File siteDir : sitesDir.listFiles() ) {
-			File to = new File( backupDir, siteDir.getName() );
-			backupNonlocal( siteDir, to );
-			backupLucene( siteDir, to );
-		}
-	}
-
-	public static void main(String[] args) throws Exception {
-		Log4j.initForConsole();
-		WebHandler.securityPassword = args[2];
-		backup( new File(args[0]), new File(args[1]) );
-		System.exit(0);
-	}
-}
diff -r 72b699bad1a4 -r 5c3702f60200 src/luan/host/Log4j.java
--- a/src/luan/host/Log4j.java	Sun Jul 07 22:49:36 2019 -0600
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,18 +0,0 @@
-package luan.host;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.Level;
-import org.apache.log4j.PatternLayout;
-import org.apache.log4j.ConsoleAppender;
-
-
-public final class Log4j {
-
-	public static void initForConsole() {
-		Logger.getRootLogger().setLevel(Level.INFO);
-		PatternLayout layout = new PatternLayout("%d %-5p %c - %m%n");
-		ConsoleAppender appender = new ConsoleAppender(layout,"System.err");
-		Logger.getRootLogger().addAppender(appender);
-	}
-
-}
diff -r 72b699bad1a4 -r 5c3702f60200 src/luan/host/WebHandler.java
--- a/src/luan/host/WebHandler.java	Sun Jul 07 22:49:36 2019 -0600
+++ b/src/luan/host/WebHandler.java	Thu Jul 11 23:19:11 2019 -0600
@@ -42,10 +42,6 @@
 	private static final DomainHandler domainHandler = new DomainHandler(factory);
 	private static String sitesDir = null;
 
-	public static boolean isServing() {
-		return sitesDir != null;
-	}
-
 	public WebHandler(String dir) {
 		if( sitesDir != null )
 			throw new RuntimeException("already set");
@@ -58,11 +54,6 @@
 		return domainHandler.handle(request);
 	}
 
-	public static Object runLuan(String domain,String sourceText,String sourceName) throws LuanException {
-		LuanHandler luanHandler = (LuanHandler)domainHandler.getHandler(domain);
-		return luanHandler.runLuan(sourceText,sourceName);
-	}
-
 	public static Object callSite(String domain,String fnName,Object... args) throws LuanException {
 		LuanHandler luanHandler = (LuanHandler)domainHandler.getHandler(domain);
 		return luanHandler.call_rpc(fnName,args);
@@ -88,7 +79,7 @@
 		return true;
 	}
 */
-	static void initLuan(Luan luan,String dir,String domain,boolean logging) {
+	private static void initLuan(Luan luan,String dir,String domain,boolean logging) {
 		security(luan,dir);
 		try {
 			LuanFunction fn = BasicLuan.load_file(luan,"classpath:luan/host/init.luan");
diff -r 72b699bad1a4 -r 5c3702f60200 src/luan/modules/http/LuanHandler.java
--- a/src/luan/modules/http/LuanHandler.java	Sun Jul 07 22:49:36 2019 -0600
+++ b/src/luan/modules/http/LuanHandler.java	Thu Jul 11 23:19:11 2019 -0600
@@ -172,21 +172,6 @@
 		isDisabled = true;
 	}
 
-	public Object runLuan(String sourceText,String sourceName) throws LuanException {
-		rwLock.readLock().lock();
-		try {
-			Luan luan = currentLuan;
-			synchronized(luanInit) {
-				LuanCloner cloner = new LuanCloner(LuanCloner.Type.INCREMENTAL);
-				Luan luan2 = (Luan)cloner.clone(luan);
-				LuanFunction fn = luan2.load(sourceText,sourceName);
-				return fn.call();
-			}
-		} finally {
-			rwLock.readLock().unlock();
-		}
-	}
-
 	public void eval_in_root(String text) throws LuanException {
 		Luan luan;
 		synchronized(luanInit) {
diff -r 72b699bad1a4 -r 5c3702f60200 src/luan/modules/lucene/Lucene.luan
--- a/src/luan/modules/lucene/Lucene.luan	Sun Jul 07 22:49:36 2019 -0600
+++ b/src/luan/modules/lucene/Lucene.luan	Thu Jul 11 23:19:11 2019 -0600
@@ -24,8 +24,6 @@
 
 local Lucene = {}
 
-Lucene.instances = {}
-
 Lucene.type = {
 	english = LuceneIndex.ENGLISH_FIELD_PARSER
 	string = LuceneIndex.STRING_FIELD_PARSER
@@ -63,19 +61,12 @@
 	index.delete = java_index.delete
 	index.save = java_index.save
 	index.update_in_transaction = java_index.update_in_transaction
---	index.close = java_index.close
 	index.ensure_open = java_index.ensure_open
 	index.next_id = java_index.nextId
 	index.highlighter = java_index.highlighter
 	index.indexed_only_fields = java_index.indexed_only_fields
 	index.count_tokens = java_index.count_tokens
-
-	Lucene.instances[index] = true
-
-	function index.close()
-		Lucene.instances[index] = nil
-		closer.close()
-	end
+	index.close = closer.close
 
 	function index.search( query, from, to, options )
 		from or error "missing 'from' parameter"