antonovsergey93 commented on a change in pull request #6374: IGNITE-11392: 
Improve LRT diagnostic messages
URL: https://github.com/apache/ignite/pull/6374#discussion_r273403007
 
 

 ##########
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
 ##########
 @@ -3521,4 +3587,58 @@ private void printToLog() {
             }
         }
     }
+
+    /**
+     * Class to limit action count for unique objects.
+     */
+    private static class ActionLimiter<T> {
+        /** */
+        private final int limit;
+
+        /**
+         * Internal storage of objects and counters for each of object.
+         */
+        private final ConcurrentMap<T, AtomicInteger> actionsCnt = new 
ConcurrentHashMap<>();
+
+        /**
+         * Set of active objects.
+         */
+        private final Set<T> activeObjects = new GridConcurrentHashSet<>();
+
+        /**
+         * @param limit Limit.
+         */
+        private ActionLimiter(int limit) {
+            this.limit = limit;
+        }
+
+        /**
+         * Shows if action is allowed for the given object. Adds this object 
to internal set of active
+         * objects that are still in use.
+         *
+         * @param obj object.
+         */
+        boolean allowAction(T obj) {
+            activeObjects.add(obj);
+
+            AtomicInteger cnt = actionsCnt.get(obj);
+
+            if (cnt != null)
+                cnt.incrementAndGet();
+            else
+                actionsCnt.put(obj, new AtomicInteger(1));
 
 Review comment:
   You could use `computeIfAbsent()` method. I.e. 
   `actionsCnt.computeIfAbsent(obj, x -> new 
AtomicInteger()).incrementAndGet();` 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to