Update of /var/cvs/contributions/lucene/src/org/mmbase/module/lucene
In directory james.mmbase.org:/tmp/cvs-serv9393

Modified Files:
        AssignmentEvents.java Lucene.java 
Log Message:
LUCENE-13. Made also other index-changing operations clustering aware


See also: 
http://cvs.mmbase.org/viewcvs/contributions/lucene/src/org/mmbase/module/lucene
See also: http://www.mmbase.org/jira/browse/LUCENE-13


Index: AssignmentEvents.java
===================================================================
RCS file: 
/var/cvs/contributions/lucene/src/org/mmbase/module/lucene/AssignmentEvents.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- AssignmentEvents.java       28 Jul 2008 13:03:36 -0000      1.1
+++ AssignmentEvents.java       28 Jul 2008 14:20:57 -0000      1.2
@@ -17,26 +17,34 @@
  *
  * @since  MMBase-1.9
  * @author Michiel Meeuwissen
- * @version $Id: AssignmentEvents.java,v 1.1 2008/07/28 13:03:36 michiel Exp $
+ * @version $Id: AssignmentEvents.java,v 1.2 2008/07/28 14:20:57 michiel Exp $
  */
 
 public class AssignmentEvents {
 
-    public static final int TYPE_FULL = 100;
-    public static final int TYPE_UPDATE = 101;
+    public static final int FULL = 100;
+    public static final int UPDATE = 101;
+    public static final int DELETE = 102;
+    public static final int CLEAR = 103;
 
     public static class Event extends org.mmbase.core.event.Event {
 
         protected final String index;
         protected final List<String> machines;
 
+        protected final Class klas;
+        protected final String identifier;
+        protected boolean copy = false;
+
         /**
          * The event itself
          */
-        public Event(String i, List<String> m) {
-            super(null, TYPE_FULL);
+        public Event(String i, List<String> m, int type, String id, Class k) {
+            super(null, type);
             index = i;
             machines = m == null ? Collections.singletonList(getMachine()) : m;
+            klas = k;
+            identifier = id;
 
         };
         public String getIndex() {
@@ -45,6 +53,18 @@
         public List<String> getMachines() {
             return machines;
         }
+        public Class getClassFilter() {
+            return klas;
+        }
+        public String getIdentifier() {
+            return identifier;
+        }
+        public boolean getCopy() {
+            return copy;
+        }
+        public void setCopy(boolean b) {
+            copy = b;
+        }
         public String toString() {
             return super.toString() + " " + index;
         }


Index: Lucene.java
===================================================================
RCS file: 
/var/cvs/contributions/lucene/src/org/mmbase/module/lucene/Lucene.java,v
retrieving revision 1.116
retrieving revision 1.117
diff -u -b -r1.116 -r1.117
--- Lucene.java 28 Jul 2008 13:56:06 -0000      1.116
+++ Lucene.java 28 Jul 2008 14:20:57 -0000      1.117
@@ -48,7 +48,7 @@
  *
  * @author Pierre van Rooden
  * @author Michiel Meeuwissen
- * @version $Id: Lucene.java,v 1.116 2008/07/28 13:56:06 michiel Exp $
+ * @version $Id: Lucene.java,v 1.117 2008/07/28 14:20:57 michiel Exp $
  **/
 public class Lucene extends ReloadableModule implements NodeEventListener, 
RelationEventListener, IdEventListener, AssignmentEvents.Listener {
 
@@ -195,7 +195,7 @@
         public Object getFunctionValue(Parameters arguments) {
             String index = (String) arguments.get(INDEX);
             List<String> machines = (List<String>) arguments.get(MACHINES);
-            EventManager.getInstance().propagateEvent(new 
AssignmentEvents.Event(index, machines));
+            EventManager.getInstance().propagateEvent(new 
AssignmentEvents.Event(index, machines, AssignmentEvents.FULL, null,  null));
             return null;
         }
     };
@@ -206,6 +206,8 @@
     public void notify(AssignmentEvents.Event event) {
         log.info("Received " + event);
         if (event.getMachines().contains(MMBase.getMMBase().getMachineName())) 
{
+            switch(event.getType()) {
+            case AssignmentEvents.FULL: {
             String index = event.getIndex();
             if (scheduler == null) throw new RuntimeException("Read only");
             if (index == null || "".equals(index)) {
@@ -213,6 +215,47 @@
             } else {
                 scheduler.fullIndex(index);
             }
+                } break;
+            case AssignmentEvents.UPDATE:
+                throw new UnsupportedOperationException();
+            case AssignmentEvents.DELETE: {
+                    if (scheduler == null) throw new RuntimeException("Read 
only");
+                    if(!readOnly){
+                        String index      = event.getIndex();
+                        String identifier = event.getIdentifier();
+                        Class  klass      = event.getClassFilter();
+                        if(index == null || "".equals(index)){
+                            scheduler.deleteIndex(identifier, klass);
+                        } else {
+                            scheduler.deleteIndex(identifier, index);
+                        }
+                    }
+                } break;
+            case AssignmentEvents.CLEAR: {
+                    if (readOnly) {
+                        throw new IllegalStateException("This lucene is 
readonly");
+                    }
+                    String index = event.getIndex();
+                    Indexer indexer = indexerMap.get(index);
+                    boolean copy = event.getCopy();
+                    try {
+                        Directory dir = copy ? 
indexer.getDirectoryForFullIndex(): indexer.getDirectory();
+                        for (String file : dir.list()) {
+                            if (file != null) {
+                                try {
+                                    log.service("Deleting " + file);
+                                    dir.deleteFile(file);
+                                } catch (Exception e) {
+                                    log.warn(e);
+                                }
+                            }
+                        }
+                        if (! copy)  
EventManager.getInstance().propagateEvent(new NewSearcher.Event(index));
+                    } catch (java.io.IOException ioe) {
+                        throw new RuntimeException(ioe);
+                    }
+                } break;
+            }
         } else {
             log.info("Event " + event + " ignored");
         }
@@ -226,17 +269,12 @@
     //protected Function<Void> deleteIndexFunction = new 
AbstractFunction<Void>("deleteIndex", INDEX, IDENTIFIER, CLASS) {
     protected Function/*<Void>*/ deleteIndexFunction = new 
AbstractFunction/*<Void>*/("deleteIndex", new Parameter[] {INDEX, MACHINES, 
IDENTIFIER, CLASS}, ReturnType.VOID) {
             public Object getFunctionValue(Parameters arguments) {
-                if (scheduler == null) throw new RuntimeException("Read only");
-                if(!readOnly){
                     String index      = (String) arguments.get(INDEX);
                     String identifier = (String) arguments.get(IDENTIFIER);
+
                     Class  klass      = (Class)  arguments.get(CLASS);
-                    if(index == null || "".equals(index)){
-                        scheduler.deleteIndex(identifier, klass);
-                    } else {
-                        scheduler.deleteIndex(identifier, identifier);
-                    }
-                }
+                List<String> machines = (List<String>) arguments.get(MACHINES);
+                EventManager.getInstance().propagateEvent(new 
AssignmentEvents.Event(index, machines, AssignmentEvents.DELETE, identifier, 
klass));
                 return null;
             }
         };
@@ -497,28 +535,11 @@
 
     protected Function/*<Void>*/ clearDirectory = new 
AbstractFunction/*<Void>*/("clearDirectory", new Parameter[] {INDEX, MACHINES, 
COPY}, ReturnType.VOID) {
         public Object getFunctionValue(Parameters arguments) {
-            if (readOnly) {
-                throw new IllegalStateException("This lucene is readonly");
-            }
-            String index = (String) arguments.getString(INDEX);
-            Indexer indexer = indexerMap.get(index);
-            boolean copy = Boolean.TRUE.equals(arguments.get(COPY));
-            try {
-                Directory dir = copy ? indexer.getDirectoryForFullIndex(): 
indexer.getDirectory();
-                for (String file : dir.list()) {
-                    if (file != null) {
-                        try {
-                            log.service("Deleting " + file);
-                            dir.deleteFile(file);
-                        } catch (Exception e) {
-                            log.warn(e);
-                        }
-                    }
-                }
-                if (! copy)  EventManager.getInstance().propagateEvent(new 
NewSearcher.Event(index));
-            } catch (java.io.IOException ioe) {
-                throw new RuntimeException(ioe);
-            }
+            String index = (String) arguments.get(INDEX);
+            List<String> machines = (List<String>) arguments.get(MACHINES);
+            AssignmentEvents.Event event = new AssignmentEvents.Event(index, 
machines, AssignmentEvents.CLEAR, null, null);
+            event.setCopy((Boolean) arguments.get(COPY));
+            EventManager.getInstance().propagateEvent(event);
             return null;
         }
         };
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to