move request counters into separate class
comment out some detailed logging
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
index c1149a3..ddf409e 100644
--- a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/ConcurrentLockManager.java
@@ -19,7 +19,6 @@
 import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -56,13 +55,8 @@
     private ConcurrentHashMap<Integer, Long> jobIdSlotMap;
     private ThreadLocal<DatasetLockCache> dsLockCache;
     
-    private final AtomicInteger lCnt = new AtomicInteger();
-    private final AtomicInteger ilCnt = new AtomicInteger();
-    private final AtomicInteger tlCnt = new AtomicInteger();
-    private final AtomicInteger itlCnt = new AtomicInteger();
-    private final AtomicInteger ulCnt = new AtomicInteger();
-    private final AtomicInteger rlCnt = new AtomicInteger();
-        
+    private LockManagerStats stats = new LockManagerStats(10000); 
+    
     enum LockAction {
         ERR(false, false),
         GET(false, false),
@@ -116,7 +110,7 @@
     public void lock(DatasetId datasetId, int entityHashValue, byte lockMode, ITransactionContext txnContext)
             throws ACIDException {
         log("lock", datasetId.getId(), entityHashValue, lockMode, txnContext);
-        lCnt.incrementAndGet();
+        stats.lock();
         
         final int dsId = datasetId.getId();        
         final int jobId = txnContext.getJobId().getId();
@@ -218,7 +212,7 @@
     public void instantLock(DatasetId datasetId, int entityHashValue, byte lockMode, ITransactionContext txnContext)
             throws ACIDException {
         log("instantLock", datasetId.getId(), entityHashValue, lockMode, txnContext);
-        ilCnt.incrementAndGet();
+        stats.instantLock();
         
         final int dsId = datasetId.getId();        
         final int jobId = txnContext.getJobId().getId();
@@ -276,7 +270,7 @@
         } finally {
             if (reqSlot != -1) {
                 // deallocate request, if we allocated one earlier
-                LOGGER.info("XXX del req slot " + TypeUtil.Global.toString(reqSlot));
+                //LOGGER.info("XXX del req slot " + TypeUtil.Global.toString(reqSlot));
                 reqArenaMgr.deallocate(reqSlot);
             }
             group.releaseLatch();
@@ -287,7 +281,7 @@
     public boolean tryLock(DatasetId datasetId, int entityHashValue, byte lockMode, ITransactionContext txnContext)
             throws ACIDException {
         log("tryLock", datasetId.getId(), entityHashValue, lockMode, txnContext);
-        tlCnt.incrementAndGet();
+        stats.tryLock();
         
         final int dsId = datasetId.getId();
         final int jobId = txnContext.getJobId().getId();
@@ -340,7 +334,7 @@
     public boolean instantTryLock(DatasetId datasetId, int entityHashValue, byte lockMode,
             ITransactionContext txnContext) throws ACIDException {
         log("instantTryLock", datasetId.getId(), entityHashValue, lockMode, txnContext);
-        itlCnt.incrementAndGet();
+        stats.instantTryLock();
         
         final int dsId = datasetId.getId();
         final int jobId = txnContext.getJobId().getId();
@@ -404,7 +398,7 @@
 
     private void unlock(int dsId, int entityHashValue, byte lockMode, long jobSlot) throws ACIDException {
         log("unlock", dsId, entityHashValue, lockMode, null);
-        ulCnt.incrementAndGet();
+        stats.unlock();
 
         ResourceGroup group = table.get(dsId, entityHashValue);
         group.getLatch();
@@ -418,7 +412,7 @@
             long holder = removeLastHolder(resource, jobSlot, lockMode);
 
             // deallocate request
-            LOGGER.info("XXX del req slot " + TypeUtil.Global.toString(holder));
+            //LOGGER.info("XXX del req slot " + TypeUtil.Global.toString(holder));
             reqArenaMgr.deallocate(holder);
             // deallocate resource or fix max lock mode
             if (resourceNotUsed(resource)) {
@@ -431,7 +425,7 @@
                     }
                     resArenaMgr.setNext(prev, resArenaMgr.getNext(resource));
                 }
-                LOGGER.info("XXX del res slot " + TypeUtil.Global.toString(resource));
+                //LOGGER.info("XXX del res slot " + TypeUtil.Global.toString(resource));
                 resArenaMgr.deallocate(resource);
             } else {
                 final int oldMaxMode = resArenaMgr.getMaxMode(resource);
@@ -453,7 +447,7 @@
     @Override
     public void releaseLocks(ITransactionContext txnContext) throws ACIDException {
         log("releaseLocks", -1, -1, LockMode.ANY, txnContext);
-        rlCnt.incrementAndGet();
+        stats.releaseLocks();
 
         int jobId = txnContext.getJobId().getId();
         Long jobSlot = jobIdSlotMap.get(jobId);
@@ -476,11 +470,11 @@
                 unlock(dsId, pkHashVal, LockMode.ANY, jobSlot);
                 holder = jobArenaMgr.getLastHolder(jobSlot);
             }
-            LOGGER.info("XXX del job slot " + TypeUtil.Global.toString(jobSlot));
+            //LOGGER.info("XXX del job slot " + TypeUtil.Global.toString(jobSlot));
             jobArenaMgr.deallocate(jobSlot);
             jobIdSlotMap.remove(jobId);
         }
-        logCounters(true);
+        stats.logCounters(LOGGER, Level.INFO, true);
         //LOGGER.info(toString());
     }
         
@@ -488,14 +482,14 @@
         Long jobSlot = jobIdSlotMap.get(jobId);
         if (jobSlot == null) {
             jobSlot = new Long(jobArenaMgr.allocate());
-            LOGGER.info("XXX new job slot " + TypeUtil.Global.toString(jobSlot) + " (" + jobId + ")");
+            //LOGGER.info("XXX new job slot " + TypeUtil.Global.toString(jobSlot) + " (" + jobId + ")");
             jobArenaMgr.setJobId(jobSlot, jobId);
             Long oldSlot = jobIdSlotMap.putIfAbsent(jobId, jobSlot);
             if (oldSlot != null) {
                 // if another thread allocated a slot for this jobId between
                 // get(..) and putIfAbsent(..), we'll use that slot and
                 // deallocate the one we allocated
-                LOGGER.info("XXX del job slot " + TypeUtil.Global.toString(jobSlot) + " due to conflict");
+                //LOGGER.info("XXX del job slot " + TypeUtil.Global.toString(jobSlot) + " due to conflict");
                 jobArenaMgr.deallocate(jobSlot);
                 jobSlot = oldSlot;
             }
@@ -514,9 +508,9 @@
             resArenaMgr.setPkHashVal(resSlot, entityHashValue);
             resArenaMgr.setNext(resSlot, group.firstResourceIndex.get());
             group.firstResourceIndex.set(resSlot);
-            LOGGER.info("XXX new res slot " + TypeUtil.Global.toString(resSlot) + " (" + dsId + ", " + entityHashValue + ")");
+            //LOGGER.info("XXX new res slot " + TypeUtil.Global.toString(resSlot) + " (" + dsId + ", " + entityHashValue + ")");
         } else {
-            LOGGER.info("XXX fnd res slot " + TypeUtil.Global.toString(resSlot) + " (" + dsId + ", " + entityHashValue + ")");
+            //LOGGER.info("XXX fnd res slot " + TypeUtil.Global.toString(resSlot) + " (" + dsId + ", " + entityHashValue + ")");
         }
         return resSlot;
     }
@@ -526,10 +520,10 @@
         reqArenaMgr.setResourceId(reqSlot, resSlot);
         reqArenaMgr.setLockMode(reqSlot, lockMode); // lock mode is a byte!!
         reqArenaMgr.setJobSlot(reqSlot, jobSlot);
-        LOGGER.info("XXX new req slot " + TypeUtil.Global.toString(reqSlot)
-                + " (" + TypeUtil.Global.toString(resSlot)
-                + ", " + TypeUtil.Global.toString(jobSlot)
-                + ", " + LockMode.toString(lockMode) + ")");
+        //LOGGER.info("XXX new req slot " + TypeUtil.Global.toString(reqSlot)
+        //        + " (" + TypeUtil.Global.toString(resSlot)
+        //        + ", " + TypeUtil.Global.toString(jobSlot)
+        //        + ", " + LockMode.toString(lockMode) + ")");
         return reqSlot;
     }
 
@@ -572,7 +566,7 @@
     }
     
     private long findResourceInGroup(ResourceGroup group, int dsId, int entityHashValue) {
-        logCounters(false);
+        stats.logCounters(LOGGER, Level.INFO, false);
 
         int i = 0;
         
@@ -591,21 +585,6 @@
         return -1;        
     }
 
-    private final void logCounters(boolean always) {
-        final Level lvl = Level.INFO;
-        if (LOGGER.isLoggable(lvl)) {
-            if (always || (lCnt.intValue() + ilCnt.intValue() + tlCnt.intValue() 
-                    + itlCnt.intValue() + ulCnt.intValue() + rlCnt.intValue())  % 10000 == 0) {
-                LOGGER.log(lvl, "number of lock requests             : " + lCnt);
-                LOGGER.log(lvl, "number of instant lock requests     : " + ilCnt);
-                LOGGER.log(lvl, "number of try lock requests         : " + tlCnt);
-                LOGGER.log(lvl, "number of instant try lock requests : " + itlCnt);
-                LOGGER.log(lvl, "number of unlock requests           : " + ulCnt);
-                LOGGER.log(lvl, "number of release locks requests    : " + rlCnt);
-            }
-        }
-    }
-
     private void addHolder(long request, long resource, long job) {
         long lastHolder = resArenaMgr.getLastHolder(resource);
         reqArenaMgr.setNextRequest(request, lastHolder);
diff --git a/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/LockManagerStats.java b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/LockManagerStats.java
new file mode 100644
index 0000000..c3aa195
--- /dev/null
+++ b/asterix-transactions/src/main/java/edu/uci/ics/asterix/transaction/management/service/locking/LockManagerStats.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ * 
+ *     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 edu.uci.ics.asterix.transaction.management.service.locking;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+final class LockManagerStats {
+    private final int loggingPeriod;
+    
+    private final AtomicInteger lCnt = new AtomicInteger();
+    private final AtomicInteger ilCnt = new AtomicInteger();
+    private final AtomicInteger tlCnt = new AtomicInteger();
+    private final AtomicInteger itlCnt = new AtomicInteger();
+    private final AtomicInteger ulCnt = new AtomicInteger();
+    private final AtomicInteger rlCnt = new AtomicInteger();
+
+    LockManagerStats(int loggingPeriod) {
+        this.loggingPeriod = loggingPeriod;
+    }
+    
+    final void lock()           { lCnt.incrementAndGet(); }
+    final void instantLock()    { ilCnt.incrementAndGet(); }
+    final void tryLock()        { tlCnt.incrementAndGet(); }
+    final void instantTryLock() { itlCnt.incrementAndGet(); }
+    final void unlock()         { ulCnt.incrementAndGet(); }
+    final void releaseLocks()   { rlCnt.incrementAndGet(); }
+    
+    final int requestSum() {
+        return lCnt.intValue() + ilCnt.intValue() + tlCnt.intValue() 
+                + itlCnt.intValue() + ulCnt.intValue() + rlCnt.intValue();
+    }
+
+    final StringBuilder append(StringBuilder sb) {
+        sb.append("{")
+        .append(" lock : ").append(lCnt)
+        .append(", instantLock : ").append(lCnt)
+        .append(", tryLock : ").append(lCnt)
+        .append(", instantTryLock : ").append(lCnt)
+        .append(", unlock : ").append(lCnt)
+        .append(", releaseLocks : ").append(lCnt)
+        .append(" }");
+        return sb;
+    }        
+
+    @Override
+    public String toString() {
+        return append(new StringBuilder()).toString();
+    }
+
+    final void logCounters(final Logger logger, final Level lvl, boolean always) {
+        if (logger.isLoggable(lvl) 
+            && (always || requestSum()  % loggingPeriod == 0)) {
+            logger.log(lvl, toString());
+        }
+    }
+}