jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1005019 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: SessionImpl.java session/SessionContext.java session/SessionState.java
Date Wed, 06 Oct 2010 13:17:12 GMT
Author: jukka
Date: Wed Oct  6 13:17:12 2010
New Revision: 1005019

URL: http://svn.apache.org/viewvc?rev=1005019&view=rev
Log:
JCR-2763: Drop the Dumpable interface

Make SessionContext.toString() more detailed while SessionImpl.toString() returns a more trimmed-down
session name.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/SessionImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.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=1005019&r1=1005018&r2=1005019&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
Wed Oct  6 13:17:12 2010
@@ -32,6 +32,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicLong;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.Credentials;
@@ -97,6 +98,7 @@ import org.apache.jackrabbit.spi.commons
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.name.NameConstants;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
+import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.xml.sax.ContentHandler;
@@ -123,6 +125,11 @@ public class SessionImpl extends Abstrac
     private static Logger log = LoggerFactory.getLogger(SessionImpl.class);
 
     /**
+     * Session counter. Used to generate unique internal session names.
+     */
+    private static final AtomicLong SESSION_COUNTER = new AtomicLong();
+
+    /**
      * The component context of this session.
      */
     protected final SessionContext context;
@@ -149,6 +156,12 @@ public class SessionImpl extends Abstrac
     protected final String userId;
 
     /**
+     * Unique internal name of this session. Returned by the
+     * {@link #toString()} method for use in logging and debugging.
+     */
+    private final String sessionName;
+
+    /**
      * the attributes of this session
      */
     protected final Map<String, Object> attributes =
@@ -230,6 +243,13 @@ public class SessionImpl extends Abstrac
         this.subject = subject;
 
         this.userId = retrieveUserId(subject, wspConfig.getName());
+        long count = SESSION_COUNTER.incrementAndGet();
+        if (userId != null) {
+            String user = Text.escapeIllegalJcrChars(userId);
+            this.sessionName = "session-" + user + "-" + count;
+        } else {
+            this.sessionName = "session-" + count;
+        }
 
         namePathResolver = new DefaultNamePathResolver(this, this, true);
         context.setItemStateManager(createSessionItemStateManager());
@@ -1202,7 +1222,7 @@ public class SessionImpl extends Abstrac
      */
     @Override
     public String toString() {
-        return context.toString();
+        return sessionName;
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java?rev=1005019&r1=1005018&r2=1005019&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionContext.java
Wed Oct  6 13:17:12 2010
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.core.session;
 
-import java.util.concurrent.atomic.AtomicLong;
-
 import javax.jcr.NamespaceException;
 import javax.jcr.RepositoryException;
 import javax.jcr.ValueFactory;
@@ -44,7 +42,6 @@ import org.apache.jackrabbit.spi.Path;
 import org.apache.jackrabbit.spi.commons.conversion.IllegalNameException;
 import org.apache.jackrabbit.spi.commons.conversion.MalformedPathException;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
-import org.apache.jackrabbit.util.Text;
 
 /**
  * Component context of a session. This class keeps track of the internal
@@ -53,28 +50,6 @@ import org.apache.jackrabbit.util.Text;
 public class SessionContext implements NamePathResolver {
 
     /**
-     * Session counter. Used to generate unique internal session names.
-     */
-    private static AtomicLong counter = new AtomicLong();
-
-    /**
-     * Creates a unique internal session name for a session with the
-     * given user.
-     *
-     * @param userId session user, or <code>null</code>
-     * @return session name
-     */
-    private static String createSessionName(String userId) {
-        long count = counter.incrementAndGet();
-        if (userId != null) {
-            String user = Text.escapeIllegalJcrChars(userId);
-            return "session-" + user + "-" + count;
-        } else {
-            return "session-" + count;
-        }
-    }
-
-    /**
      * The repository context of this session.
      */
     private final RepositoryContext repositoryContext;
@@ -85,12 +60,6 @@ public class SessionContext implements N
     private final SessionImpl session;
 
     /**
-     * Unique internal name of this session. Returned by the
-     * {@link #toString()} method for use in logging and debugging.
-     */
-    private final String sessionName;
-
-    /**
      * The state of this session.
      */
     private final SessionState state;
@@ -150,7 +119,6 @@ public class SessionContext implements N
         assert session != null;
         this.repositoryContext = repositoryContext;
         this.session = session;
-        this.sessionName = createSessionName(session.getUserID());
         this.state = new SessionState(this);
         this.valueFactory =
             new ValueFactoryImpl(session, repositoryContext.getDataStore());
@@ -350,15 +318,13 @@ public class SessionContext implements N
     //--------------------------------------------------------------< Object >
 
     /**
-     * Returns the unique internal name of this session. The returned name
-     * is especially useful for debugging and logging purposes.
+     * Dumps the session internals to a string.
      *
-     * @see #sessionName
-     * @return session name
+     * @return string representation of session internals
      */
     @Override
     public String toString() {
-        return sessionName;
+        return session + ":\n" + itemManager + "\n" + itemStateManager;
     }
 
 }

Modified: 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=1005019&r1=1005018&r2=1005019&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Wed Oct  6 13:17:12 2010
@@ -136,6 +136,8 @@ public class SessionState {
      */
     public <T> T perform(SessionOperation<T> operation)
             throws RepositoryException {
+        String session = context.getSessionImpl().toString();
+
         // Acquire the exclusive lock for accessing session internals.
         // No other session should be holding the lock, so we log a
         // message to let the user know of such cases.
@@ -143,19 +145,19 @@ public class SessionState {
             if (isWriteOperation
                     && operation instanceof SessionWriteOperation) {
                 Exception trace = new Exception(
-                        "Stack trace of concurrent access to " + context);
+                        "Stack trace of concurrent access to " + session);
                 log.warn("Attempt to perform " + operation
                         + " while another thread is concurrently writing"
-                        + " to " + context + ". Blocking until the other"
+                        + " to " + session + ". Blocking until the other"
                         + " thread is finished using this session. Please"
                         + " review your code to avoid concurrent use of"
                         + " a session.", trace);
             } else if (log.isDebugEnabled()) {
                 Exception trace = new Exception(
-                        "Stack trace of concurrent access to " + context);
+                        "Stack trace of concurrent access to " + session);
                 log.debug("Attempt to perform " + operation + " while"
                         + " another thread is concurrently reading from "
-                        + context + ". Blocking until the other thread"
+                        + session + ". Blocking until the other thread"
                         + " is finished using this session. Please"
                         + " review your code to avoid concurrent use of"
                         + " a session.", trace);
@@ -226,10 +228,12 @@ public class SessionState {
      *         <code>false</code> if the session had already been closed
      */
     public boolean close() {
+        String session = context.getSessionImpl().toString();
+
         if (!lock.tryLock()) {
             Exception trace = new Exception(
-                    "Stack trace of concurrent access to " + context);
-            log.warn("Attempt to close " + context + " while another"
+                    "Stack trace of concurrent access to " + session);
+            log.warn("Attempt to close " + session + " while another"
                     + " thread is concurrently accessing this session."
                     + " Blocking until the other thread is finished"
                     + " using this session. Please review your code"
@@ -239,17 +243,17 @@ public class SessionState {
         try {
             if (isAlive()) {
                 closed = new Exception(
-                        "Stack trace of  where " + context
+                        "Stack trace of  where " + session
                         + " was originally closed");
                 return true;
             } else {
                 Exception trace = new Exception(
                         "Stack trace of the duplicate attempt to close "
-                        + context);
-                log.warn("Attempt to close " + context + " after it has"
+                        + session);
+                log.warn("Attempt to close " + session + " after it has"
                         + " already been closed. Please review your code"
                         + " for proper session management.", trace);
-                log.warn(context + " has already been closed. See the"
+                log.warn(session + " has already been closed. See the"
                         + " attached exception for a trace of where this"
                         + " session was closed.", closed);
                 return false;



Mime
View raw message