jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r724300 - in /jackrabbit/trunk/jackrabbit-core/src: main/java/org/apache/jackrabbit/core/ main/java/org/apache/jackrabbit/core/cluster/ main/java/org/apache/jackrabbit/core/nodetype/virtual/ main/java/org/apache/jackrabbit/core/observation/...
Date Mon, 08 Dec 2008 09:52:32 GMT
Author: mreutegg
Date: Mon Dec  8 01:52:31 2008
New Revision: 724300

URL: http://svn.apache.org/viewvc?rev=724300&view=rev
Log:
JCR-1904: Event user data

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/AbstractObservationTest.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/UserDataTest.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventListener.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.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/EventImpl.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/EventState.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.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
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/UpdateEventFactory.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/EventJournalTest.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
Mon Dec  8 01:52:31 2008
@@ -2098,10 +2098,11 @@
          */
         public void externalUpdate(ChangeLog external,
                                    List events,
-                                   long timestamp) throws RepositoryException {
+                                   long timestamp,
+                                   String userData) throws RepositoryException {
             try {
                 EventStateCollection esc = new EventStateCollection(
-                        getObservationDispatcher(), null, null);
+                        getObservationDispatcher(), null, null, userData);
                 esc.addAll(events);
                 esc.setTimestamp(timestamp);
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ChangeLogRecord.java
Mon Dec  8 01:52:31 2008
@@ -63,6 +63,11 @@
     static final char EVENT_IDENTIFIER = 'E';
 
     /**
+     * Identifier: USER DATA.
+     */
+    static final char USER_DATA_IDENTIFIER = 'U';
+
+    /**
      * Operation type: added.
      */
     private static final int ADDED = 1;
@@ -93,6 +98,11 @@
     private List events;
 
     /**
+     * The user data.
+     */
+    private String userData;
+
+    /**
      * First identifier read.
      */
     private int identifier;
@@ -110,14 +120,17 @@
      * @param record record
      * @param workspace workspace
      * @param timestamp when the changes for this record were persisted.
+     * @param userData the user data associated with these changes.
      */
     public ChangeLogRecord(ChangeLog changes, List events,
-                           Record record, String workspace, long timestamp) {
+                           Record record, String workspace,
+                           long timestamp, String userData) {
         super(record, workspace);
 
         this.changes = changes;
         this.events = events;
         this.timestamp = timestamp;
+        this.userData = userData;
     }
 
     /**
@@ -146,6 +159,9 @@
             case DATE_IDENTIFIER:
                 readTimestampRecord();
                 break;
+            case USER_DATA_IDENTIFIER:
+                readUserDataRecord();
+                break;
             case NODE_IDENTIFIER:
                 readNodeRecord();
                 break;
@@ -182,6 +198,15 @@
     }
 
     /**
+     * Reads the user data record.
+     *
+     * @throws JournalException if an error occurs.
+     */
+    private void readUserDataRecord() throws JournalException {
+        userData = record.readString();
+    }
+
+    /**
      * Read a node record.
      *
      * @throws JournalException if an error occurs
@@ -313,6 +338,7 @@
      */
     protected void doWrite() throws JournalException {
         writeTimestampRecord();
+        writeUserDataRecord();
         Iterator deletedStates = changes.deletedStates();
         while (deletedStates.hasNext()) {
             ItemState state = (ItemState) deletedStates.next();
@@ -359,6 +385,18 @@
     }
 
     /**
+     * Writes the user data record.
+     *
+     * @throws JournalException if an error occurs.
+     */
+    private void writeUserDataRecord() throws JournalException {
+        if (userData != null) {
+            record.writeChar(USER_DATA_IDENTIFIER);
+            record.writeString(userData);
+        }
+    }
+
+    /**
      * Write a node record
      *
      * @param operation operation
@@ -445,4 +483,13 @@
     public long getTimestamp() {
         return timestamp;
     }
+
+    /**
+     * Returns the user data.
+     *
+     * @return the user data.
+     */
+    public String getUserData() {
+        return userData;
+    }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/ClusterNode.java
Mon Dec  8 01:52:31 2008
@@ -615,7 +615,8 @@
 
             try {
                 ChangeLogRecord clr = new ChangeLogRecord(changes, events,
-                        record, workspace, update.getTimestamp());
+                        record, workspace, update.getTimestamp(),
+                        update.getUserData());
                 clr.write();
                 succeeded = true;
             } catch (JournalException e) {
@@ -849,8 +850,8 @@
             }
         }
         try {
-            listener.externalUpdate(record.getChanges(),
-                    record.getEvents(), record.getTimestamp());
+            listener.externalUpdate(record.getChanges(), record.getEvents(),
+                    record.getTimestamp(), record.getUserData());
         } catch (RepositoryException e) {
             String msg = "Unable to deliver update events: " + e.getMessage();
             log.error(msg);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/Update.java
Mon Dec  8 01:52:31 2008
@@ -64,4 +64,10 @@
      */
     long getTimestamp();
 
+    /**
+     * Returns the user data associated with this update.
+     *
+     * @return the user data associated with this update.
+     */
+    String getUserData();
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventListener.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventListener.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/cluster/UpdateEventListener.java
Mon Dec  8 01:52:31 2008
@@ -31,9 +31,10 @@
      * @param changes external changes containing only node and property ids.
      * @param events events to deliver
      * @param timestamp when the change occured.
+     * @param userData the user data associated with this update.
      * @throws RepositoryException if the update cannot be processed
      */
-    void externalUpdate(ChangeLog changes, List events, long timestamp)
+    void externalUpdate(ChangeLog changes, List events, long timestamp, String userData)
             throws RepositoryException;
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/nodetype/virtual/VirtualNodeTypeStateManager.java
Mon Dec  8 01:52:31 2008
@@ -155,7 +155,8 @@
                 NodeImpl child = root.getNode(ntName);
                 List events = new ArrayList();
                 recursiveAdd(events, root, child);
-                obsDispatcher.dispatch(events, systemSession, NODE_TYPES_PATH);
+                obsDispatcher.dispatch(events, systemSession,
+                        NODE_TYPES_PATH, null);
             }
         } catch (RepositoryException e) {
             log.error("Unable to index new nodetype: " + e.toString());
@@ -182,7 +183,8 @@
                 NodeImpl child = root.getNode(ntName);
                 List events = new ArrayList();
                 recursiveRemove(events, root, child);
-                obsDispatcher.dispatch(events, systemSession, NODE_TYPES_PATH);
+                obsDispatcher.dispatch(events, systemSession,
+                        NODE_TYPES_PATH, null);
             }
             if (virtProvider != null) {
                 // allow provider to update

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/DelegatingObservationDispatcher.java
Mon Dec  8 01:52:31 2008
@@ -25,6 +25,8 @@
 import java.util.HashSet;
 import java.util.List;
 
+import javax.jcr.RepositoryException;
+
 /**
  * This Class implements an observation dispatcher, that delegates events to
  * a set of underlying dispatchers.
@@ -73,7 +75,14 @@
      */
     public EventStateCollection createEventStateCollection(SessionImpl session,
                                                            Path pathPrefix) {
-        return new EventStateCollection(this, session, pathPrefix);
+        String userData = null;
+        try {
+            userData = ((ObservationManagerImpl) session.getWorkspace().getObservationManager()).getUserData();
+        } catch (RepositoryException e) {
+            // should never happen because this
+            // implementation supports observation
+        }
+        return new EventStateCollection(this, session, pathPrefix, userData);
     }
 
     //------------------------------------------------------< EventDispatcher >
@@ -96,7 +105,8 @@
      * {@inheritDoc}
      */
     void dispatchEvents(EventStateCollection events) {
-        dispatch(events.getEvents(), events.getSession(), events.getPathPrefix());
+        dispatch(events.getEvents(), events.getSession(),
+                events.getPathPrefix(), events.getUserData());
     }
 
     /**
@@ -107,8 +117,10 @@
      * @param eventList list of events
      * @param session current session
      * @param pathPrefix event path prefix
+     * @param userData the user data
      */
-    public void dispatch(List eventList, SessionImpl session, Path pathPrefix) {
+    public void dispatch(List eventList, SessionImpl session,
+                         Path pathPrefix, String userData) {
         ObservationDispatcher[] disp;
         synchronized (dispatchers) {
             disp = (ObservationDispatcher[]) dispatchers.toArray(
@@ -116,7 +128,8 @@
         }
         for (int i = 0; i < disp.length; i++) {
             EventStateCollection events =
-                    new EventStateCollection(disp[i], session, pathPrefix);
+                    new EventStateCollection(disp[i], session,
+                            pathPrefix, userData);
             try {
                 events.addAll(eventList);
                 events.prepare();

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=724300&r1=724299&r2=724300&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
Mon Dec  8 01:52:31 2008
@@ -239,7 +239,7 @@
         }
         // check if filtered iterator has at least one event
         EventIterator it = new FilteredEventIterator(events.iterator(),
-                events.getTimestamp(), filter, denied);
+                events.getTimestamp(), events.getUserData(), filter, denied);
         if (it.hasNext()) {
             listener.onEvent(it);
         } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventImpl.java
Mon Dec  8 01:52:31 2008
@@ -55,6 +55,11 @@
     private final long timestamp;
 
     /**
+     * The user data associated with this event.
+     */
+    private final String userData;
+
+    /**
      * Cached String value of this <code>Event</code> instance.
      */
     private String stringValue;
@@ -67,11 +72,14 @@
      *                   where this <code>Event</code> will be delivered to.
      * @param eventState the underlying <code>EventState</code>.
      * @param timestamp  the time when the change occured that caused this event.
+     * @param userData   the user data associated with this event.
      */
-    EventImpl(SessionImpl session, EventState eventState, long timestamp) {
+    EventImpl(SessionImpl session, EventState eventState,
+              long timestamp, String userData) {
         this.session = session;
         this.eventState = eventState;
         this.timestamp = timestamp;
+        this.userData = userData;
     }
 
     //---------------------------------------------------------------< Event >
@@ -104,6 +112,13 @@
         return timestamp;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public String getUserData() {
+        return userData;
+    }
+
     //-----------------------------------------------------------< EventImpl >
 
     /**
@@ -177,6 +192,8 @@
             }
             sb.append(", ").append(EventState.valueOf(getType())).append(": ");
             sb.append(", UserId: ").append(getUserID());
+            sb.append(", Timestamp: ").append(timestamp);
+            sb.append(", UserData: ").append(userData);
             stringValue = sb.toString();
         }
         return stringValue;
@@ -186,7 +203,11 @@
      * @see Object#hashCode()
      */
     public int hashCode() {
-        return eventState.hashCode() ^ session.hashCode();
+        int h = eventState.hashCode() ^ new Long(timestamp).hashCode() ^ session.hashCode();
+        if (userData != null) {
+            h = h ^ userData.hashCode();
+        }
+        return h;
     }
 
     /**
@@ -209,8 +230,26 @@
         if (obj instanceof EventImpl) {
             EventImpl other = (EventImpl) obj;
             return this.eventState.equals(other.eventState)
-                    && this.session.equals(other.session);
+                    && this.session.equals(other.session)
+                    && this.timestamp == other.timestamp
+                    && equals(this.userData, other.userData);
         }
         return false;
     }
+
+    /**
+     * Returns <code>true</code> if the objects are equal or both are
+     * <code>null</code>; otherwise returns <code>false</code>.
+     *
+     * @param o1 an object.
+     * @param o2 another object.
+     * @return <code>true</code> if equal; <code>false</code> otherwise.
+     */
+    private static boolean equals(Object o1, Object o2) {
+        if (o1 == null) {
+            return o2 == null;
+        } else {
+            return o1.equals(o2);
+        }
+    }
 }

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=724300&r1=724299&r2=724300&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
Mon Dec  8 01:52:31 2008
@@ -270,7 +270,7 @@
             List events = record.getEvents();
             if (!events.isEmpty()) {
                 EventBundle bundle = new EventBundle(events,
-                        record.getTimestamp(), filter);
+                        record.getTimestamp(), record.getUserData(), filter);
                 if (bundle.events.hasNext()) {
                     // only queue bundle if there is an event
                     eventBundleBuffer.add(bundle);
@@ -400,13 +400,15 @@
          *
          * @param eventStates the {@link EventState}s that belong to this bundle.
          * @param timestamp the timestamp when the events were created.
+         * @param userData the user data associated with this event.
          * @param filter the event filter.
          */
         private EventBundle(List eventStates,
                             long timestamp,
+                            String userData,
                             EventFilter filter) {
             this.events = new FilteredEventIterator(eventStates.iterator(),
-                    timestamp, filter, Collections.EMPTY_SET);
+                    timestamp, userData, filter, Collections.EMPTY_SET);
             this.timestamp = timestamp;
         }
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventState.java
Mon Dec  8 01:52:31 2008
@@ -633,7 +633,7 @@
         } else if (eventType == Event.PROPERTY_ADDED) {
             return "PropertyAdded";
         } else if (eventType == Event.PROPERTY_CHANGED) {
-            return "PropertyOperation";
+            return "PropertyChanged";
         } else if (eventType == Event.PROPERTY_REMOVED) {
             return "PropertyRemoved";
         } else {

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/observation/EventStateCollection.java
Mon Dec  8 01:52:31 2008
@@ -93,6 +93,11 @@
     private long timestamp = System.currentTimeMillis();
 
     /**
+     * The user data attached to this event state collection.
+     */
+    private String userData;
+
+    /**
      * Creates a new empty <code>EventStateCollection</code>.
      * <p/>
      * Because the item state manager in {@link #createEventStates} may represent
@@ -104,13 +109,16 @@
      * @param session    the session that created these events.
      * @param pathPrefix the path to prefix the event paths or <code>null</code>
      *                   if no prefix should be used.
+     * @param userData   the user data attached to this event state collection.
      */
     public EventStateCollection(EventDispatcher dispatcher,
                                 SessionImpl session,
-                                Path pathPrefix) {
+                                Path pathPrefix,
+                                String userData) {
         this.dispatcher = dispatcher;
         this.session = session;
         this.pathPrefix = pathPrefix;
+        this.userData = userData;
     }
 
     /**
@@ -480,6 +488,24 @@
     }
 
     /**
+     * @return the user data attached to this event state collection.
+     */
+    public String getUserData() {
+        return userData;
+    }
+
+    /**
+     * Sets the user data for this event state collection.
+     *
+     * @param userData the user data.
+     */
+    public void setUserData(String userData) {
+        this.userData = userData;
+    }
+
+    //----------------------------< internal >----------------------------------
+
+    /**
      * Resolves the node type name in <code>node</code> into a {@link javax.jcr.nodetype.NodeType}
      * object using the {@link javax.jcr.nodetype.NodeTypeManager} of <code>session</code>.
      *

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=724300&r1=724299&r2=724300&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
Mon Dec  8 01:52:31 2008
@@ -68,10 +68,16 @@
     private long timestamp;
 
     /**
+     * The user data associated with these events.
+     */
+    private final String userData;
+
+    /**
      * Creates a new <code>FilteredEventIterator</code>.
      *
      * @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
@@ -80,12 +86,14 @@
      */
     public FilteredEventIterator(Iterator eventStates,
                                  long timestamp,
+                                 String userData,
                                  EventFilter filter,
                                  Set denied) {
         this.actualEvents = eventStates;
         this.filter = filter;
         this.denied = denied;
         this.timestamp = timestamp;
+        this.userData = userData;
         fetchNext();
     }
 
@@ -167,7 +175,7 @@
             if (denied == null || !denied.contains(state.getTargetId())) {
                 try {
                     next = filter.blocks(state) ? null : new EventImpl(
-                            filter.getSession(), state, timestamp);
+                            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=724300&r1=724299&r2=724300&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
Mon Dec  8 01:52:31 2008
@@ -59,6 +59,11 @@
      */
     private final ObservationDispatcher dispatcher;
 
+    /**
+     * The currently set user data.
+     */
+    private String userData;
+
     static {
         // preload EventListenerIteratorImpl to prevent classloader issues during shutdown
         EventListenerIteratorImpl.class.hashCode();
@@ -131,6 +136,20 @@
     }
 
     /**
+     * {@inheritDoc}
+     */
+    public void setUserData(String userData) throws RepositoryException {
+        this.userData = userData;
+    }
+
+    /**
+     * @return the currently set user data.
+     */
+    String getUserData() {
+        return userData;
+    }
+
+    /**
      * Unregisters all EventListeners.
      */
     public void dispose() {
@@ -210,6 +229,6 @@
      * which is attached to this <code>ObservationManager</code> instance.
      */
     public EventStateCollection createEventStateCollection() {
-        return new EventStateCollection(dispatcher, session, null);
+        return new EventStateCollection(dispatcher, session, null, userData);
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/SharedItemStateManager.java
Mon Dec  8 01:52:31 2008
@@ -846,6 +846,10 @@
             return timestamp;
         }
 
+        public String getUserData() {
+            return events.getUserData();
+        }
+
         /**
          * Updates the target node references collections based on the
          * modifications in the change log (i.e. added/removed/modified

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionManagerImpl.java
Mon Dec  8 01:52:31 2008
@@ -494,11 +494,13 @@
     /**
      * {@inheritDoc}
      */
-    public void externalUpdate(ChangeLog changes, List events, long timestamp)
+    public void externalUpdate(ChangeLog changes, List events,
+                               long timestamp, String userData)
             throws RepositoryException {
         EventStateCollection esc = getEscFactory().createEventStateCollection(null);
         esc.addAll(events);
         esc.setTimestamp(timestamp);
+        esc.setUserData(userData);
 
         sharedStateMgr.externalUpdate(changes, esc);
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/SimpleEventListener.java
Mon Dec  8 01:52:31 2008
@@ -412,10 +412,11 @@
     /**
      * {@inheritDoc}
      */
-    public void externalUpdate(ChangeLog changes, List events, long timestamp)
+    public void externalUpdate(ChangeLog changes, List events,
+                               long timestamp, String userData)
             throws RepositoryException {
 
-        clusterEvents.add(new UpdateEvent(changes, events, timestamp));
+        clusterEvents.add(new UpdateEvent(changes, events, timestamp, userData));
 
     }
 
@@ -445,16 +446,24 @@
         private final long timestamp;
 
         /**
+         * The user data associated with this update.
+         */
+        private final String userData;
+
+        /**
          * Create a new instance of this class.
          *
          * @param changes change log
          * @param events list of <code>EventState</code>s
          * @param timestamp time when the changes in this event occured.
+         * @param userData the user data associated with this update.
          */
-        public UpdateEvent(ChangeLog changes, List events, long timestamp) {
+        public UpdateEvent(ChangeLog changes, List events,
+                           long timestamp, String userData) {
             this.changes = changes;
             this.events = events;
             this.timestamp = timestamp;
+            this.userData = userData;
         }
 
         /**
@@ -482,6 +491,10 @@
             return timestamp;
         }
 
+        public String getUserData() {
+            return userData;
+        }
+
         /**
          * {@inheritDoc}
          */
@@ -500,7 +513,11 @@
          * {@inheritDoc}
          */
         public int hashCode() {
-            return changes.hashCode() ^ events.hashCode() ^ (int) (timestamp ^ (timestamp
>>> 32));
+            int h = changes.hashCode() ^ events.hashCode() ^ (int) (timestamp ^ (timestamp
>>> 32));
+            if (userData != null) {
+                h = h ^ userData.hashCode();
+            }
+            return h;
         }
 
         /**
@@ -511,7 +528,8 @@
                 UpdateEvent other = (UpdateEvent) obj;
                 return SimpleEventListener.equals(changes, other.changes) &&
                     SimpleEventListener.equals(events, other.events) &&
-                    timestamp == other.timestamp;
+                    timestamp == other.timestamp &&
+                    SimpleEventListener.equals(userData, other.userData);
             }
             return false;
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/UpdateEventFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/UpdateEventFactory.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/UpdateEventFactory.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/cluster/UpdateEventFactory.java
Mon Dec  8 01:52:31 2008
@@ -116,7 +116,7 @@
         events.add(createEventState(p2, n2, Event.PROPERTY_REMOVED));
         events.add(createEventState(n3, Event.NODE_REMOVED, "{}n3"));
 
-        return new UpdateEvent(changes, events, System.currentTimeMillis());
+        return new UpdateEvent(changes, events, System.currentTimeMillis(), "user-data");
     }
 
 

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/AbstractObservationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/AbstractObservationTest.java?rev=724300&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/AbstractObservationTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/AbstractObservationTest.java
Mon Dec  8 01:52:31 2008
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.observation;
+
+import javax.jcr.observation.Event;
+
+/**
+ * <code>AbstractObservationTest</code> is a base class with utility methods
+ * for observation related tests.
+ */
+public class AbstractObservationTest extends org.apache.jackrabbit.test.api.observation.AbstractObservationTest
{
+
+    protected static final int ALL_TYPES = Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED
| Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
+
+    /**
+     * @return the observation manager implementation.
+     */
+    protected ObservationManagerImpl getObservationManager() {
+        // TODO: remove when JCR 2.0 is final
+        return (ObservationManagerImpl) obsMgr;
+    }
+
+    /**
+     * Returns the user data for the given <code>event</code>.
+     *
+     * @param e the event.
+     * @return the user data for the given <code>event</code>.
+     */
+    protected static String getUserData(Event e) {
+        // TODO: remove when JCR 2.0 is final
+        return ((EventImpl) e).getUserData();
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/AbstractObservationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/EventJournalTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/EventJournalTest.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/EventJournalTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/EventJournalTest.java
Mon Dec  8 01:52:31 2008
@@ -25,16 +25,13 @@
 import javax.jcr.Session;
 import javax.jcr.observation.Event;
 
-import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.core.WorkspaceImpl;
 import org.apache.jackrabbit.api.jsr283.observation.EventJournal;
 
 /**
  * <code>EventJournalTest</code> performs EventJournal tests.
  */
-public class EventJournalTest extends AbstractJCRTest {
-
-    private static final int ALL_TYPES = Event.NODE_ADDED | Event.NODE_REMOVED | Event.PROPERTY_ADDED
| Event.PROPERTY_CHANGED | Event.PROPERTY_REMOVED;
+public class EventJournalTest extends AbstractObservationTest {
 
     private EventJournal journal;
 
@@ -178,6 +175,20 @@
         checkJournal(new String[]{n2.getPath()}, new String[]{n1.getPath()});
     }
 
+    public void testUserData() throws RepositoryException {
+        testRootNode.addNode(nodeName1);
+        String data = createRandomString(5);
+        getObservationManager().setUserData(data);
+
+        journal = getEventJournal(ALL_TYPES, testRoot, true, null, null);
+        journal.skipTo(System.currentTimeMillis());
+
+        superuser.save();
+
+        assertTrue("no more events", journal.hasNext());
+        assertEquals("Wrong user data", data, getUserData(journal.nextEvent()));
+    }
+
     //-------------------------------< internal >-------------------------------
 
     private EventJournal getEventJournal(int eventTypes,
@@ -186,6 +197,7 @@
                                         String[] uuid,
                                         String[] nodeTypeName)
             throws RepositoryException {
+        // TODO: remove cast when JCR 2.0 is final
         return ((WorkspaceImpl) superuser.getWorkspace()).getEventJournal(
                 eventTypes, absPath, isDeep, uuid, nodeTypeName);
     }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java?rev=724300&r1=724299&r2=724300&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/TestAll.java
Mon Dec  8 01:52:31 2008
@@ -41,6 +41,7 @@
         suite.addTestSuite(VersionEventsTest.class);
         suite.addTestSuite(MoveInPlaceTest.class);
         suite.addTestSuite(EventJournalTest.class);
+        suite.addTestSuite(UserDataTest.class);
 
         return suite;
     }

Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/UserDataTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/UserDataTest.java?rev=724300&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/UserDataTest.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/UserDataTest.java
Mon Dec  8 01:52:31 2008
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.core.observation;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+import javax.jcr.observation.Event;
+
+import org.apache.jackrabbit.test.api.observation.EventResult;
+
+/**
+ * <code>UserDataTest</code>...
+ */
+public class UserDataTest extends AbstractObservationTest {
+
+    public void testSave() throws RepositoryException {
+        runWithUserData(new Callable() {
+            public void call() throws RepositoryException {
+                testRootNode.addNode(nodeName1, testNodeType);
+                testRootNode.save();
+            }
+        }, ALL_TYPES);
+    }
+
+    public void testWorkspaceOperation() throws RepositoryException {
+        testRootNode.addNode(nodeName1);
+        testRootNode.save();
+
+        runWithUserData(new Callable() {
+            public void call() throws RepositoryException {
+                String src = testRoot + "/" + nodeName1;
+                String dest = testRoot + "/" + nodeName2;
+                superuser.getWorkspace().move(src, dest);
+            }
+        }, ALL_TYPES);
+    }
+
+    public void testVersioning() throws RepositoryException {
+        final Node n1 = testRootNode.addNode(nodeName1);
+        n1.addMixin(mixVersionable);
+        testRootNode.save();
+
+        runWithUserData(new Callable() {
+            public void call() throws RepositoryException {
+                n1.checkin();
+            }
+        }, Event.NODE_ADDED); // get events for added version node
+    }
+
+    protected void runWithUserData(Callable c, int eventTypes)
+            throws RepositoryException {
+        EventResult result = new EventResult(log);
+        addEventListener(result, eventTypes);
+        String data = createRandomString(5);
+        getObservationManager().setUserData(data);
+
+        c.call();
+
+        removeEventListener(result);
+
+        Event[] events = result.getEvents(DEFAULT_WAIT_TIMEOUT);
+        assertTrue("no events returned", events.length > 0);
+        for (int i = 0; i < events.length; i++) {
+            assertEquals("Wrong user data", data, getUserData(events[i]));
+        }
+    }
+
+    public interface Callable {
+
+        public void call() throws RepositoryException;
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/observation/UserDataTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message