diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java index be07777c1a..2ea1b41711 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/repository/RepositoryImpl.java @@ -22,7 +22,6 @@ import static java.util.Collections.singletonMap; import static org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils.registerMBean; import java.io.Closeable; -import java.util.List; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ScheduledExecutorService; @@ -40,7 +39,6 @@ import javax.jcr.SimpleCredentials; import javax.jcr.Value; import javax.security.auth.login.LoginException; -import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; import org.apache.commons.io.IOUtils; @@ -62,7 +60,6 @@ import org.apache.jackrabbit.oak.spi.gc.GCMonitor; import org.apache.jackrabbit.oak.spi.mount.MountInfoProvider; import org.apache.jackrabbit.oak.spi.security.SecurityProvider; import org.apache.jackrabbit.oak.spi.whiteboard.Registration; -import org.apache.jackrabbit.oak.spi.whiteboard.Tracker; import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard; import org.apache.jackrabbit.oak.spi.whiteboard.WhiteboardUtils; import org.apache.jackrabbit.oak.stats.Clock; @@ -279,18 +276,12 @@ public class RepositoryImpl implements JackrabbitRepository { throw new RepositoryException("Duplicate attribute '" + REFRESH_INTERVAL + "'."); } boolean relaxedLocking = getRelaxedLocking(attributes); - - RefreshPredicate predicate = new RefreshPredicate(); - RefreshStrategy refreshStrategy = refreshInterval == null - ? new RefreshStrategy.ConditionalRefreshStrategy(new RefreshStrategy.LogOnce(60), predicate) - : new RefreshStrategy.Timed(refreshInterval); ContentSession contentSession = contentRepository.login(credentials, workspaceName); - SessionDelegate sessionDelegate = createSessionDelegate(refreshStrategy, contentSession); + SessionDelegate sessionDelegate = createSessionDelegate(refreshInterval, contentSession); SessionContext context = createSessionContext( statisticManager, securityProvider, createAttributes(refreshInterval, relaxedLocking), sessionDelegate, observationQueueLength, commitRateLimiter); - predicate.setSessionContext(context); return context.getSession(); } catch (LoginException e) { throw new javax.jcr.LoginException(e.getMessage(), e); @@ -298,11 +289,16 @@ public class RepositoryImpl implements JackrabbitRepository { } private SessionDelegate createSessionDelegate( - RefreshStrategy refreshStrategy, + Long refreshInterval, ContentSession contentSession) { + RefreshStrategy refreshStrategy; final RefreshOnGC refreshOnGC = new RefreshOnGC(gcMonitor); - refreshStrategy = Composite.create(refreshStrategy, refreshOnGC); + if (refreshInterval == null) { + refreshStrategy = refreshOnGC; + } else { + refreshStrategy = Composite.create(new RefreshStrategy.Timed(refreshInterval), refreshOnGC); + } return new SessionDelegate( contentSession, securityProvider, refreshStrategy, @@ -514,26 +510,6 @@ public class RepositoryImpl implements JackrabbitRepository { } } - /** - * Predicate which ensures that refresh strategy is invoked only - * if there is no event listeners registered with the session - */ - private static class RefreshPredicate implements Predicate{ - private SessionContext sessionContext; - - @Override - public boolean apply(@Nullable Long input) { - if (sessionContext == null){ - return true; - } - return !sessionContext.hasEventListeners(); - } - - public void setSessionContext(SessionContext sessionContext) { - this.sessionContext = sessionContext; - } - } - private static class RegistrationTask implements Runnable { private final SessionStats sessionStats; private final Whiteboard whiteboard; diff --git a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java index 1c941ad66e..96c637413d 100644 --- a/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java +++ b/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/RefreshStrategy.java @@ -20,14 +20,10 @@ package org.apache.jackrabbit.oak.jcr.session; import static com.google.common.collect.Lists.newArrayList; import static java.util.Arrays.asList; -import static java.util.concurrent.TimeUnit.MINUTES; -import static java.util.concurrent.TimeUnit.SECONDS; import java.util.ArrayList; import com.google.common.base.Predicate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Implementations of this interface determine whether a session needs @@ -37,7 +33,6 @@ import org.slf4j.LoggerFactory; * * @see Composite * @see Timed - * @see LogOnce */ public interface RefreshStrategy { @@ -156,58 +151,6 @@ public interface RefreshStrategy { } } - /** - * This refresh strategy never refreshed the session but logs - * a warning if a session has been idle for more than a given time. - * - * TODO replace logging with JMX monitoring. See OAK-941 - */ - class LogOnce extends Timed { - - private static final Logger log = - LoggerFactory.getLogger(RefreshStrategy.class); - - private final Exception initStackTrace = - new Exception("The session was created here:"); - - private boolean warnIfIdle = true; - - /** - * @param interval Interval in seconds after which a warning is logged if there was no - * activity. - */ - public LogOnce(long interval) { - super(interval); - } - - /** - * Log once - * @param secondsSinceLastAccess seconds since last access - * @return {@code false} - */ - @Override - public boolean needsRefresh(long secondsSinceLastAccess) { - if (super.needsRefresh(secondsSinceLastAccess) && warnIfIdle) { - log.warn("This session has been idle for " - + MINUTES.convert(secondsSinceLastAccess, SECONDS) - + " minutes and might be out of date. " + - "Consider using a fresh session or explicitly refresh the session.", - initStackTrace); - } - return false; - } - - @Override - public void refreshed() { - warnIfIdle = false; - } - - @Override - public String toString() { - return "Never refresh but log warning after more than " + interval + " seconds of inactivity"; - } - } - /** * This strategy conditionally invokes the delegated strategy based on the passed predicate */