Revision: 17337
          http://sourceforge.net/p/gate/code/17337
Author:   valyt
Date:     2014-02-19 11:45:22 +0000 (Wed, 19 Feb 2014)
Log Message:
-----------
Patches that will help allow the opening of old style indexes:
- set the time between batches to the default value if it's not present in the 
index config
- hack to load the correct class when deserializing DocumentData values from 
old mimir archives. 

Modified Paths:
--------------
    mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java
    mimir/branches/5.0/mimir-core/src/gate/mimir/index/DocumentCollection.java

Modified: mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java
===================================================================
--- mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java        
2014-02-19 08:40:49 UTC (rev 17336)
+++ mimir/branches/5.0/mimir-core/src/gate/mimir/MimirIndex.java        
2014-02-19 11:45:22 UTC (rev 17337)
@@ -530,6 +530,9 @@
     maintenanceTimer = new Timer("Mímir index maintenance timer");
     synchronized(maintenanceTimer) {
       syncToDiskTask = new SyncToDiskTask();
+      if(indexConfig.getTimeBetweenBatches() <= 0) {
+        
indexConfig.setTimeBetweenBatches(IndexConfig.DEFAULT_TIME_BETWEEN_BATCHES);
+      }
       maintenanceTimer.schedule(syncToDiskTask, 
           indexConfig.getTimeBetweenBatches(), 
           indexConfig.getTimeBetweenBatches());

Modified: 
mimir/branches/5.0/mimir-core/src/gate/mimir/index/DocumentCollection.java
===================================================================
--- mimir/branches/5.0/mimir-core/src/gate/mimir/index/DocumentCollection.java  
2014-02-19 08:40:49 UTC (rev 17336)
+++ mimir/branches/5.0/mimir-core/src/gate/mimir/index/DocumentCollection.java  
2014-02-19 11:45:22 UTC (rev 17337)
@@ -27,6 +27,7 @@
 import java.io.InputStream;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -181,10 +182,9 @@
       ZipEntry entry = zipFile.getEntry(Long.toString(documentID));
       if(entry == null) throw new NoSuchElementException(
           "No entry found for document ID " + documentID);
-      ObjectInputStream ois = null;
+      CustomObjectInputStream ois = null;
       try {
-        ois = new ObjectInputStream(
-            zipFile.getInputStream(entry));
+        ois = new CustomObjectInputStream(zipFile.getInputStream(entry));
         return (DocumentData) ois.readObject();
       } catch(ClassNotFoundException e) {
         //invalid data read from the zip file
@@ -201,6 +201,31 @@
   }
 
   /**
+   * Custom implementation of {@link ObjectInputStream} that handles reading
+   * old mimir archive files where the contents include serialised classes
+   * with old (pre-Mímir-5) class names.
+   */
+  protected static class CustomObjectInputStream extends ObjectInputStream {
+
+    public CustomObjectInputStream() throws IOException, SecurityException {
+      super();
+    }
+
+    public CustomObjectInputStream(InputStream in) throws IOException {
+      super(in);
+    }
+
+    @Override
+    protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException,
+        ClassNotFoundException {
+      
if("gate.mimir.index.mg4j.zipcollection.DocumentData".equals(desc.getName())) {
+        desc = 
ObjectStreamClass.lookup(Class.forName("gate.mimir.index.DocumentData"));
+      }
+      return super.resolveClass(desc);
+    }
+  }
+  
+  /**
    * Class that handles the creation of collection files.
    */
   protected static class CollectionFileWriter {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121054471&iu=/4140/ostg.clktrk
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to