From ac22436aa690a4d770a4ac3803264dc233d6fdbf Mon Sep 17 00:00:00 2001
From: abobrov <abobrov@localhost>
Date: Mon, 20 Aug 2007 13:46:51 +0000
Subject: [PATCH] - remove toVerboseString method from the public EntryCache API. - make toVerboseString method private in implementation classes. - make toVerboseString use StringBuilder instead of string concat. - make toVerboseString use ServerConstants.EOL where required.  

---
 opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java                     |   13 --
 opendj-sdk/opends/src/server/org/opends/server/extensions/SoftReferenceEntryCache.java |   57 +++++---
 opendj-sdk/opends/src/server/org/opends/server/extensions/DefaultEntryCache.java       |   11 -
 opendj-sdk/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java          |  121 +++++++++++--------
 opendj-sdk/opends/src/server/org/opends/server/extensions/FileSystemEntryCache.java    |  139 +++++++++++++---------
 5 files changed, 184 insertions(+), 157 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java b/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java
index 085c5c0..09c7d0c 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/api/EntryCache.java
@@ -526,19 +526,6 @@
 
 
   /**
-   * Return a verbose string representation of the current cache maps.
-   * This is useful primary for debugging and diagnostic purposes such
-   * as in the entry cache unit tests.
-   * @return String verbose string representation of the current cache
-   *                maps in the following format: dn:id:backend
-   *                one cache entry map representation per line
-   *                or <CODE>null</CODE> if all maps are empty.
-   */
-  public abstract String toVerboseString();
-
-
-
-  /**
    * Retrieves the maximum length of time in milliseconds to wait for
    * a lock before giving up.
    *
diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/DefaultEntryCache.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/DefaultEntryCache.java
index e66f9ca..7633e06 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/DefaultEntryCache.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/DefaultEntryCache.java
@@ -210,17 +210,6 @@
   /**
    * {@inheritDoc}
    */
-  public String toVerboseString()
-  {
-    // This implementation does not store entries.
-    return null;
-  }
-
-
-
-  /**
-   * {@inheritDoc}
-   */
   public boolean isConfigurationChangeAcceptable(
       EntryCacheCfg configuration,
       List<Message> unacceptableReasons
diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java
index 201df37..e1b070f 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/FIFOEntryCache.java
@@ -57,6 +57,7 @@
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.ResultCode;
 import org.opends.server.types.SearchFilter;
+import org.opends.server.util.ServerConstants;
 
 import static org.opends.server.loggers.debug.DebugLogger.*;
 import static org.opends.messages.ExtensionMessages.*;
@@ -865,59 +866,6 @@
   /**
    * {@inheritDoc}
    */
-  public String toVerboseString()
-  {
-    String verboseString = new String();
-
-    Map<DN,CacheEntry> dnMapCopy;
-    Map<Backend,HashMap<Long,CacheEntry>> idMapCopy;
-
-    // Grab cache lock to prevent any modifications
-    // to the cache maps until a snapshot is taken.
-    cacheLock.lock();
-    try {
-      // Examining the real maps will hold the lock and can cause map
-      // modifications in case of any access order maps, make copies
-      // instead.
-      dnMapCopy = new LinkedHashMap<DN,CacheEntry>(dnMap);
-      idMapCopy = new HashMap<Backend,HashMap<Long,CacheEntry>>(idMap);
-    } finally {
-      cacheLock.unlock();
-    }
-
-    // Check dnMap first.
-    for(DN dn : dnMapCopy.keySet()) {
-      verboseString = verboseString + dn.toString() + ":" +
-        (dnMapCopy.get(dn) != null ?
-          Long.toString(dnMapCopy.get(dn).getEntryID()) : null) +
-        ":" + (dnMapCopy.get(dn) != null ?
-          dnMapCopy.get(dn).getBackend().getBackendID() : null) +
-        "\n";
-    }
-
-    // See if there is anything on idMap that isnt reflected on
-    // dnMap in case maps went out of sync.
-    for (Backend backend : idMapCopy.keySet()) {
-      for (Long id : idMapCopy.get(backend).keySet()) {
-        if ((idMapCopy.get(backend).get(id) == null) ||
-            !dnMapCopy.containsKey(
-              idMapCopy.get(backend).get(id).getDN())) {
-          verboseString = verboseString +
-            (idMapCopy.get(backend).get(id) != null ?
-              idMapCopy.get(backend).get(id).getDN().toString() : null) +
-            ":" + id.toString() + ":" + backend.getBackendID() + "\n";
-        }
-      }
-    }
-
-    return (verboseString.length() > 0 ? verboseString : null);
-  }
-
-
-
-  /**
-   * {@inheritDoc}
-   */
   @Override()
   public boolean isConfigurationAcceptable(EntryCacheCfg configuration,
                                            List<Message> unacceptableReasons)
@@ -1144,5 +1092,72 @@
     return errorHandler.getIsAcceptable();
   }
 
+
+
+  /**
+   * Return a verbose string representation of the current cache maps.
+   * This is useful primary for debugging and diagnostic purposes such
+   * as in the entry cache unit tests.
+   * @return String verbose string representation of the current cache
+   *                maps in the following format: dn:id:backend
+   *                one cache entry map representation per line
+   *                or <CODE>null</CODE> if all maps are empty.
+   */
+  private String toVerboseString()
+  {
+    String verboseString = new String();
+    StringBuilder sb = new StringBuilder();
+
+    Map<DN,CacheEntry> dnMapCopy;
+    Map<Backend,HashMap<Long,CacheEntry>> idMapCopy;
+
+    // Grab cache lock to prevent any modifications
+    // to the cache maps until a snapshot is taken.
+    cacheLock.lock();
+    try {
+      // Examining the real maps will hold the lock and can cause map
+      // modifications in case of any access order maps, make copies
+      // instead.
+      dnMapCopy = new LinkedHashMap<DN,CacheEntry>(dnMap);
+      idMapCopy = new HashMap<Backend,HashMap<Long,CacheEntry>>(idMap);
+    } finally {
+      cacheLock.unlock();
+    }
+
+    // Check dnMap first.
+    for (DN dn : dnMapCopy.keySet()) {
+      sb.append(dn.toString());
+      sb.append(":");
+      sb.append((dnMapCopy.get(dn) != null ?
+          Long.toString(dnMapCopy.get(dn).getEntryID()) : null));
+      sb.append(":");
+      sb.append((dnMapCopy.get(dn) != null ?
+          dnMapCopy.get(dn).getBackend().getBackendID() : null));
+      sb.append(ServerConstants.EOL);
+    }
+
+    // See if there is anything on idMap that isnt reflected on
+    // dnMap in case maps went out of sync.
+    for (Backend backend : idMapCopy.keySet()) {
+      for (Long id : idMapCopy.get(backend).keySet()) {
+        if ((idMapCopy.get(backend).get(id) == null) ||
+            !dnMapCopy.containsKey(
+              idMapCopy.get(backend).get(id).getDN())) {
+          sb.append((idMapCopy.get(backend).get(id) != null ?
+              idMapCopy.get(backend).get(id).getDN().toString() : null));
+          sb.append(":");
+          sb.append(id.toString());
+          sb.append(":");
+          sb.append(backend.getBackendID());
+          sb.append(ServerConstants.EOL);
+        }
+      }
+    }
+
+    verboseString = sb.toString();
+
+    return (verboseString.length() > 0 ? verboseString : null);
+  }
+
 }
 
diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/FileSystemEntryCache.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/FileSystemEntryCache.java
index 310f277..c33e8eb 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/FileSystemEntryCache.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/FileSystemEntryCache.java
@@ -74,6 +74,7 @@
 import org.opends.server.types.DebugLogLevel;
 import org.opends.server.types.OpenDsException;
 import org.opends.server.loggers.debug.DebugTracer;
+import org.opends.server.util.ServerConstants;
 import static org.opends.server.loggers.debug.DebugLogger.*;
 import static org.opends.server.loggers.ErrorLogger.logError;
 import static org.opends.server.config.ConfigConstants.*;
@@ -1022,64 +1023,6 @@
   /**
    * {@inheritDoc}
    */
-  public String toVerboseString()
-  {
-    String verboseString = new String();
-
-    Map<DN,Long> dnMapCopy;
-    Map<Backend,Map<Long,DN>> backendMapCopy;
-
-    // Grab write lock to prevent any modifications
-    // to the cache maps until a snapshot is taken.
-    cacheWriteLock.lock();
-    try {
-      // Examining the real maps will hold the lock
-      // and can cause map modifications in case of
-      // any access order maps, make copies instead.
-      dnMapCopy = new LinkedHashMap<DN,Long>(dnMap);
-      backendMapCopy =
-        new LinkedHashMap<Backend,Map<Long,DN>>
-          (backendMap);
-    } finally {
-      cacheWriteLock.unlock();
-    }
-
-    // Check dnMap first.
-    for (DN dn : dnMapCopy.keySet()) {
-      Backend backend = null;
-      Iterator<Backend> backendIterator = backendMapCopy.keySet().iterator();
-      while (backendIterator.hasNext()) {
-        backend = backendIterator.next();
-        Map<Long, DN> map = backendMapCopy.get(backend);
-        if ((map.get(dnMapCopy.get(dn)) != null) &&
-            (map.get(dnMapCopy.get(dn)).equals(dn))) {
-          break;
-        }
-      }
-    }
-
-    // See if there is anything on backendMap that isnt reflected on dnMap
-    // in case maps went out of sync.
-    Backend backend = null;
-    Iterator<Backend> backendIterator = backendMapCopy.keySet().iterator();
-    while (backendIterator.hasNext()) {
-      backend = backendIterator.next();
-      Map<Long, DN> map = backendMapCopy.get(backend);
-      for (Long id : map.keySet()) {
-        if (!dnMapCopy.containsKey(map.get(id)) || map.get(id) == null) {
-          verboseString = verboseString + (map.get(id) != null ?
-            map.get(id) : null) + ":" + id.toString() + ":" +
-          backend.getBackendID() + "\n";
-        }
-      }
-    }
-
-    return (verboseString.length() > 0 ? verboseString : null);
-  }
-
-  /**
-   * {@inheritDoc}
-   */
   @Override()
   public boolean isConfigurationAcceptable(EntryCacheCfg configuration,
                                            List<Message> unacceptableReasons)
@@ -1553,6 +1496,86 @@
     }
   }
 
+  /**
+   * Return a verbose string representation of the current cache maps.
+   * This is useful primary for debugging and diagnostic purposes such
+   * as in the entry cache unit tests.
+   * @return String verbose string representation of the current cache
+   *                maps in the following format: dn:id:backend
+   *                one cache entry map representation per line
+   *                or <CODE>null</CODE> if all maps are empty.
+   */
+  private String toVerboseString()
+  {
+    String verboseString = new String();
+    StringBuilder sb = new StringBuilder();
+
+    Map<DN,Long> dnMapCopy;
+    Map<Backend,Map<Long,DN>> backendMapCopy;
+
+    // Grab write lock to prevent any modifications
+    // to the cache maps until a snapshot is taken.
+    cacheWriteLock.lock();
+    try {
+      // Examining the real maps will hold the lock
+      // and can cause map modifications in case of
+      // any access order maps, make copies instead.
+      dnMapCopy = new LinkedHashMap<DN,Long>(dnMap);
+      backendMapCopy =
+        new LinkedHashMap<Backend,Map<Long,DN>>
+          (backendMap);
+    } finally {
+      cacheWriteLock.unlock();
+    }
+
+    // Check dnMap first.
+    for (DN dn : dnMapCopy.keySet()) {
+      sb.append(dn.toString());
+      sb.append(":");
+      sb.append((dnMapCopy.get(dn) != null ?
+          dnMapCopy.get(dn).toString() : null));
+      sb.append(":");
+      Backend backend = null;
+      String backendID = null;
+      Iterator<Backend> backendIterator = backendMapCopy.keySet().iterator();
+      while (backendIterator.hasNext()) {
+        backend = backendIterator.next();
+        Map<Long, DN> map = backendMapCopy.get(backend);
+        if ((map != null) &&
+            (map.get(dnMapCopy.get(dn)) != null) &&
+            (map.get(dnMapCopy.get(dn)).equals(dn))) {
+          backendID = backend.getBackendID();
+          break;
+        }
+      }
+      sb.append(backendID);
+      sb.append(ServerConstants.EOL);
+    }
+
+    // See if there is anything on backendMap that isnt reflected on dnMap
+    // in case maps went out of sync.
+    Backend backend = null;
+    Iterator<Backend> backendIterator = backendMapCopy.keySet().iterator();
+    while (backendIterator.hasNext()) {
+      backend = backendIterator.next();
+      Map<Long, DN> map = backendMapCopy.get(backend);
+      for (Long id : map.keySet()) {
+        if (!dnMapCopy.containsKey(map.get(id)) || map.get(id) == null) {
+          sb.append((map.get(id) != null ? map.get(id) : null));
+          sb.append(":");
+          sb.append(id.toString());
+          sb.append(":");
+          sb.append(backend.getBackendID());
+          sb.append(ServerConstants.EOL);
+        }
+      }
+    }
+
+    verboseString = sb.toString();
+
+    return (verboseString.length() > 0 ? verboseString : null);
+  }
+
  /**
   * This inner class exist solely to override <CODE>removeEldestEntry()</CODE>
   * method of the LinkedHashMap.
diff --git a/opendj-sdk/opends/src/server/org/opends/server/extensions/SoftReferenceEntryCache.java b/opendj-sdk/opends/src/server/org/opends/server/extensions/SoftReferenceEntryCache.java
index 1cf9825..0ba3056 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/extensions/SoftReferenceEntryCache.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/extensions/SoftReferenceEntryCache.java
@@ -53,6 +53,7 @@
 import org.opends.server.types.InitializationException;
 import org.opends.server.types.LockManager;
 import org.opends.server.types.SearchFilter;
+import org.opends.server.util.ServerConstants;
 
 
 import static org.opends.server.loggers.debug.DebugLogger.*;
@@ -448,28 +449,6 @@
   /**
    * {@inheritDoc}
    */
-  public String toVerboseString()
-  {
-    String verboseString = new String();
-
-    // There're no locks in this cache to keep dnMap and idMap in
-    // sync. Examine dnMap only since its more likely to be up to
-    // date than idMap. Dont bother with copies either since this
-    // is SoftReference based implementation.
-    for(SoftReference<CacheEntry> ce : dnMap.values()) {
-      verboseString = verboseString + ce.get().getDN().toString() +
-        ":" + Long.toString(ce.get().getEntryID()) + ":" +
-        ce.get().getBackend().getBackendID() + "\n";
-    }
-
-    return (verboseString.length() > 0 ? verboseString : null);
-  }
-
-
-
-  /**
-   * {@inheritDoc}
-   */
   @Override()
   public boolean isConfigurationAcceptable(EntryCacheCfg configuration,
                                            List<Message> unacceptableReasons)
@@ -669,5 +648,39 @@
       }
     }
   }
+
+
+
+  /**
+   * Return a verbose string representation of the current cache maps.
+   * This is useful primary for debugging and diagnostic purposes such
+   * as in the entry cache unit tests.
+   * @return String verbose string representation of the current cache
+   *                maps in the following format: dn:id:backend
+   *                one cache entry map representation per line
+   *                or <CODE>null</CODE> if all maps are empty.
+   */
+  private String toVerboseString()
+  {
+    String verboseString = new String();
+    StringBuilder sb = new StringBuilder();
+
+    // There're no locks in this cache to keep dnMap and idMap in
+    // sync. Examine dnMap only since its more likely to be up to
+    // date than idMap. Dont bother with copies either since this
+    // is SoftReference based implementation.
+    for(SoftReference<CacheEntry> ce : dnMap.values()) {
+      sb.append(ce.get().getDN().toString());
+      sb.append(":");
+      sb.append(Long.toString(ce.get().getEntryID()));
+      sb.append(":");
+      sb.append(ce.get().getBackend().getBackendID());
+      sb.append(ServerConstants.EOL);
+    }
+
+    verboseString = sb.toString();
+
+    return (verboseString.length() > 0 ? verboseString : null);
+  }
 }
 

--
Gitblit v1.10.0