jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1181744 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: RepositoryContext.java session/SessionState.java
Date Tue, 11 Oct 2011 12:17:38 GMT
Author: jukka
Date: Tue Oct 11 12:17:37 2011
New Revision: 1181744

URL: http://svn.apache.org/viewvc?rev=1181744&view=rev
Log:
JCR-3040: JMX Stats for the Session

Add "read", "write", and "login" counters to SessionState.

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.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/RepositoryContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java?rev=1181744&r1=1181743&r2=1181744&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryContext.java
Tue Oct 11 12:17:37 2011
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.core.nodety
 import org.apache.jackrabbit.core.security.JackrabbitSecurityManager;
 import org.apache.jackrabbit.core.security.authorization.PrivilegeRegistry;
 import org.apache.jackrabbit.core.state.ItemStateCacheFactory;
+import org.apache.jackrabbit.core.stats.RepositoryStatistics;
 import org.apache.jackrabbit.core.version.InternalVersionManagerImpl;
 
 /**
@@ -107,6 +108,11 @@ public class RepositoryContext {
             new JackrabbitThreadPool();
 
     /**
+     * Repository statistics collector.
+     */
+    private final RepositoryStatistics statistics;
+
+    /**
      * Creates a component context for the given repository.
      *
      * @param repository repository instance
@@ -114,6 +120,7 @@ public class RepositoryContext {
     RepositoryContext(RepositoryImpl repository) {
         assert repository != null;
         this.repository = repository;
+        this.statistics = new RepositoryStatistics(executor);
     }
 
     /**
@@ -361,4 +368,13 @@ public class RepositoryContext {
         return nodeIdFactory;
     }
 
+    /**
+     * Returns the repository statistics collector.
+     *
+     * @return repository statistics collector
+     */
+    public RepositoryStatistics getRepositoryStatistics() {
+        return statistics;
+    }
+
 }

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=1181744&r1=1181743&r2=1181744&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
Tue Oct 11 12:17:37 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.session;
 
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -24,6 +25,7 @@ import javax.jcr.Session;
 
 import org.apache.jackrabbit.core.WorkspaceManager;
 import org.apache.jackrabbit.core.observation.ObservationDispatcher;
+import org.apache.jackrabbit.core.stats.RepositoryStatistics;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -66,6 +68,16 @@ public class SessionState {
     private final SessionContext context;
 
     /**
+     * Counter of read operations.
+     */
+    private final AtomicLong readCounter;
+
+    /**
+     * Counter of write operations.
+     */
+    private final AtomicLong writeCounter;
+
+    /**
      * The lock used to guarantee synchronized execution of repository
      * operations. An explicit lock is used instead of normal Java
      * synchronization in order to be able to log attempts to concurrently
@@ -95,6 +107,12 @@ public class SessionState {
      */
     public SessionState(SessionContext context) {
         this.context = context;
+
+        RepositoryStatistics statistics =
+                context.getRepositoryContext().getRepositoryStatistics();
+        statistics.getCounter("login").incrementAndGet();
+        this.readCounter = statistics.getCounter("read");
+        this.writeCounter = statistics.getCounter("write");
     }
 
     /**
@@ -180,6 +198,13 @@ public class SessionState {
             }
 
             try {
+                // JCR-3040: Increment the operation counters
+                if (isWriteOperation) {
+                    writeCounter.incrementAndGet();
+                } else {
+                    readCounter.incrementAndGet();
+                }
+
                 // Perform the actual operation, optionally with debug logs
                 if (log.isDebugEnabled()) {
                     log.debug("Performing {}", operation);



Mime
View raw message