You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2010/02/01 11:47:22 UTC

svn commit: r905243 - in /sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base: ./ internal/ util/

Author: fmeschbe
Date: Mon Feb  1 10:47:21 2010
New Revision: 905243

URL: http://svn.apache.org/viewvc?rev=905243&view=rev
Log:
SLING-1283 Remove SessionPool support

Removed:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/PooledJackrabbitSession.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/PooledSession.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SessionPool.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SessionPoolFactory.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/internal/SessionPoolManager.java
Modified:
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
    sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/util/AccessControlUtil.java

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java?rev=905243&r1=905242&r2=905243&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java (original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/AbstractSlingRepository.java Mon Feb  1 10:47:21 2010
@@ -31,9 +31,6 @@
 
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
 import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.base.internal.SessionPool;
-import org.apache.sling.jcr.base.internal.SessionPoolFactory;
-import org.apache.sling.jcr.base.internal.SessionPoolManager;
 import org.apache.sling.jcr.base.internal.loader.Loader;
 import org.apache.sling.jcr.base.util.RepositoryAccessor;
 import org.osgi.framework.BundleContext;
@@ -45,13 +42,11 @@
 
 /**
  * The <code>AbstractSlingRepository</code> is an abstract implementation of
- * the {@link SlingRepository} interface which provides core support for session
- * pooling. Implementations of the <code>SlingRepository</code> interface may
- * wish to extend this class to benefit from a default implementation.
- * <p>
- * Extensions of this class will have to declare the following
- * <code>scr.property</code> tags to have them declared automatically in the
- * respective component and metatype definitions by the maven-sling-plugin:
+ * the {@link SlingRepository} interface which provides default support for
+ * attached repositories as well as ensuring live repository connection,
+ * reconnecting if needed. Implementations of the <code>SlingRepository</code>
+ * interface may wish to extend this class to benefit from a default
+ * implementation.
  *
  * @scr.component metatype="no"
  */
@@ -79,31 +74,6 @@
     /** @scr.property valueRef="DEFAULT_POLL_INACTIVE" */
     public static final String PROPERTY_POLL_INACTIVE = "poll.inactive";
 
-    /**
-     * The name of the configuration parameter containing the maximum number of
-     * seconds to wait for the number of currently active sessions to drop be
-     * low the upper limit before giving up (value is "pool.maxActiveWait").
-     *
-     * @scr.property value="1" type="Integer"
-     */
-    public static final String PROPERTY_MAX_ACTIVE_SESSIONS_WAIT = "pool.maxActiveWait";
-
-    /**
-     * The name of the configuration parameter containing the upper limit of the
-     * simultaneously active sessions (value is "pool.maxActive").
-     *
-     * @scr.property value="-1" type="Integer"
-     */
-    public static final String PROPERTY_MAX_ACTIVE_SESSIONS = "pool.maxActive";
-
-    /**
-     * The name of the configuration parameter containing the upper limit of the
-     * currently idle sessions to keep in the pool (value is "pool.maxIdle").
-     *
-     * @scr.property value="0" type="Integer"
-     */
-    public static final String PROPERTY_MAX_IDLE_SESSIONS = "pool.maxIdle";
-
     public static final String DEFAULT_ANONYMOUS_USER = "anonymous";
 
     public static final String DEFAULT_ANONYMOUS_PASS = "anonymous";
@@ -146,8 +116,6 @@
 
     private char[] adminPass;
 
-    private SessionPoolManager poolManager;
-
     private Loader loader;
 
     // the poll interval used while the repository is not active
@@ -236,7 +204,7 @@
         try {
             log(LogService.LOG_DEBUG, "login: Logging in to workspace '"
                 + workspace + "'");
-            Session session = getPoolManager().login(credentials, workspace);
+            Session session = getRepository().login(credentials, workspace);
 
             // if the defualt workspace is null, acquire a session from the pool
             // and use the workspace used as the new default workspace
@@ -255,13 +223,13 @@
             if (workspace != null
                 && workspace.equals(this.getDefaultWorkspace())
                 && this.createWorkspace(workspace)) {
-                return this.getPoolManager().login(credentials, workspace);
+                return this.getRepository().login(credentials, workspace);
             }
 
             // otherwise (any workspace) or if workspace creation fails
             // just forward the original exception
             throw nswe;
-            
+
         } catch (RuntimeException re) {
             // SLING-702: Jackrabbit throws IllegalStateException if the
             // repository has already been shut down ...
@@ -319,49 +287,6 @@
         return new String[0];
     }
 
-    // ---------- Session Pool support -----------------------------------------
-
-    protected final SessionPoolManager getPoolManager() {
-        if (this.poolManager == null) {
-            this.poolManager = new SessionPoolManager(this.getRepository(),
-                this.loader, this.getSessionPoolFactory());
-        }
-
-        return this.poolManager;
-    }
-
-    /**
-     * @return
-     */
-    protected SessionPoolFactory getSessionPoolFactory() {
-        @SuppressWarnings("unchecked")
-        Dictionary<String, Object> properties = this.componentContext.getProperties();
-        final int maxActiveSessions = this.getIntProperty(properties,
-            PROPERTY_MAX_ACTIVE_SESSIONS);
-        final int maxIdleSessions = this.getIntProperty(properties,
-            PROPERTY_MAX_IDLE_SESSIONS);
-        final int maxActiveSessionsWait = this.getIntProperty(properties,
-            PROPERTY_MAX_ACTIVE_SESSIONS_WAIT);
-        return new SessionPoolFactory() {
-
-            public SessionPool createPool(final SessionPoolManager mgr,
-                    final SimpleCredentials credentials) {
-                // create and configure the new pool
-                final SessionPool pool = createSessionPool(mgr, credentials);
-                pool.setMaxActiveSessions(maxActiveSessions);
-                pool.setMaxActiveSessionsWait(maxActiveSessionsWait);
-                pool.setMaxIdleSessions(maxIdleSessions);
-                return pool;
-            }
-        };
-    }
-
-    protected SessionPool createSessionPool(final SessionPoolManager mgr,
-            final SimpleCredentials credentials) {
-        final SessionPool pool = new SessionPool(mgr, credentials);
-        return pool;
-    }
-
     // ---------- logging ------------------------------------------------------
 
     protected void log(int level, String message) {
@@ -555,12 +480,6 @@
      * @param repository
      */
     protected void tearDown(Repository repository) {
-
-        if (this.poolManager != null) {
-            this.poolManager.dispose();
-            this.poolManager = null;
-        }
-
         if (this.loader != null) {
             this.loader.dispose();
             this.loader = null;
@@ -851,10 +770,10 @@
                     log(
                         LogService.LOG_DEBUG,
                         "pingRepository() successful but pingAndCheck() fails, calling disposeRepository()");
-                    
+
                     // drop reference
                     repository = null;
-                    
+
                 } else {
 
                     // otherwise let go of the repository and fail startup
@@ -951,7 +870,7 @@
                     if (repo == null) {
                         // No Repository yet, try to start
                         if (startRepository()) {
-                            log(LogService.LOG_INFO, "Repository started successfully"); 
+                            log(LogService.LOG_INFO, "Repository started successfully");
                             ok = true;
                             newPollTime = pollTimeActiveSeconds * MSEC;
                         } else {
@@ -962,7 +881,7 @@
                     } else if (pingAndCheck()) {
                         ok = true;
                         newPollTime = pollTimeActiveSeconds * MSEC;
-                        
+
                     } else {
                         // Repository disappeared
                         log(LogService.LOG_INFO,
@@ -970,10 +889,10 @@
                         stopRepository();
                         newPollTime = pollTimeInActiveSeconds * MSEC;
                     }
-                    
+
                     if(newPollTime != pollTimeMsec) {
                         pollTimeMsec = newPollTime;
-                        log(LogService.LOG_DEBUG, 
+                        log(LogService.LOG_DEBUG,
                                 "Repository Pinger interval set to " + pollTimeMsec + " msec, repository is "
                                 + (ok ? "available" : "NOT available")
                                 );
@@ -987,9 +906,9 @@
         } catch (Throwable t) {
             // try to log the cause for thread termination
             log(LogService.LOG_ERROR, "Repository Pinger caught unexpected issue", t);
-            
+
         } finally {
-            
+
             // whatever goes on, make sure the repository is disposed of
             // at the end of the thread....
             log(LogService.LOG_INFO, "Stopping repository on shutdown");

Modified: sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/util/AccessControlUtil.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/util/AccessControlUtil.java?rev=905243&r1=905242&r2=905243&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/util/AccessControlUtil.java (original)
+++ sling/trunk/bundles/jcr/base/src/main/java/org/apache/sling/jcr/base/util/AccessControlUtil.java Mon Feb  1 10:47:21 2010
@@ -36,14 +36,13 @@
 import org.apache.jackrabbit.api.jsr283.security.Privilege;
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.sling.jcr.base.internal.PooledSession;
 
 /**
- * A simple utility class providing utilities with respect to 
+ * A simple utility class providing utilities with respect to
  * access control over repositories.
  */
 public class AccessControlUtil {
-	
+
 	// the name of the accessor method for the AccessControlManager
     private static final String METHOD_GET_ACCESS_CONTROL_MANAGER = "getAccessControlManager";
     // the name of the accessor method for the UserManager
@@ -52,19 +51,19 @@
     private static final String METHOD_GET_PRINCIPAL_MANAGER = "getPrincipalManager";
     // the name of the JackrabbitAccessControlList method getPath
     private static final String METHOD_JACKRABBIT_ACL_GET_PATH = "getPath";
-    // the name of the JackrabbitAccessControlList method 
+    // the name of the JackrabbitAccessControlList method
     private static final String METHOD_JACKRABBIT_ACL_IS_EMPTY = "isEmpty";
-    // the name of the JackrabbitAccessControlList method 
+    // the name of the JackrabbitAccessControlList method
     private static final String METHOD_JACKRABBIT_ACL_SIZE = "size";
-    // the name of the JackrabbitAccessControlList method 
+    // the name of the JackrabbitAccessControlList method
     private static final String METHOD_JACKRABBIT_ACL_ADD_ENTRY = "addEntry";
-    // the name of the JackrabbitAccessControlEntry method 
+    // the name of the JackrabbitAccessControlEntry method
     private static final String METHOD_JACKRABBIT_ACE_IS_ALLOW = "isAllow";
 
 
-	
+
     // ---------- SessionImpl methods -----------------------------------------------------
-    
+
 	/**
      * Returns the <code>AccessControlManager</code> for the given
      * <code>session</code>. If the session does not have a
@@ -72,7 +71,7 @@
      * <code>UnsupportedRepositoryOperationException</code> is thrown. Otherwise
      * the <code>AccessControlManager</code> is returned or if the call fails,
      * the respective exception is thrown.
-     * 
+     *
      * @param session The JCR Session whose <code>AccessControlManager</code> is
      *            to be returned. If the session is a pooled session, the
      *            session underlying the pooled session is actually used.
@@ -85,16 +84,11 @@
      */
 	public static AccessControlManager getAccessControlManager(Session session)
 											throws UnsupportedRepositoryOperationException, RepositoryException {
-		 // unwrap a pooled session
-        if (session instanceof PooledSession) {
-            session = ((PooledSession) session).getSession();
-        }
-        
         return safeInvokeRepoMethod(session, METHOD_GET_ACCESS_CONTROL_MANAGER, AccessControlManager.class);
 	}
-	
+
 	// ---------- JackrabbitSession methods -----------------------------------------------
-	
+
 	/**
 	 * Returns the <code>UserManager</code> for the given
      * <code>session</code>. If the session does not have a
@@ -102,12 +96,12 @@
      * <code>UnsupportedRepositoryOperationException</code> is thrown. Otherwise
      * the <code>UserManager</code> is returned or if the call fails,
      * the respective exception is thrown.
-	 * 
+	 *
 	 * @param session  The JCR Session whose <code>UserManager</code> is
      *            to be returned. If the session is not a <code>JackrabbitSession</code>
      *            uses reflection to retrive the manager from the repository.
 	 * @return The <code>UserManager</code> of the session.
-	 * @throws AccessDeniedException If this session is not allowed 
+	 * @throws AccessDeniedException If this session is not allowed
 	 * 			  to access user data.
 	 * @throws UnsupportedRepositoryOperationException If the session has no
      *            <code>getUserManager</code> method or the exception
@@ -115,7 +109,7 @@
 	 * @throws RepositoryException Forwarded from the
      *             <code>getUserManager</code> method call.
 	 */
-	public static UserManager getUserManager(Session session) 
+	public static UserManager getUserManager(Session session)
 										throws AccessDeniedException, UnsupportedRepositoryOperationException, RepositoryException {
 		JackrabbitSession jackrabbitSession = getJackrabbitSession(session);
 		if(jackrabbitSession != null) {
@@ -124,7 +118,7 @@
 			return safeInvokeRepoMethod(session, METHOD_GET_USER_MANAGER, UserManager.class);
 		}
 	}
-	
+
 	/**
 	 * Returns the <code>PrincipalManager</code> for the given
      * <code>session</code>. If the session does not have a
@@ -132,13 +126,13 @@
      * <code>UnsupportedRepositoryOperationException</code> is thrown. Otherwise
      * the <code>PrincipalManager</code> is returned or if the call fails,
      * the respective exception is thrown.
-	 * 
+	 *
 	 * @param session  The JCR Session whose <code>PrincipalManager</code> is
      *            to be returned. If the session is not a <code>JackrabbitSession</code>
      *            uses reflection to retrive the manager from the repository.
 	 * @return The <code>PrincipalManager</code> of the session.
 	 * @throws AccessDeniedException
-	 * @throws UnsupportedRepositoryOperationException If the session has no 
+	 * @throws UnsupportedRepositoryOperationException If the session has no
 	 * 				<code>PrincipalManager</code> method or the exception
      *             	thrown by the method.
 	 * @throws RepositoryException Forwarded from the
@@ -153,9 +147,9 @@
 			return safeInvokeRepoMethod(session, METHOD_GET_PRINCIPAL_MANAGER, PrincipalManager.class);
 		}
 	}
-	
+
 	// ---------- AccessControlList methods -----------------------------------------------
-	
+
 	/**
 	 * Returns the path of the node <code>AccessControlList</code> acl
 	 * has been created for.
@@ -163,7 +157,7 @@
 	public static String getPath(AccessControlList acl) throws RepositoryException {
 			return safeInvokeRepoMethod(acl, METHOD_JACKRABBIT_ACL_GET_PATH, String.class);
 	}
-	
+
 	/**
 	 * Returns <code>true</code> if <code>AccessControlList</code> acl
 	 * does not yet define any entries.
@@ -171,14 +165,14 @@
     public static boolean isEmpty(AccessControlList acl) throws RepositoryException {
 		return safeInvokeRepoMethod(acl, METHOD_JACKRABBIT_ACL_IS_EMPTY, Boolean.class);
     }
-    
+
     /**
      * Returns the number of acl entries or 0 if the acl is empty.
      */
     public static int size(AccessControlList acl) throws RepositoryException {
 		return safeInvokeRepoMethod(acl, METHOD_JACKRABBIT_ACL_SIZE, Integer.class);
     }
-    
+
     /**
      * Same as {@link #addEntry(AccessControlList, Principal, Privilege[], boolean, Map)} using
      * some implementation specific restrictions.
@@ -190,7 +184,7 @@
     	Class[] types = new Class[] {Principal.class, Privilege[].class, boolean.class};
 		return safeInvokeRepoMethod(acl, METHOD_JACKRABBIT_ACL_ADD_ENTRY, Boolean.class, args, types);
     }
-    
+
     /**
      * Adds an access control entry to the acl consisting of the specified
      * <code>principal</code>, the specified <code>privileges</code>, the
@@ -207,24 +201,24 @@
     	Class[] types = new Class[] {Principal.class, Privilege[].class, boolean.class, Map.class};
 		return safeInvokeRepoMethod(acl, METHOD_JACKRABBIT_ACL_ADD_ENTRY, Boolean.class, args, types);
     }
-    
+
     // ---------- AccessControlEntry methods -----------------------------------------------
-    
+
     /**
-     * Returns true if the AccessControlEntry represents 'allowed' rights or false 
+     * Returns true if the AccessControlEntry represents 'allowed' rights or false
      * it it represents 'denied' rights.
      */
     public static boolean isAllow(AccessControlEntry ace) throws RepositoryException {
 		return safeInvokeRepoMethod(ace, METHOD_JACKRABBIT_ACE_IS_ALLOW, Boolean.class);
     }
-    
+
     // ---------- internal -----------------------------------------------------
-    
+
     /**
      * Use reflection to invoke a repository method.
      */
     @SuppressWarnings("unchecked")
-	private static <T> T safeInvokeRepoMethod(Object target, String methodName, Class<T> returnType, Object[] args, Class[] argsTypes) 
+	private static <T> T safeInvokeRepoMethod(Object target, String methodName, Class<T> returnType, Object[] args, Class[] argsTypes)
     													throws UnsupportedRepositoryOperationException, RepositoryException {
     	try {
     		Method m = target.getClass().getMethod(methodName, argsTypes);
@@ -255,19 +249,19 @@
             throw new RepositoryException(methodName, t);
         }
 	}
-    
-    private static <T> T safeInvokeRepoMethod(Object target, String methodName, Class<T> returnType, Object... args) 
+
+    private static <T> T safeInvokeRepoMethod(Object target, String methodName, Class<T> returnType, Object... args)
 																		throws UnsupportedRepositoryOperationException, RepositoryException {
     	return safeInvokeRepoMethod(target, methodName, returnType, args, new Class[0]);
     }
-    
+
     /**
      * Unwrap the jackrabbit session.
      */
 	private static JackrabbitSession getJackrabbitSession(Session session) {
 		if (session instanceof JackrabbitSession)
 			return (JackrabbitSession) session;
-		else 
+		else
 			return null;
 	}
 }