vgritsenko    2004/02/20 18:11:23

  Modified:    .        status.xml
               java/src/org/apache/xindice/client/xmldb/xmlrpc
                        CollectionImpl.java
               java/src/org/apache/xindice/core Collection.java
               java/src/org/apache/xindice/core/indexer IndexManager.java
  Log:
  Implement close()
  
  Revision  Changes    Path
  1.34      +3 -0      xml-xindice/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/xml-xindice/status.xml,v
  retrieving revision 1.33
  retrieving revision 1.34
  diff -u -r1.33 -r1.34
  --- status.xml        19 Feb 2004 03:05:15 -0000      1.33
  +++ status.xml        21 Feb 2004 02:11:23 -0000      1.34
  @@ -70,6 +70,9 @@
       <changes>
           <release version="1.1b4-dev" date="February 11 2004">
               <action dev="VG" type="update">
  +                Implemented close() in Collection, IndexManager.
  +            </action>
  +            <action dev="VG" type="update">
                   XML-RPC interface now passes XMLDBException codes as XML-RPC 
faults.
               </action>
               <action dev="VG" type="update">
  
  
  
  1.47      +3 -4      
xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java
  
  Index: CollectionImpl.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/client/xmldb/xmlrpc/CollectionImpl.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- CollectionImpl.java       19 Feb 2004 13:14:26 -0000      1.46
  +++ CollectionImpl.java       21 Feb 2004 02:11:23 -0000      1.47
  @@ -336,8 +336,7 @@
        *  <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
        *  specific errors that occur.<br />
        */
  -    public void close() throws org.xmldb.api.base.XMLDBException {
  -
  +    public void close() throws XMLDBException {
           client = null;
       }
   
  
  
  
  1.49      +9 -10     
xml-xindice/java/src/org/apache/xindice/core/Collection.java
  
  Index: Collection.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/Collection.java,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- Collection.java   20 Feb 2004 13:45:05 -0000      1.48
  +++ Collection.java   21 Feb 2004 02:11:23 -0000      1.49
  @@ -238,7 +238,11 @@
        * @see org.apache.xindice.core.DBObject#close()
        */
       public boolean close() throws DBException {
  -        // TODO: Why this is no-op? How filers (and all RandomAccessFiles) 
will ever get closed?
  +        if (filer != null) {
  +            indexManager.close();
  +            filer.close();
  +        }
  +        super.close();
           return true;
       }
   
  @@ -362,13 +366,8 @@
           }
   
           if (filer != null) {
  -            // Drop Indexers
  -            String[] idx = indexManager.list();
  -            for (int i = 0; i < idx.length; i++) {
  -                dropIndexer(getIndexer(idx[i]));
  -            }
  -
  -            // Now Drop The Filer
  +            // Drop Indexers and Filer
  +            indexManager.drop();
               filer.drop();
           }
   
  
  
  
  1.28      +43 -15    
xml-xindice/java/src/org/apache/xindice/core/indexer/IndexManager.java
  
  Index: IndexManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xindice/java/src/org/apache/xindice/core/indexer/IndexManager.java,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- IndexManager.java 11 Feb 2004 14:00:33 -0000      1.27
  +++ IndexManager.java 21 Feb 2004 02:11:23 -0000      1.28
  @@ -58,8 +58,8 @@
   
       private static final Log log = LogFactory.getLog(IndexManager.class);
   
  -    private static final String[] EmptyStrings = new String[0];
  -    private static final IndexerInfo[] EmptyIndexerInfo = new IndexerInfo[0];
  +    private static final String[] EMPTY_STRINGS = new String[0];
  +    private static final IndexerInfo[] EMPTY_INDEXERS = new IndexerInfo[0];
   
       private static final String INDEX = "index";
       private static final String NAME = "name";
  @@ -67,30 +67,35 @@
   
       private static final int STATUS_READY = 0;
       private static final int STATUS_BUSY = 1;
  -    // private static final int STATUS_DELETED = 2;
   
       private static final int ACTION_CREATE = 0;
       private static final int ACTION_UPDATE = 1;
       private static final int ACTION_DELETE = 2;
  -    private static final Timer indexTimer = new Timer(true);
  +
  +    private static final Timer timer = new Timer(true);
   
       private Map patternMap = new HashMap(); // IndexPattern to IndexerInfo
       private Map indexes = new HashMap(); // String to IndexerInfo
       private Map bestIndexers = new HashMap(); // String to SoftRefTab
       // of IndexPattern to Indexer
   
  -    private IndexerInfo[] idxList = EmptyIndexerInfo;
  +    private IndexerInfo[] idxList = EMPTY_INDEXERS;
   
       private Collection collection;
       private SymbolTable symbols;
       private List newIndexers = new ArrayList(); // of IndexerInfo
   
  -
  +    /**
  +     * Create index manager for a collection
  +     */
       public IndexManager(Collection collection) throws DBException {
           this.collection = collection;
           this.symbols = collection.getSymbols();
       }
   
  +    /**
  +     * Configure index manager, register all indexes
  +     */
       public void setConfig(Configuration config) throws XindiceException {
           super.setConfig(config);
   
  @@ -101,7 +106,7 @@
                       register(Class.forName(className), cfg);
                   } catch (Exception e) {
                       if (log.isWarnEnabled()) {
  -                        log.warn("Failed to register index with class '" + 
className + "'", e);
  +                        log.warn("Failed to register index with class '" + 
className + "' for collection " + collection.getCanonicalName(), e);
                       }
                   }
               }
  @@ -115,7 +120,7 @@
        * @return An array containing the Indexer names
        */
       public String[] list() {
  -        return (String[]) indexes.keySet().toArray(EmptyStrings);
  +        return (String[]) indexes.keySet().toArray(EMPTY_STRINGS);
       }
   
       /**
  @@ -154,6 +159,15 @@
       }
   
       /**
  +     * Drop all indexers
  +     */
  +    public void drop() {
  +        for (int i = 0; i < idxList.length; i++) {
  +            drop(idxList[i].name);
  +        }
  +    }
  +
  +    /**
        * create creates a new Indexer object and any associated
        * system resources that the Indexer will need.
        *
  @@ -185,6 +199,21 @@
           }
       }
   
  +    /**
  +     * Closes all indexers managed by this index manager.
  +     */
  +    public void close() {
  +        for (int i = 0; i < idxList.length; i++) {
  +            try {
  +                idxList[i].indexer.close();
  +            } catch (DBException e) {
  +                if (log.isWarnEnabled()) {
  +                    log.warn("Failed to close indexer " + idxList[i].name + 
" on collection " + collection.getCanonicalName(), e);
  +                }
  +            }
  +        }
  +    }
  +
       public Indexer register(Class c, Configuration cfg) throws DBException {
           String name = null;
           try {
  @@ -205,7 +234,7 @@
                   synchronized (newIndexers) {
                       newIndexers.add(info);
                   }
  -                indexTimer.schedule(new PopulateIndexersTimerTask(this), 0);
  +                timer.schedule(new PopulateIndexersTimerTask(this), 0);
               } else {
                   info.status = STATUS_READY;
                   idx.open();
  @@ -221,7 +250,7 @@
               } else {
                   tbl.clear();
               }
  -            idxList = (IndexerInfo[]) 
indexes.values().toArray(EmptyIndexerInfo);
  +            idxList = (IndexerInfo[]) 
indexes.values().toArray(EMPTY_INDEXERS);
   
               return idx;
           } catch (DBException e) {
  @@ -243,7 +272,7 @@
           }
           tbl.clear();
   
  -        idxList = (IndexerInfo[]) indexes.values().toArray(EmptyIndexerInfo);
  +        idxList = (IndexerInfo[]) indexes.values().toArray(EMPTY_INDEXERS);
       }
   
       private void initialize(Indexer idx, Configuration cfg) throws 
XindiceException {
  @@ -254,7 +283,7 @@
       private void populateNewIndexers() throws DBException {
           IndexerInfo[] list = null;
           synchronized (newIndexers) {
  -            list = (IndexerInfo[]) newIndexers.toArray(EmptyIndexerInfo);
  +            list = (IndexerInfo[]) newIndexers.toArray(EMPTY_INDEXERS);
               newIndexers.clear();
           }
   
  @@ -570,7 +599,6 @@
       /**
        * StackInfo
        */
  -
       private class StackInfo {
           public short symbolID;
           public StringBuffer sb = null;
  
  
  

Reply via email to