Mercurial Hosting > luan
comparison src/luan/host/Backup.java @ 1264:d41997776788
fix onClose issues
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 25 Sep 2018 17:03:57 -0600 |
parents | 83c8a5a47f70 |
children | 307e76ccd0d6 |
comparison
equal
deleted
inserted
replaced
1263:382c444a6c77 | 1264:d41997776788 |
---|---|
1 package luan.host; | 1 package luan.host; |
2 | 2 |
3 import java.io.Closeable; | |
3 import java.io.File; | 4 import java.io.File; |
4 import java.io.IOException; | 5 import java.io.IOException; |
5 import java.nio.file.Files; | 6 import java.nio.file.Files; |
6 import java.util.Map; | 7 import java.util.Map; |
8 import java.util.List; | |
9 import java.util.ArrayList; | |
7 import org.slf4j.Logger; | 10 import org.slf4j.Logger; |
8 import org.slf4j.LoggerFactory; | 11 import org.slf4j.LoggerFactory; |
9 import org.apache.lucene.index.SnapshotDeletionPolicy; | 12 import org.apache.lucene.index.SnapshotDeletionPolicy; |
10 import org.apache.lucene.index.IndexCommit; | 13 import org.apache.lucene.index.IndexCommit; |
11 import org.apache.lucene.store.FSDirectory; | 14 import org.apache.lucene.store.FSDirectory; |
62 try { | 65 try { |
63 if( WebHandler.isServing() ) { | 66 if( WebHandler.isServing() ) { |
64 luceneInstances = (LuanTable)WebHandler.runLuan( from.getName(), getLucenes, "getLucenes" ); | 67 luceneInstances = (LuanTable)WebHandler.runLuan( from.getName(), getLucenes, "getLucenes" ); |
65 } else { | 68 } else { |
66 luan = new LuanState(); | 69 luan = new LuanState(); |
70 luan.onClose = new LuanState.OnClose() { | |
71 private final List<Closeable> onClose = new ArrayList<Closeable>(); | |
72 | |
73 public void onClose(Closeable c) { | |
74 onClose.add(c); | |
75 } | |
76 | |
77 public void close() { | |
78 for( Closeable c : onClose ) { | |
79 try { | |
80 c.close(); | |
81 } catch(IOException e) { | |
82 logger.error(c.toString(),e); | |
83 } | |
84 } | |
85 onClose.clear(); | |
86 } | |
87 }; | |
67 WebHandler.initLuan( luan, from.toString(), from.getName() ); | 88 WebHandler.initLuan( luan, from.toString(), from.getName() ); |
68 PackageLuan.load(luan,"site:/init.luan"); | 89 PackageLuan.load(luan,"site:/init.luan"); |
69 luceneInstances = (LuanTable)luan.eval(getLucenes); | 90 luceneInstances = (LuanTable)luan.eval(getLucenes); |
70 } | 91 } |
71 } catch(LuanException e) { | 92 } catch(LuanException e) { |
90 } finally { | 111 } finally { |
91 snapshotDeletionPolicy.release(ic); | 112 snapshotDeletionPolicy.release(ic); |
92 } | 113 } |
93 } | 114 } |
94 if( luan != null ) | 115 if( luan != null ) |
95 luan.close(); | 116 luan.onClose.close(); |
96 } | 117 } |
97 | 118 |
98 public static void backup(File sitesDir,File backupDir) throws IOException { | 119 public static void backup(File sitesDir,File backupDir) throws IOException { |
99 mkdir(backupDir); | 120 mkdir(backupDir); |
100 for( File siteDir : sitesDir.listFiles() ) { | 121 for( File siteDir : sitesDir.listFiles() ) { |