jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r956879 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SessionImpl.java session/ session/ActiveSessionState.java session/ClosedSessionState.java session/SessionState.java
Date Tue, 22 Jun 2010 13:19:07 GMT
Author: jukka
Date: Tue Jun 22 13:19:07 2010
New Revision: 956879

URL: http://svn.apache.org/viewvc?rev=956879&view=rev
Log:
JCR-890: concurrent read-only access to a session

Introduce an initial SessionState concept for separating the session internals from SessionImpl.

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java
  (with props)
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java?rev=956879&r1=956878&r2=956879&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
Tue Jun 22 13:19:07 2010
@@ -37,6 +37,9 @@ import org.apache.jackrabbit.core.securi
 import org.apache.jackrabbit.core.security.SecurityConstants;
 import org.apache.jackrabbit.core.security.authentication.AuthContext;
 import org.apache.jackrabbit.core.security.authorization.Permission;
+import org.apache.jackrabbit.core.session.ActiveSessionState;
+import org.apache.jackrabbit.core.session.ClosedSessionState;
+import org.apache.jackrabbit.core.session.SessionState;
 import org.apache.jackrabbit.core.state.LocalItemStateManager;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.SessionItemStateManager;
@@ -123,9 +126,9 @@ public class SessionImpl extends Abstrac
     private static Logger log = LoggerFactory.getLogger(SessionImpl.class);
 
     /**
-     * flag indicating whether this session is alive
+     * The state of this session.
      */
-    protected boolean alive;
+    protected volatile SessionState state = new ActiveSessionState();
 
     /**
      * The component context of the repository that issued this session.
@@ -270,7 +273,6 @@ public class SessionImpl extends Abstrac
             RepositoryContext repositoryContext, Subject subject,
             WorkspaceConfig wspConfig)
             throws AccessDeniedException, RepositoryException {
-        alive = true;
         this.repositoryContext = repositoryContext;
         this.subject = subject;
 
@@ -380,10 +382,7 @@ public class SessionImpl extends Abstrac
      *                             been closed explicitly or if it has expired)
      */
     protected void sanityCheck() throws RepositoryException {
-        // check session status
-        if (!alive) {
-            throw new RepositoryException("this session has been closed");
-        }
+        state.checkAlive();
     }
 
     /**
@@ -1168,7 +1167,7 @@ public class SessionImpl extends Abstrac
      * {@inheritDoc}
      */
     public boolean isLive() {
-        return alive;
+        return state.isAlive();
     }
 
     /**
@@ -1198,7 +1197,7 @@ public class SessionImpl extends Abstrac
      */
     @Override
     public synchronized void logout() {
-        if (!alive) {
+        if (!isLive()) {
             // ignore
             return;
         }
@@ -1222,7 +1221,7 @@ public class SessionImpl extends Abstrac
         wsp.dispose();
 
         // invalidate session
-        alive = false;
+        state = new ClosedSessionState();
 
         // logout JAAS subject
         if (loginContext != null) {
@@ -1346,7 +1345,7 @@ public class SessionImpl extends Abstrac
     public Lock[] getLocks() {
         // check sanity of this session
         //sanityCheck();
-        if (!alive) {
+        if (!isLive()) {
             log.error("failed to retrieve locks: session has been closed");
             return new Lock[0];
         }
@@ -1662,7 +1661,7 @@ public class SessionImpl extends Abstrac
      */
     @Override
     public void finalize() {
-        if (alive) {
+        if (isLive()) {
             log.warn("Unclosed session detected. The session was opened here: ", openStackTrace);
             logout();
         }

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java?rev=956879&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
Tue Jun 22 13:19:07 2010
@@ -0,0 +1,36 @@
+/*
+ * 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.core.session;
+
+public class ActiveSessionState implements SessionState {
+
+    /**
+     * Returns <code>true</code>; the session is alive.
+     *
+     * @return <code>true</code>
+     */
+    public boolean isAlive() {
+        return true;
+    }
+
+    /**
+     * Ignored; the session is alive.
+     */
+    public void checkAlive() {
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ActiveSessionState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java?rev=956879&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java
Tue Jun 22 13:19:07 2010
@@ -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.core.session;
+
+import javax.jcr.RepositoryException;
+
+public class ClosedSessionState implements SessionState {
+
+    /**
+     * Exception that holds the stack trace of where the session was closed.
+     */
+    private final Exception exception;
+
+    public ClosedSessionState() {
+        this.exception = new Exception();
+    }
+
+    /**
+     * Returns <code>false</code>; the session is closed.
+     *
+     * @return <code>false</code>
+     */
+    public boolean isAlive() {
+        return false;
+    }
+
+    /**
+     * Throws an exception; the session is closed.
+     *
+     * @throws RepositoryException always thrown
+     */
+    public void checkAlive() throws RepositoryException {
+        throw new RepositoryException(
+                "This session has been closed; see the chained exception"
+                + " for where the session was closed", exception);
+    }
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/ClosedSessionState.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java?rev=956879&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Tue Jun 22 13:19:07 2010
@@ -0,0 +1,43 @@
+/*
+ * 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.core.session;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+/**
+ * The internal state of a session.
+ */
+public interface SessionState {
+
+    /**
+     * Checks whether this session is alive.
+     *
+     * @see Session#isLive()
+     * @return <code>true</code> if the session is alive,
+     *         <code>false</code> otherwise
+     */
+    boolean isAlive();
+
+    /**
+     * Checks whether this session is alive, and throws an exception if not.
+     *
+     * @throws RepositoryException if this session is not alive
+     */
+    void checkAlive() throws RepositoryException;
+
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message