jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r501605 - in /jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SearchManager.java cluster/AbstractJournal.java cluster/FileRevision.java observation/EventImpl.java observation/EventState.java
Date Tue, 30 Jan 2007 22:25:38 GMT
Author: jukka
Date: Tue Jan 30 14:25:37 2007
New Revision: 501605

URL: http://svn.apache.org/viewvc?view=rev&rev=501605
Log:
1.2: Merged revision 496271 (JCR-708)

Modified:
    jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
    jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java
    jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java
    jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
    jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java

Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java?view=diff&rev=501605&r1=501604&r2=501605
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
(original)
+++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SearchManager.java
Tue Jan 30 14:25:37 2007
@@ -54,6 +54,8 @@
 import java.util.Properties;
 import java.util.Set;
 import java.util.WeakHashMap;
+import java.util.Map;
+import java.util.HashMap;
 
 /**
  * Acts as a global entry point to execute queries and index nodes.
@@ -353,7 +355,7 @@
         // nodes that need to be removed from the index.
         final Set removedNodes = new HashSet();
         // nodes that need to be added to the index.
-        final Set addedNodes = new HashSet();
+        final Map addedNodes = new HashMap();
         // property events
         List propEvents = new ArrayList();
 
@@ -368,7 +370,7 @@
             }
             long type = e.getType();
             if (type == Event.NODE_ADDED) {
-                addedNodes.add(e.getChildId());
+                addedNodes.put(e.getChildId(), e);
             } else if (type == Event.NODE_REMOVED) {
                 removedNodes.add(e.getChildId());
             } else {
@@ -378,29 +380,29 @@
 
         // sort out property events
         for (int i = 0; i < propEvents.size(); i++) {
-            EventImpl event = (EventImpl) propEvents.get(i);
-            NodeId nodeId = event.getParentId();
-            if (event.getType() == Event.PROPERTY_ADDED) {
-                if (addedNodes.add(nodeId)) {
+            EventImpl e = (EventImpl) propEvents.get(i);
+            NodeId nodeId = e.getParentId();
+            if (e.getType() == Event.PROPERTY_ADDED) {
+                if (addedNodes.put(nodeId, e) == null) {
                     // only property added
                     // need to re-index
                     removedNodes.add(nodeId);
                 } else {
                     // the node where this prop belongs to is also new
                 }
-            } else if (event.getType() == Event.PROPERTY_CHANGED) {
+            } else if (e.getType() == Event.PROPERTY_CHANGED) {
                 // need to re-index
-                addedNodes.add(nodeId);
+                addedNodes.put(nodeId, e);
                 removedNodes.add(nodeId);
             } else {
                 // property removed event is only generated when node still exists
-                addedNodes.add(nodeId);
+                addedNodes.put(nodeId, e);
                 removedNodes.add(nodeId);
             }
         }
 
         NodeStateIterator addedStates = new NodeStateIterator() {
-            private final Iterator iter = addedNodes.iterator();
+            private final Iterator iter = addedNodes.keySet().iterator();
 
             public void remove() {
                 throw new UnsupportedOperationException();
@@ -419,8 +421,15 @@
                 NodeId id = (NodeId) iter.next();
                 try {
                     item = (NodeState) itemMgr.getItemState(id);
-                } catch (ItemStateException e) {
-                    log.error("Unable to index node " + id + ": does not exist");
+                } catch (ItemStateException ise) {
+                    // check whether this item state change originated from
+                    // an external event
+                    EventImpl e = (EventImpl) addedNodes.get(id);
+                    if (e == null || !e.isExternal()) {
+                        log.error("Unable to index node " + id + ": does not exist");
+                    } else {
+                        log.info("Node no longer available " + id + ", skipped.");
+                    }
                 }
                 return item;
             }

Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java?view=diff&rev=501605&r1=501604&r2=501605
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java
(original)
+++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/AbstractJournal.java
Tue Jan 30 14:25:37 2007
@@ -577,19 +577,19 @@
         switch (type) {
             case Event.NODE_ADDED:
                 return EventState.childNodeAdded(parentId, parentPath, childId, childRelPath,
-                        ntName, mixins, getOrCreateSession(userId));
+                        ntName, mixins, getOrCreateSession(userId), true);
             case Event.NODE_REMOVED:
                 return EventState.childNodeRemoved(parentId, parentPath, childId, childRelPath,
-                        ntName, mixins, getOrCreateSession(userId));
+                        ntName, mixins, getOrCreateSession(userId), true);
             case Event.PROPERTY_ADDED:
                 return EventState.propertyAdded(parentId, parentPath, childRelPath,
-                        ntName, mixins, getOrCreateSession(userId));
+                        ntName, mixins, getOrCreateSession(userId), true);
             case Event.PROPERTY_CHANGED:
                 return EventState.propertyChanged(parentId, parentPath, childRelPath,
-                        ntName, mixins, getOrCreateSession(userId));
+                        ntName, mixins, getOrCreateSession(userId), true);
             case Event.PROPERTY_REMOVED:
                 return EventState.propertyRemoved(parentId, parentPath, childRelPath,
-                        ntName, mixins, getOrCreateSession(userId));
+                        ntName, mixins, getOrCreateSession(userId), true);
             default:
                 String msg = "Unexpected event type: " + type;
                 throw new IllegalArgumentException(msg);

Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java?view=diff&rev=501605&r1=501604&r2=501605
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java
(original)
+++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/FileRevision.java
Tue Jan 30 14:25:37 2007
@@ -113,11 +113,13 @@
             }
             lock = null;
 
-            try {
-                raf.close();
-            } catch (IOException e) {
-                String msg = "I/O error while closing file: " + e.getMessage();
-                log.warn(msg);
+            if (raf != null) {
+                try {
+                    raf.close();
+                } catch (IOException e) {
+                    String msg = "I/O error while closing file: " + e.getMessage();
+                    log.warn(msg);
+                }
             }
             raf = null;
         }

Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java?view=diff&rev=501605&r1=501604&r2=501605
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
(original)
+++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
Tue Jan 30 14:25:37 2007
@@ -131,6 +131,16 @@
     }
 
     /**
+     * Return a flag indicating whether this is an externally generated event.
+     *
+     * @return <code>true</code> if this is an external event;
+     *         <code>false</code> otherwise
+     */
+    public boolean isExternal() {
+        return eventState.isExternal();
+    }
+
+    /**
      * Returns a String representation of this <code>Event</code>.
      *
      * @return a String representation of this <code>Event</code>.

Modified: jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java?view=diff&rev=501605&r1=501604&r2=501605
==============================================================================
--- jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
(original)
+++ jackrabbit/branches/1.2/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
Tue Jan 30 14:25:37 2007
@@ -105,6 +105,12 @@
      * Cached hashCode value for this <code>Event</code>.
      */
     private int hashCode;
+    
+    /**
+     * Flag indicating whether this is an external event, e.g. originating from
+     * another node in a clustered environment.
+     */ 
+    private final boolean external;
 
     /**
      * Creates a new <code>EventState</code> instance.
@@ -123,14 +129,10 @@
      * @param mixins     mixins assigned to the parent node.
      * @param session    the {@link javax.jcr.Session} that caused this event.
      */
-    private EventState(int type,
-                       NodeId parentId,
-                       Path parentPath,
-                       NodeId childId,
-                       Path.PathElement childPath,
-                       QName nodeType,
-                       Set mixins,
-                       Session session) {
+    private EventState(int type, NodeId parentId, Path parentPath,
+                       NodeId childId, Path.PathElement childPath, QName nodeType,
+                       Set mixins, Session session, boolean external) {
+
         int mask = (Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED);
         if ((type & mask) > 0) {
             if (childId != null) {
@@ -149,6 +151,7 @@
         this.nodeType = nodeType;
         this.mixins = mixins;
         this.session = session;
+        this.external = external;
     }
 
     //-----------------< factory methods >--------------------------------------
@@ -175,18 +178,42 @@
                                             QName nodeType,
                                             Set mixins,
                                             Session session) {
-        return new EventState(Event.NODE_ADDED,
-                parentId,
-                parentPath,
-                childId,
-                childPath,
-                nodeType,
-                mixins,
-                session);
+        
+        return childNodeAdded(parentId, parentPath, childId,
+                childPath, nodeType, mixins, session, false);
     }
 
     /**
      * Creates a new {@link javax.jcr.observation.Event} of type
+     * {@link javax.jcr.observation.Event#NODE_ADDED}.
+     *
+     * @param parentId   the id of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param parentPath the path of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param childId    the id of the child node associated with this event.
+     * @param childPath  the relative path of the child node that was added.
+     * @param nodeType   the node type of the parent node.
+     * @param mixins     mixins assigned to the parent node.
+     * @param session    the session that added the node.
+     * @param external   flag indicating whether this is an external event
+     * @return an <code>EventState</code> instance.
+     */
+    public static EventState childNodeAdded(NodeId parentId,
+                                            Path parentPath,
+                                            NodeId childId,
+                                            Path.PathElement childPath,
+                                            QName nodeType,
+                                            Set mixins,
+                                            Session session,
+                                            boolean external) {
+
+        return new EventState(Event.NODE_ADDED, parentId, parentPath,
+                childId, childPath, nodeType, mixins, session, external);
+    }
+    
+    /**
+     * Creates a new {@link javax.jcr.observation.Event} of type
      * {@link javax.jcr.observation.Event#NODE_REMOVED}.
      *
      * @param parentId   the id of the parent node associated with
@@ -207,18 +234,42 @@
                                               QName nodeType,
                                               Set mixins,
                                               Session session) {
-        return new EventState(Event.NODE_REMOVED,
-                parentId,
-                parentPath,
-                childId,
-                childPath,
-                nodeType,
-                mixins,
-                session);
+
+        return childNodeRemoved(parentId, parentPath, childId,
+                childPath, nodeType, mixins, session, false);
     }
 
     /**
      * Creates a new {@link javax.jcr.observation.Event} of type
+     * {@link javax.jcr.observation.Event#NODE_REMOVED}.
+     *
+     * @param parentId   the id of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param parentPath the path of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param childId    the id of the child node associated with this event.
+     * @param childPath  the relative path of the child node that was removed.
+     * @param nodeType   the node type of the parent node.
+     * @param mixins     mixins assigned to the parent node.
+     * @param session    the session that removed the node.
+     * @param external   flag indicating whether this is an external event
+     * @return an <code>EventState</code> instance.
+     */
+    public static EventState childNodeRemoved(NodeId parentId,
+                                              Path parentPath,
+                                              NodeId childId,
+                                              Path.PathElement childPath,
+                                              QName nodeType,
+                                              Set mixins,
+                                              Session session,
+                                              boolean external) {
+
+        return new EventState(Event.NODE_REMOVED, parentId, parentPath,
+                childId, childPath, nodeType, mixins, session, external);
+    }
+    
+    /**
+     * Creates a new {@link javax.jcr.observation.Event} of type
      * {@link javax.jcr.observation.Event#PROPERTY_ADDED}.
      *
      * @param parentId   the id of the parent node associated with
@@ -237,14 +288,36 @@
                                            QName nodeType,
                                            Set mixins,
                                            Session session) {
-        return new EventState(Event.PROPERTY_ADDED,
-                parentId,
-                parentPath,
-                null,
-                childPath,
-                nodeType,
-                mixins,
-                session);
+        
+        return propertyAdded(parentId, parentPath, childPath, 
+                nodeType, mixins, session, false);
+    }
+
+    /**
+     * Creates a new {@link javax.jcr.observation.Event} of type
+     * {@link javax.jcr.observation.Event#PROPERTY_ADDED}.
+     *
+     * @param parentId   the id of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param parentPath the path of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param childPath  the relative path of the property that was added.
+     * @param nodeType   the node type of the parent node.
+     * @param mixins     mixins assigned to the parent node.
+     * @param session    the session that added the property.
+     * @param external   flag indicating whether this is an external event
+     * @return an <code>EventState</code> instance.
+     */
+    public static EventState propertyAdded(NodeId parentId,
+                                           Path parentPath,
+                                           Path.PathElement childPath,
+                                           QName nodeType,
+                                           Set mixins,
+                                           Session session,
+                                           boolean external) {
+        
+        return new EventState(Event.PROPERTY_ADDED, parentId, parentPath,
+                null, childPath, nodeType, mixins, session, external);
     }
 
     /**
@@ -267,14 +340,36 @@
                                              QName nodeType,
                                              Set mixins,
                                              Session session) {
-        return new EventState(Event.PROPERTY_REMOVED,
-                parentId,
-                parentPath,
-                null,
-                childPath,
-                nodeType,
-                mixins,
-                session);
+        
+        return propertyRemoved(parentId, parentPath, childPath,
+                nodeType, mixins, session, false);
+    }
+
+    /**
+     * Creates a new {@link javax.jcr.observation.Event} of type
+     * {@link javax.jcr.observation.Event#PROPERTY_REMOVED}.
+     *
+     * @param parentId   the id of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param parentPath the path of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param childPath  the relative path of the property that was removed.
+     * @param nodeType   the node type of the parent node.
+     * @param mixins     mixins assigned to the parent node.
+     * @param session    the session that removed the property.
+     * @param external   flag indicating whether this is an external event
+     * @return an <code>EventState</code> instance.
+     */
+    public static EventState propertyRemoved(NodeId parentId,
+                                             Path parentPath,
+                                             Path.PathElement childPath,
+                                             QName nodeType,
+                                             Set mixins,
+                                             Session session,
+                                             boolean external) {
+
+        return new EventState(Event.PROPERTY_REMOVED, parentId, parentPath,
+                null, childPath, nodeType, mixins, session, external);
     }
 
     /**
@@ -297,14 +392,36 @@
                                              QName nodeType,
                                              Set mixins,
                                              Session session) {
-        return new EventState(Event.PROPERTY_CHANGED,
-                parentId,
-                parentPath,
-                null,
-                childPath,
-                nodeType,
-                mixins,
-                session);
+
+        return propertyChanged(parentId, parentPath, childPath,
+                nodeType, mixins, session, false);
+    }
+
+    /**
+     * Creates a new {@link javax.jcr.observation.Event} of type
+     * {@link javax.jcr.observation.Event#PROPERTY_CHANGED}.
+     *
+     * @param parentId   the id of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param parentPath the path of the parent node associated with
+     *                   this <code>EventState</code>.
+     * @param childPath  the relative path of the property that changed.
+     * @param nodeType   the node type of the parent node.
+     * @param mixins     mixins assigned to the parent node.
+     * @param session    the session that changed the property.
+     * @param external   flag indicating whether this is an external event
+     * @return an <code>EventState</code> instance.
+     */
+    public static EventState propertyChanged(NodeId parentId,
+                                             Path parentPath,
+                                             Path.PathElement childPath,
+                                             QName nodeType,
+                                             Set mixins,
+                                             Session session,
+                                             boolean external) {
+
+        return new EventState(Event.PROPERTY_CHANGED, parentId, parentPath,
+                null, childPath, nodeType, mixins, session, external);
     }
 
     /**
@@ -432,6 +549,16 @@
             // node event
             return childId;
         }
+    }
+
+    /**
+     * Return a flag indicating whether this is an externally generated event.
+     *
+     * @return <code>true</code> if this is an external event;
+     *         <code>false</code> otherwise
+     */
+    boolean isExternal() {
+        return external;
     }
 
     /**



Mime
View raw message