From f15e69d46eb0444e28427f49fb519ea476c7feae Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 15 Oct 2015 19:38:35 +0000
Subject: [PATCH] Replaced calls to DirectoryServer.getDefaultAttributeType() by DirectoryServer.getAttributeTypeOrDefault(). + Directly used Attributes and AttributeBuilder methods which accepts a String instead of AttributeType parameter.

---
 opendj-server-legacy/src/main/java/org/opends/server/monitors/MemoryUsageMonitorProvider.java |   64 ++++++++------------------------
 1 files changed, 16 insertions(+), 48 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/monitors/MemoryUsageMonitorProvider.java b/opendj-server-legacy/src/main/java/org/opends/server/monitors/MemoryUsageMonitorProvider.java
index 1ec12a4..92c3358 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/monitors/MemoryUsageMonitorProvider.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/monitors/MemoryUsageMonitorProvider.java
@@ -34,13 +34,15 @@
 import java.lang.management.MemoryUsage;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 
+import org.forgerock.opendj.config.server.ConfigException;
 import org.opends.server.admin.std.server.MemoryUsageMonitorProviderCfg;
 import org.opends.server.api.MonitorProvider;
-import org.forgerock.opendj.config.server.ConfigException;
-import org.opends.server.core.DirectoryServer;
-import org.opends.server.types.*;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.Attributes;
+import org.opends.server.types.InitializationException;
 
 /**
  * This class defines a monitor provider that reports information about
@@ -111,9 +113,8 @@
 
 
 
-  /** {@inheritDoc} */
   @Override
-  public ArrayList<Attribute> getMonitorData()
+  public List<Attribute> getMonitorData()
   {
     ArrayList<Attribute> attrs = new ArrayList<>();
 
@@ -143,14 +144,10 @@
         gcSafeNames.put(gcName, safeName);
       }
 
-      attrs.add(createAttribute(safeName + "-total-collection-count",
-                                String.valueOf(gcCount)));
-      attrs.add(createAttribute(safeName + "-total-collection-duration",
-                                String.valueOf(gcTime)));
-      attrs.add(createAttribute(safeName + "-average-collection-duration",
-                                String.valueOf(avgGCDuration)));
-      attrs.add(createAttribute(safeName + "-recent-collection-duration",
-                                String.valueOf(recentGCDuration)));
+      attrs.add(createAttribute(safeName + "-total-collection-count", gcCount));
+      attrs.add(createAttribute(safeName + "-total-collection-duration", gcTime));
+      attrs.add(createAttribute(safeName + "-average-collection-duration", avgGCDuration));
+      attrs.add(createAttribute(safeName + "-recent-collection-duration", recentGCDuration));
     }
 
     for (MemoryPoolMXBean mp : ManagementFactory.getMemoryPoolMXBeans())
@@ -166,48 +163,19 @@
         gcSafeNames.put(poolName, safeName);
       }
 
-      if (currentUsage == null)
-      {
-        attrs.add(createAttribute(safeName + "-current-bytes-used", "0"));
-      }
-      else
-      {
-        attrs.add(createAttribute(safeName + "-current-bytes-used",
-                                  String.valueOf(currentUsage.getUsed())));
-      }
+      long currentBytesUsed = currentUsage != null ? currentUsage.getUsed() : 0;
+      attrs.add(createAttribute(safeName + "-current-bytes-used", currentBytesUsed));
 
-      if (collectionUsage == null)
-      {
-        attrs.add(createAttribute(safeName +
-                                       "-bytes-used-after-last-collection",
-                                  "0"));
-      }
-      else
-      {
-        attrs.add(createAttribute(safeName +
-                                       "-bytes-used-after-last-collection",
-                                  String.valueOf(collectionUsage.getUsed())));
-      }
+      long collectionBytesUsed = collectionUsage != null ? collectionUsage.getUsed() : 0;
+      attrs.add(createAttribute(safeName + "-bytes-used-after-last-collection", collectionBytesUsed));
     }
 
     return attrs;
   }
 
-
-
-  /**
-   * Constructs an attribute using the provided information.  It will have the
-   * default syntax.
-   *
-   * @param  name   The name to use for the attribute.
-   * @param  value  The value to use for the attribute.
-   *
-   * @return  The attribute created from the provided information.
-   */
-  private Attribute createAttribute(String name, String value)
+  private Attribute createAttribute(String name, Object value)
   {
-    AttributeType attrType = DirectoryServer.getDefaultAttributeType(name);
-    return Attributes.create(attrType, value);
+    return Attributes.create(name, String.valueOf(value));
   }
 
 

--
Gitblit v1.10.0