jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1503737 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: RepositoryImpl.java SessionImpl.java delegate/SessionDelegate.java delegate/SessionOperation.java
Date Tue, 16 Jul 2013 14:48:01 GMT
Author: mduerig
Date: Tue Jul 16 14:48:00 2013
New Revision: 1503737

URL: http://svn.apache.org/r1503737
Log:
OAK-803 Backwards compatibility of long-lived sessions
log warnings for access to long lived sessions that are not set to "never refresh"

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java?rev=1503737&r1=1503736&r2=1503737&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
Tue Jul 16 14:48:00 2013
@@ -18,6 +18,8 @@ package org.apache.jackrabbit.oak.jcr;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
+import java.util.concurrent.TimeUnit;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import javax.jcr.Credentials;
@@ -46,6 +48,9 @@ public class RepositoryImpl implements R
      */
     private static final Logger log = LoggerFactory.getLogger(RepositoryImpl.class);
 
+    // TODO implement auto refresh configuration. See OAK-803, OAK-88
+    private static final long AUTO_REFRESH_INTERVAL = TimeUnit.SECONDS.toMillis(1);
+
     private final Descriptors descriptors = new Descriptors(new SimpleValueFactory());
     private final ContentRepository contentRepository;
     private final Whiteboard whiteboard;
@@ -125,7 +130,7 @@ public class RepositoryImpl implements R
             ContentSession contentSession =
                     contentRepository.login(credentials, workspaceName);
             SessionContext context = new SessionContext(
-                    this, whiteboard, new SessionDelegate(contentSession));
+                    this, whiteboard, new SessionDelegate(contentSession, AUTO_REFRESH_INTERVAL));
             return context.getSession();
         } catch (LoginException e) {
             throw new javax.jcr.LoginException(e.getMessage(), e);

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1503737&r1=1503736&r2=1503737&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Tue Jul 16 14:48:00 2013
@@ -395,6 +395,11 @@ public class SessionImpl implements Jack
                 sessionContext.refresh();
                 return null;
             }
+
+            @Override
+            public boolean isRefresh() {
+                return true;
+            }
         });
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1503737&r1=1503736&r2=1503737&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
Tue Jul 16 14:48:00 2013
@@ -17,9 +17,10 @@
 package org.apache.jackrabbit.oak.jcr.delegate;
 
 import static com.google.common.base.Preconditions.checkNotNull;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static java.util.concurrent.TimeUnit.MINUTES;
 
 import java.io.IOException;
-import java.util.concurrent.TimeUnit;
 
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
@@ -51,16 +52,13 @@ import org.slf4j.LoggerFactory;
  * TODO document
  */
 public class SessionDelegate {
-
     static final Logger log = LoggerFactory.getLogger(SessionDelegate.class);
 
-    // TODO implement auto refresh configuration. See OAK-803, OAK-88
-    private static final long AUTO_REFRESH_INTERVAL =
-            TimeUnit.SECONDS.toMillis(1);
-
     private final ContentSession contentSession;
+    private final long refreshInterval;
     private final Root root;
     private final IdentifierManager idManager;
+    private final Exception initStackTrace;
 
     private boolean isAlive = true;
     private int sessionOpCount;
@@ -68,10 +66,19 @@ public class SessionDelegate {
 
     private long lastAccessed = System.currentTimeMillis();
 
-    public SessionDelegate(@Nonnull ContentSession contentSession) {
+    /**
+     * Create a new session delegate for a {@code ContentSession}. The refresh behaviour
of the
+     * session is governed by the value of the {@code refreshInterval} argument: if the session
+     * has been idle longer than that value, an implicit refresh will take place.
+     * @param contentSession  the content session
+     * @param refreshInterval  refresh interval in seconds or {@code -1} for never.
+     */
+    public SessionDelegate(@Nonnull ContentSession contentSession, long refreshInterval)
{
         this.contentSession = checkNotNull(contentSession);
+        this.refreshInterval = refreshInterval;
         this.root = contentSession.getLatestRoot();
         this.idManager = new IdentifierManager(root);
+        this.initStackTrace = new Exception("The session was created here:");
     }
 
     public synchronized void refreshAtNextAccess() {
@@ -95,12 +102,24 @@ public class SessionDelegate {
         if (sessionOpCount == 0) {
             // Refresh and checks only for non re-entrant session operations
             long now = System.currentTimeMillis();
-            if (now > lastAccessed + AUTO_REFRESH_INTERVAL) {
-                refresh(true);
-                updateCount++;
+            long timeElapsed = now - lastAccessed;
+            if (!sessionOperation.isRefresh()) {
+                // Don't refresh if this operation is a refresh operation itself
+                if (refreshInterval > 0 && timeElapsed > MILLISECONDS.convert(1,
MINUTES)) {
+                    // Warn if the refresh interval is neither zero nor never (-1) and this
+                    // session has been idle too long
+                    log.warn("This session has been idle for " + MINUTES.convert(timeElapsed,
MILLISECONDS) +
+                            " minutes and might be out of date. Consider using a fresh session
or explicitly" +
+                            " refresh the session.", initStackTrace);
+                }
+                if (refreshInterval != -1 && timeElapsed >= refreshInterval) {
+                    // Refresh if the refresh interval is not never (-1) and the session
+                    // has been idle too long
+                    refresh(true);
+                    updateCount++;
+                }
             }
             lastAccessed = now;
-
             sessionOperation.checkPreconditions();
         }
         try {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java?rev=1503737&r1=1503736&r2=1503737&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperation.java
Tue Jul 16 14:48:00 2013
@@ -43,6 +43,14 @@ public abstract class SessionOperation<T
         return update;
     }
 
+    /**
+     * Return {@code true} if this operation refreshed the transient space
+     * @return
+     */
+    public boolean isRefresh() {
+        return false;
+    }
+
     protected void checkPreconditions() throws RepositoryException {}
     protected abstract T perform() throws RepositoryException;
 



Mime
View raw message