Author: mduerig
Date: Mon May 23 15:47:25 2016
New Revision: 1745222

URL: http://svn.apache.org/viewvc?rev=1745222&view=rev
Log:
OAK-4373: Refactor SegmentTracker
- Javadoc for SegmentId
- Fix memoisation in getSegment

Modified:
    
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentId.java

Modified: 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentId.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentId.java?rev=1745222&r1=1745221&r2=1745222&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentId.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/SegmentId.java
 Mon May 23 15:47:25 2016
@@ -92,15 +92,21 @@ public class SegmentId implements Compar
         return lsb;
     }
 
+    /**
+     * Get the segment identified by this instance. The segment is memoised in 
this instance's
+     * {@link #segment} field.
+     * @return  the segment identified by this instance.
+     * @see #loaded(Segment)
+     * @see #unloaded()
+     */
+    @Nonnull
     public Segment getSegment() {
-        Segment segment = this.segment;
         if (segment == null) {
             synchronized (this) {
-                segment = this.segment;
                 if (segment == null) {
                     try {
                         log.debug("Loading segment {}", this);
-                        segment = store.readSegment(this);
+                        this.segment = store.readSegment(this);
                     } catch (SegmentNotFoundException snfe) {
                         long delta = System.currentTimeMillis() - creationTime;
                         log.error("Segment not found: {}. Creation date delta 
is {} ms.",
@@ -113,14 +119,32 @@ public class SegmentId implements Compar
         return segment;
     }
 
+    /**
+     * This method should only be called from lower level caches to notify 
this instance that the
+     * passed {@code segment} has been loaded and should be memoised.
+     * @param segment  segment with this id. If the id doesn't match the 
behaviour is undefined.
+     * @see #getSegment()
+     * @see #unloaded()
+     */
     void loaded(@Nonnull Segment segment) {
         this.segment = segment;
     }
 
+    /**
+     * This method should only be called from lower level caches to notify 
this instance that the
+     * passed {@code segment} has been unloaded and should no longer be 
memoised.
+     * @see #getSegment()
+     * @see #loaded(Segment)
+     */
     void unloaded() {
         this.segment = null;
     }
 
+    /**
+     * Determine whether this instance belongs to the passed {@code store}
+     * @param store
+     * @return  {@code true} iff this instance belongs to {@code store}
+     */
     public boolean sameStore(@Nonnull SegmentStore store) {
         return this.store == store;
     }


Reply via email to