Author: chetanm
Date: Thu Nov 24 14:00:39 2016
New Revision: 1771129

URL: http://svn.apache.org/viewvc?rev=1771129&view=rev
Log:
OAK-4898 - Allow for external changes to have a CommitInfo attached

-- Add external flag to CommitInfo
-- Update the javadocs for Observer and mark CommitInfo as NonNull param

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Observer.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java?rev=1771129&r1=1771128&r2=1771129&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CommitInfo.java
 Thu Nov 24 14:00:39 2016
@@ -45,6 +45,13 @@ public final class CommitInfo {
     public static final CommitInfo EMPTY =
             new CommitInfo(OAK_UNKNOWN, OAK_UNKNOWN);
 
+    /**
+     * Empty commit information object to be used for <b>external changes</b>. 
Used as a dummy object when no
+     * metadata is known (or needed) about a commit.
+     */
+    public static final CommitInfo EMPTY_EXTERNAL =
+            new CommitInfo(OAK_UNKNOWN, OAK_UNKNOWN, Collections.<String, 
Object>emptyMap(), true);
+
     private final String sessionId;
 
     private final String userId;
@@ -53,6 +60,8 @@ public final class CommitInfo {
 
     private final Map<String, Object> info;
 
+    private final boolean external;
+
     /**
      * Creates a commit info for the given session and user.
      *
@@ -72,9 +81,21 @@ public final class CommitInfo {
      * @param info info map
      */
     public CommitInfo(@Nonnull String sessionId, @Nullable String userId, 
Map<String, Object> info) {
+        this(sessionId, userId, info, false);
+    }
+
+    /**
+     * Creates a commit info for the given session and user and info map.
+     *  @param sessionId session identifier
+     * @param userId The user id.
+     * @param info info map
+     * @param external indicates if the commit info is from external change
+     */
+    public CommitInfo(@Nonnull String sessionId, @Nullable String userId, 
Map<String, Object> info, boolean external) {
         this.sessionId = checkNotNull(sessionId);
         this.userId = (userId == null) ? OAK_UNKNOWN : userId;
         this.info = checkNotNull(info);
+        this.external = external;
     }
 
     /**
@@ -101,6 +122,18 @@ public final class CommitInfo {
     }
 
     /**
+     * Return a flag indicating whether this is commit info is
+     * for an external change
+     *
+     * @return true if commit info is for an external change
+     */
+    public boolean isExternal() {
+        return external;
+    }
+
+    /**
+
+    /**
      * Returns the base path of this commit. All changes within this commit
      * are expected to be located within the returned path. By default this
      * is the root path, but a particular commit can declare a more specific
@@ -135,6 +168,7 @@ public final class CommitInfo {
             return sessionId.equals(that.sessionId)
                     && userId.equals(that.userId)
                     && this.date == that.date
+                    && this.external == that.external
                     && info.equals(that.info);
         } else {
             return false;
@@ -143,7 +177,7 @@ public final class CommitInfo {
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(sessionId, userId, date, info);
+        return Objects.hashCode(sessionId, userId, date, info, external);
     }
 
     @Override
@@ -151,6 +185,7 @@ public final class CommitInfo {
         return toStringHelper(this).omitNullValues()
                 .add("sessionId", sessionId)
                 .add("userId", userId)
+                .add("external", external)
                 .add("date", date)
                 .add("info", info)
                 .toString();

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Observer.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Observer.java?rev=1771129&r1=1771128&r2=1771129&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Observer.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/Observer.java
 Thu Nov 24 14:00:39 2016
@@ -17,7 +17,6 @@
 package org.apache.jackrabbit.oak.spi.commit;
 
 import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
 
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
@@ -37,14 +36,18 @@ import org.apache.jackrabbit.oak.spi.sta
  * is expected to keep track of the previously observed state if it wants to
  * use a content diff to determine what exactly changed between two states.
  * <p>
- * A repository may capture the optional {@link CommitInfo} instance passed
- * to a commit and make it available to observers along with the committed
- * content changes. In such cases, i.e. when the commit info argument is
+ * For local changes repository passes in a  {@link CommitInfo} instance which
+ * was used as part of commit and make it available to observers along with the
+ * committed content changes. In such cases, i.e. when the commit info 
argument is
  * non-{@code null}, the reported content change is guaranteed to contain
  * <em>only</em> changes from that specific commit (and the applied commit
  * hooks). Note that it is possible for a repository to report commit
  * information for only some commits but not others.
  * <p>
+ * For external changes repository would construct a {@link CommitInfo} 
instance
+ * which might include some metadata which can be used by observers. Such
+ * {@link CommitInfo} instances would <code>external</code> flag set to true
+ * <p>
  * It should also be noted that two observers may not necessarily see the
  * same sequence of content changes. It is also possible for an observer to
  * be notified when no actual content changes have happened therefore passing
@@ -64,8 +67,8 @@ public interface Observer {
      * information on when and how this method gets called.
      *
      * @param root root state of the repository
-     * @param info local commit information, or {@code null}
+     * @param info commit information
      */
-    void contentChanged(@Nonnull NodeState root, @Nullable CommitInfo info);
+    void contentChanged(@Nonnull NodeState root, @Nonnull CommitInfo info);
 
 }


Reply via email to