jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1000867 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ observation/
Date Fri, 24 Sep 2010 13:40:56 GMT
Author: jukka
Date: Fri Sep 24 13:40:55 2010
New Revision: 1000867

URL: http://svn.apache.org/viewvc?rev=1000867&view=rev
Log:
JCR-515: Enhance test data

Use the FilteredRangeIterator class to implement FilteredEventIterator so that getSize() will
return a good value and we can run more tests.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventFilter.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/FilteredEventIterator.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationManagerImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=1000867&r1=1000866&r2=1000867&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Fri Sep 24 13:40:55 2010
@@ -281,8 +281,7 @@ public class SessionImpl extends Abstrac
         try {
             return new ObservationManagerImpl(
                     context.getRepository().getObservationDispatcher(wspName),
-                    this, context.getItemManager(),
-                    context.getRepositoryContext().getClusterNode());
+                    this, context.getRepositoryContext().getClusterNode());
         } catch (NoSuchWorkspaceException e) {
             // should never get here
             throw new RepositoryException(

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java?rev=1000867&r1=1000866&r2=1000867&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventConsumer.java
Fri Sep 24 13:40:55 2010
@@ -219,6 +219,10 @@ class EventConsumer {
     void consumeEvents(EventStateCollection events) throws RepositoryException {
         // Set of ItemIds of denied ItemStates
         Set<ItemId> denied = accessDenied.remove(events);
+        if (denied == null) {
+            denied = new HashSet<ItemId>();
+        }
+
         // check permissions
         for (Iterator<EventState> it = events.iterator(); it.hasNext() && session.isLive();)
{
             EventState state = it.next();
@@ -227,9 +231,6 @@ class EventConsumer {
                     || state.getType() == Event.PROPERTY_CHANGED) {
                 ItemId targetId = state.getTargetId();
                 if (!canRead(state)) {
-                    if (denied == null) {
-                        denied = new HashSet<ItemId>();
-                    }
                     denied.add(targetId);
                 }
             }
@@ -239,8 +240,9 @@ class EventConsumer {
             return;
         }
         // check if filtered iterator has at least one event
-        EventIterator it = new FilteredEventIterator(events.iterator(),
-                events.getTimestamp(), events.getUserData(), filter, denied);
+        EventIterator it = new FilteredEventIterator(
+                session, events.iterator(), events.getTimestamp(),
+                events.getUserData(), filter, denied);
         if (it.hasNext()) {
             long time = System.currentTimeMillis();
             listener.onEvent(it);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventFilter.java?rev=1000867&r1=1000866&r2=1000867&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventFilter.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventFilter.java
Fri Sep 24 13:40:55 2010
@@ -19,11 +19,9 @@ package org.apache.jackrabbit.core.obser
 import java.util.Iterator;
 import java.util.Set;
 
-import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.nodetype.NodeTypeImpl;
-import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.Path;
 
 import javax.jcr.RepositoryException;
@@ -38,11 +36,6 @@ public class EventFilter {
     static final EventFilter BLOCK_ALL = new BlockAllFilter();
 
     /**
-     * The ItemManager of the session
-     */
-    private final ItemManager itemMgr;
-
-    /**
      * The session this EventFilter belongs to.
      */
     private final SessionImpl session;
@@ -83,7 +76,6 @@ public class EventFilter {
     /**
      * Creates a new <code>EventFilter</code> instance.
      *
-     * @param itemMgr    the <code>ItemManager</code> of the <code>session</code>.
      * @param session    the <code>Session</code> that registered the {@link
      *                   javax.jcr.observation.EventListener}.
      * @param eventTypes only allow specified {@link javax.jcr.observation.Event} types.
@@ -101,16 +93,13 @@ public class EventFilter {
      *                   created from changes related to the <code>Session</code>
      *                   that registered the {@link javax.jcr.observation.EventListener}.
      */
-    EventFilter(ItemManager itemMgr,
-                SessionImpl session,
+    EventFilter(SessionImpl session,
                 long eventTypes,
                 Path path,
                 boolean isDeep,
                 NodeId[] ids,
                 NodeTypeImpl[] nodeTypes,
                 boolean noLocal) {
-
-        this.itemMgr = itemMgr;
         this.session = session;
         this.eventTypes = eventTypes;
         this.path = path;
@@ -121,29 +110,6 @@ public class EventFilter {
     }
 
     /**
-     * Returns the <code>Session</code> associated with this
-     * <code>EventFilter</code>.
-     *
-     * @return the <code>Session</code> associated with this
-     *         <code>EventFilter</code>.
-     */
-    SessionImpl getSession() {
-        return session;
-    }
-
-    /**
-     * TODO: remove this unused method.
-     * Returns the <code>ItemManager</code> associated with this
-     * <code>EventFilter</code>.
-     *
-     * @return the <code>ItemManager</code> associated with this
-     *         <code>EventFilter</code>.
-     */
-    ItemManager getItemManager() {
-        return itemMgr;
-    }
-
-    /**
      * Returns <code>true</code> if this <code>EventFilter</code>
does not allow
      * the specified <code>EventState</code>; <code>false</code>
otherwise.
      *
@@ -196,18 +162,13 @@ public class EventFilter {
         }
 
         // finally check path
-        try {
-            Path eventPath = eventState.getParentPath();
-            boolean match = eventPath.equals(path);
-            if (!match && isDeep) {
-                match = eventPath.isDescendantOf(path);
-            }
-
-            return !match;
-        } catch (MalformedPathException mpe) {
-            // should never get here...
-            throw new RepositoryException("internal error: failed to check path filter",
mpe);
+        Path eventPath = eventState.getParentPath();
+        boolean match = eventPath.equals(path);
+        if (!match && isDeep) {
+            match = eventPath.isDescendantOf(path);
         }
+
+        return !match;
     }
 
     /**
@@ -220,7 +181,7 @@ public class EventFilter {
          * Creates a new <code>BlockAllFilter</code>.
          */
         BlockAllFilter() {
-            super(null, null, 0, null, true, null, null, true);
+            super(null, 0, null, true, null, null, true);
         }
 
         /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java?rev=1000867&r1=1000866&r2=1000867&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventJournalImpl.java
Fri Sep 24 13:40:55 2010
@@ -31,6 +31,8 @@ import javax.jcr.observation.Event;
 import javax.jcr.observation.EventIterator;
 
 import javax.jcr.observation.EventJournal;
+
+import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.journal.Journal;
 import org.apache.jackrabbit.core.journal.RecordIterator;
 import org.apache.jackrabbit.core.journal.JournalException;
@@ -90,9 +92,9 @@ public class EventJournalImpl implements
     private final String producerId;
 
     /**
-     * The name of the workspace to filter journal records.
+     * Target session.
      */
-    private final String wspName;
+    private final SessionImpl session;
 
     /**
      * Buffer of {@link EventBundle}s.
@@ -110,14 +112,15 @@ public class EventJournalImpl implements
      * @param filter for filtering the events read from the journal.
      * @param journal the cluster journal.
      * @param producerId the producer id of the cluster node.
+     * @param session target session
      */
-    public EventJournalImpl(EventFilter filter,
-                            Journal journal,
-                            String producerId) {
+    public EventJournalImpl(
+            EventFilter filter, Journal journal,
+            String producerId, SessionImpl session) {
         this.filter = filter;
         this.journal = journal;
         this.producerId = producerId;
-        this.wspName = filter.getSession().getWorkspace().getName();
+        this.session = session;
     }
 
     //------------------------< EventJournal >---------------------------------
@@ -269,8 +272,8 @@ public class EventJournalImpl implements
         public void process(ChangeLogRecord record) {
             List<EventState> events = record.getEvents();
             if (!events.isEmpty()) {
-                EventBundle bundle = new EventBundle(events,
-                        record.getTimestamp(), record.getUserData(), filter);
+                EventBundle bundle = new EventBundle(
+                        events, record.getTimestamp(), record.getUserData());
                 if (bundle.events.hasNext()) {
                     // only queue bundle if there is an event
                     eventBundleBuffer.add(bundle);
@@ -336,7 +339,7 @@ public class EventJournalImpl implements
                     Record record = records.nextRecord();
                     if (record.getProducerId().equals(producerId)) {
                         ClusterRecord cr = deserializer.deserialize(record);
-                        if (!wspName.equals(cr.getWorkspace())) {
+                        if (!session.getWorkspace().getName().equals(cr.getWorkspace()))
{
                             continue;
                         }
                         cr.process(processor);
@@ -383,7 +386,7 @@ public class EventJournalImpl implements
     /**
      * Simple class to associate an {@link EventState} iterator with a timestamp.
      */
-    private static final class EventBundle {
+    private final class EventBundle {
 
         /**
          * An iterator of {@link Event}s.
@@ -403,12 +406,11 @@ public class EventJournalImpl implements
          * @param userData the user data associated with this event.
          * @param filter the event filter.
          */
-        private EventBundle(List<EventState> eventStates,
-                            long timestamp,
-                            String userData,
-                            EventFilter filter) {
-            this.events = new FilteredEventIterator(eventStates.iterator(),
-                    timestamp, userData, filter, Collections.EMPTY_SET);
+        private EventBundle(
+                List<EventState> eventStates, long timestamp, String userData) {
+            this.events = new FilteredEventIterator(
+                    session, eventStates.iterator(),
+                    timestamp, userData, filter, Collections.emptySet());
             this.timestamp = timestamp;
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/FilteredEventIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/FilteredEventIterator.java?rev=1000867&r1=1000866&r2=1000867&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/FilteredEventIterator.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/FilteredEventIterator.java
Fri Sep 24 13:40:55 2010
@@ -17,18 +17,20 @@
 package org.apache.jackrabbit.core.observation;
 
 import java.util.Iterator;
-import java.util.NoSuchElementException;
 import java.util.Set;
 
 import javax.jcr.RepositoryException;
-import javax.jcr.observation.Event;
 
+import org.apache.jackrabbit.commons.iterator.EventIteratorAdapter;
+import org.apache.jackrabbit.commons.iterator.FilteredRangeIterator;
+import org.apache.jackrabbit.commons.predicate.Predicate;
+import org.apache.jackrabbit.core.SessionImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  */
-class FilteredEventIterator implements javax.jcr.observation.EventIterator {
+class FilteredEventIterator extends EventIteratorAdapter {
 
     /**
      * Logger instance for this class
@@ -37,34 +39,14 @@ class FilteredEventIterator implements j
             = LoggerFactory.getLogger(FilteredEventIterator.class);
 
     /**
-     * The actual {@link EventState}s fired by the workspace (unfiltered)
+     * Target session
      */
-    private final Iterator actualEvents;
+    private final SessionImpl session;
 
     /**
-     * For filtering the {@link javax.jcr.observation.Event}s.
+     * The timestamp when the events occurred.
      */
-    private final EventFilter filter;
-
-    /**
-     * Set of <code>ItemId</code>s of denied <code>ItemState</code>s.
-     */
-    private final Set denied;
-
-    /**
-     * The next {@link javax.jcr.observation.Event} in this iterator
-     */
-    private Event next;
-
-    /**
-     * Current position
-     */
-    private long pos;
-
-    /**
-     * The timestamp when the events occured.
-     */
-    private long timestamp;
+    private final long timestamp;
 
     /**
      * The user data associated with these events.
@@ -74,111 +56,40 @@ class FilteredEventIterator implements j
     /**
      * Creates a new <code>FilteredEventIterator</code>.
      *
+     * @param session target session
      * @param eventStates an iterator over unfiltered {@link EventState}s.
      * @param timestamp the time when the event were created.
      * @param userData   the user data associated with these events.
      * @param filter only event that pass the filter will be dispatched to the
      *               event listener.
      * @param denied <code>Set</code> of <code>ItemId</code>s of
denied <code>ItemState</code>s
-     *               rejected by the <code>AccessManager</code>. If
-     *               <code>null</code> no <code>ItemState</code>
is denied.
+     *               rejected by the <code>AccessManager</code>
      */
-    public FilteredEventIterator(Iterator eventStates,
-                                 long timestamp,
-                                 String userData,
-                                 EventFilter filter,
-                                 Set denied) {
-        this.actualEvents = eventStates;
-        this.filter = filter;
-        this.denied = denied;
+    public FilteredEventIterator(
+            SessionImpl session, Iterator<?> eventStates,
+            long timestamp, String userData,
+            final EventFilter filter, final Set<?> denied) {
+        super(new FilteredRangeIterator(eventStates, new Predicate() {
+            public boolean evaluate(Object object) {
+                try {
+                    EventState state = (EventState) object;
+                    return !denied.contains(state.getTargetId())
+                        && !filter.blocks(state);
+                } catch (RepositoryException e) {
+                    log.error("Exception while applying event filter", e);
+                    return false;
+                }
+            }
+        }));
+        this.session = session;
         this.timestamp = timestamp;
         this.userData = userData;
-        fetchNext();
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    @Override
     public Object next() {
-        if (next == null) {
-            throw new NoSuchElementException();
-        }
-        Event e = next;
-        fetchNext();
-        pos++;
-        return e;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public Event nextEvent() {
-        return (Event) next();
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public void skip(long skipNum) {
-        while (skipNum-- > 0) {
-            next();
-        }
+        return new EventImpl(
+                session, (EventState) super.next(), timestamp, userData);
     }
 
-    /**
-     * Always returns <code>-1</code>.
-     *
-     * @return <code>-1</code>.
-     */
-    public long getSize() {
-        return -1;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
-    public long getPosition() {
-        return pos;
-    }
-
-    /**
-     * This method is not supported.
-     * Always throws a <code>UnsupportedOperationException</code>.
-     */
-    public void remove() {
-        throw new UnsupportedOperationException("EventIterator.remove()");
-    }
-
-    /**
-     * Returns <tt>true</tt> if the iteration has more elements. (In other
-     * words, returns <tt>true</tt> if <tt>next</tt> would return
an element
-     * rather than throwing an exception.)
-     *
-     * @return <tt>true</tt> if the iterator has more elements.
-     */
-    public boolean hasNext() {
-        return (next != null);
-    }
-
-    /**
-     * Fetches the next Event from the collection of events
-     * passed in the constructor of <code>FilteredEventIterator</code>
-     * that is allowed by the {@link EventFilter}.
-     */
-    private void fetchNext() {
-        EventState state;
-        next = null;
-        while (next == null && actualEvents.hasNext()) {
-            state = (EventState) actualEvents.next();
-            // check denied set
-            if (denied == null || !denied.contains(state.getTargetId())) {
-                try {
-                    next = filter.blocks(state) ? null : new EventImpl(
-                            filter.getSession(), state, timestamp, userData);
-                } catch (RepositoryException e) {
-                    log.error("Exception while applying filter.", e);
-                }
-            }
-        }
-    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationManagerImpl.java?rev=1000867&r1=1000866&r2=1000867&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/ObservationManagerImpl.java
Fri Sep 24 13:40:55 2010
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.observation;
 
-import org.apache.jackrabbit.core.ItemManager;
 import org.apache.jackrabbit.core.SessionImpl;
 import org.apache.jackrabbit.core.id.NodeId;
 import org.apache.jackrabbit.core.cluster.ClusterNode;
@@ -55,11 +54,6 @@ public class ObservationManagerImpl impl
     private final SessionImpl session;
 
     /**
-     * The <code>ItemManager</code> for this <code>ObservationManager</code>.
-     */
-    private final ItemManager itemMgr;
-
-    /**
      * The cluster node where this session is running.
      */
     private final ClusterNode clusterNode;
@@ -92,20 +86,16 @@ public class ObservationManagerImpl impl
      */
     public ObservationManagerImpl(
             ObservationDispatcher dispatcher, SessionImpl session,
-            ItemManager itemMgr, ClusterNode clusterNode) {
+            ClusterNode clusterNode) {
         if (dispatcher == null) {
             throw new NullPointerException("dispatcher");
         }
         if (session == null) {
             throw new NullPointerException("session");
         }
-        if (itemMgr == null) {
-            throw new NullPointerException("itemMgr");
-        }
-        
+
         this.dispatcher = dispatcher;
         this.session = session;
-        this.itemMgr = itemMgr;
         this.clusterNode = clusterNode;
     }
 
@@ -230,8 +220,8 @@ public class ObservationManagerImpl impl
             }
         }
         // create filter
-        return new EventFilter(itemMgr, session, eventTypes, path,
-                isDeep, ids, nodeTypes, noLocal);
+        return new EventFilter(
+                session, eventTypes, path, isDeep, ids, nodeTypes, noLocal);
     }
 
     /**
@@ -267,7 +257,7 @@ public class ObservationManagerImpl impl
         EventFilter filter = createEventFilter(
                 eventTypes, absPath, isDeep, uuid, nodeTypeName, false);
         return new EventJournalImpl(
-                filter, clusterNode.getJournal(), clusterNode.getId());
+                filter, clusterNode.getJournal(), clusterNode.getId(), session);
     }
 
     /**



Mime
View raw message