From a381819e25430ccca6f3d5645d7422d1dda97c1c Mon Sep 17 00:00:00 2001
From: Nicolas Capponi <nicolas.capponi@forgerock.com>
Date: Fri, 17 Jun 2016 09:54:07 +0000
Subject: [PATCH] OPENDJ-2655 Optimize Group implementations by lazily creating examined groups

---
 opendj-server-legacy/src/main/java/org/opends/server/extensions/VirtualStaticGroup.java |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/VirtualStaticGroup.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/VirtualStaticGroup.java
index fee8a8d..a66e621 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/VirtualStaticGroup.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/VirtualStaticGroup.java
@@ -17,8 +17,10 @@
 package org.opends.server.extensions;
 
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.forgerock.i18n.LocalizableMessage;
 import org.forgerock.i18n.LocalizedIllegalArgumentException;
@@ -216,10 +218,11 @@
   }
 
   @Override
-  public boolean isMember(DN userDN, Set<DN> examinedGroups)
+  public boolean isMember(DN userDN, AtomicReference<Set<DN>> examinedGroups)
          throws DirectoryException
   {
-    if (! examinedGroups.add(getGroupDN()))
+    Set<DN> groups = getExaminedGroups(examinedGroups);
+    if (! groups.add(getGroupDN()))
     {
       return false;
     }
@@ -243,10 +246,11 @@
   }
 
   @Override
-  public boolean isMember(Entry userEntry, Set<DN> examinedGroups)
+  public boolean isMember(Entry userEntry, AtomicReference<Set<DN>> examinedGroups)
          throws DirectoryException
   {
-    if (! examinedGroups.add(getGroupDN()))
+    Set<DN> groups = getExaminedGroups(examinedGroups);
+    if (! groups.add(getGroupDN()))
     {
       return false;
     }
@@ -269,6 +273,17 @@
     }
   }
 
+  private Set<DN> getExaminedGroups(AtomicReference<Set<DN>> examinedGroups)
+  {
+    Set<DN> groups = examinedGroups.get();
+    if (groups == null)
+    {
+      groups = new HashSet<DN>();
+      examinedGroups.set(groups);
+    }
+    return groups;
+  }
+
   @Override
   public MemberList getMembers()
          throws DirectoryException

--
Gitblit v1.10.0