You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ch...@apache.org on 2013/08/19 15:06:15 UTC
svn commit: r1515395 - in
/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr:
RepositoryImpl.java delegate/SessionDelegate.java
delegate/SessionOperationInterceptor.java
Author: chetanm
Date: Mon Aug 19 13:06:15 2013
New Revision: 1515395
URL: http://svn.apache.org/r1515395
Log:
OAK-960 - Provide an interceptor for SessionOperations
Initial implementation
Added:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperationInterceptor.java
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/delegate/SessionDelegate.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=1515395&r1=1515394&r2=1515395&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 Mon Aug 19 13:06:15 2013
@@ -205,13 +205,15 @@ public class RepositoryImpl implements J
ContentSession contentSession = contentRepository.login(credentials, workspaceName);
SessionContext context = createSessionContext(
Collections.<String, Object>singletonMap(REFRESH_INTERVAL, refreshInterval),
- new SessionDelegate(contentSession, securityProvider, refreshInterval));
+ createSessionDelegate(contentSession, securityProvider, refreshInterval));
return context.getSession();
} catch (LoginException e) {
throw new javax.jcr.LoginException(e.getMessage(), e);
}
}
+
+
@Override
public void shutdown() {
// empty
@@ -231,6 +233,18 @@ public class RepositoryImpl implements J
return new SessionContext(this, whiteboard, attributes, delegate);
}
+ /**
+ * Factory method for creating a {@link SessionDelegate} instance for
+ * a new session. Called by {@link #login()}. Can be overridden by
+ * subclasses to customize the SessionDelegate implementation.
+ *
+ * @return session context
+ */
+ protected SessionDelegate createSessionDelegate(ContentSession contentSession, SecurityProvider securityProvider,
+ Long refreshInterval) {
+ return new SessionDelegate(contentSession,securityProvider,refreshInterval);
+ }
+
SecurityProvider getSecurityProvider() {
return securityProvider;
}
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=1515395&r1=1515394&r2=1515395&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 Mon Aug 19 13:06:15 2013
@@ -59,6 +59,7 @@ public class SessionDelegate {
private final IdentifierManager idManager;
private final Exception initStackTrace;
private final PermissionProvider permissionProvider;
+ private final SessionOperationInterceptor interceptor;
private boolean isAlive = true;
private int sessionOpCount;
@@ -68,6 +69,12 @@ public class SessionDelegate {
private boolean warnIfIdle = true;
private boolean refreshAtNextAccess = false;
+
+ public SessionDelegate(@Nonnull ContentSession contentSession, SecurityProvider securityProvider,
+ long refreshInterval) {
+ this(contentSession, securityProvider, SessionOperationInterceptor.NOOP,refreshInterval);
+ }
+
/**
* 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
@@ -80,8 +87,10 @@ public class SessionDelegate {
* @param securityProvider the security provider
* @param refreshInterval refresh interval in seconds.
*/
- public SessionDelegate(@Nonnull ContentSession contentSession, SecurityProvider securityProvider, long refreshInterval) {
+ public SessionDelegate(@Nonnull ContentSession contentSession, SecurityProvider securityProvider,
+ SessionOperationInterceptor interceptor,long refreshInterval) {
this.contentSession = checkNotNull(contentSession);
+ this.interceptor = checkNotNull(interceptor);
this.refreshInterval = MILLISECONDS.convert(refreshInterval, SECONDS);
this.root = contentSession.getLatestRoot();
this.idManager = new IdentifierManager(root);
@@ -109,6 +118,8 @@ public class SessionDelegate {
*/
public synchronized <T> T perform(SessionOperation<T> sessionOperation)
throws RepositoryException {
+
+ interceptor.before(this,sessionOperation);
// Synchronize to avoid conflicting refreshes from concurrent JCR API calls
if (sessionOpCount == 0) {
// Refresh and checks only for non re-entrant session operations
@@ -142,6 +153,7 @@ public class SessionDelegate {
if (sessionOperation.isUpdate()) {
updateCount++;
}
+ interceptor.after(this,sessionOperation);
}
}
Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperationInterceptor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperationInterceptor.java?rev=1515395&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperationInterceptor.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionOperationInterceptor.java Mon Aug 19 13:06:15 2013
@@ -0,0 +1,52 @@
+/*
+ * 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.oak.jcr.delegate;
+
+import org.apache.jackrabbit.oak.jcr.operation.SessionOperation;
+
+public interface SessionOperationInterceptor {
+ SessionOperationInterceptor NOOP = new SessionOperationInterceptor() {
+ @Override
+ public void before(SessionDelegate delegate, SessionOperation operation) {
+ }
+
+ @Override
+ public void after(SessionDelegate delegate, SessionOperation operation) {
+ }
+ };
+
+ /**
+ * Invoked before the sessionOperation is performed. SessionOperation MUST only be
+ * used for reading purpose and implementation must not invoke the {@link SessionOperation#perform}
+ *
+ * @param delegate sessionDelegate performing the operation
+ * @param operation operation to perform
+ */
+ void before(SessionDelegate delegate, SessionOperation operation);
+
+ /**
+ * Invoked after the sessionOperation is performed. SessionOperation MUST only be
+ * used for reading purpose and implementation must not invoke the {@link SessionOperation#perform}
+ *
+ * @param delegate sessionDelegate performing the operation
+ * @param operation operation to perform
+ */
+ void after(SessionDelegate delegate, SessionOperation operation);
+}