mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
28.26.2013 4d082692f9931e08eca62029f1880c40d3f14de3
Code cleanup

Added toString() for debuggging.
Added or completed javadocs.
Fixed a little bug in test code.
5 files modified
125 ■■■■ changed files
opends/src/server/org/opends/server/replication/server/ChangelogState.java 8 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/changelog/api/ChangeNumberIndexRecord.java 8 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/changelog/je/DraftCNDB.java 12 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/RuntimeInformation.java 91 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/changelog/je/ChangeNumberIndexerTest.java 6 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/replication/server/ChangelogState.java
@@ -102,4 +102,12 @@
  {
    return domainToServerIds;
  }
  /** {@inheritDoc} */
  @Override
  public String toString()
  {
    return "domainToGenerationId=" + domainToGenerationId
        + ", domainToServerIds=" + domainToServerIds;
  }
}
opends/src/server/org/opends/server/replication/server/changelog/api/ChangeNumberIndexRecord.java
@@ -31,15 +31,19 @@
/**
 * The Change Number Index Record class represents records stored in the
 * {@link ChangeNumberIndexDB}.
 * {@link ChangeNumberIndexDB}. It stores data about a change that happened with
 * the replication.
 */
public final class ChangeNumberIndexRecord
{
  /** This is the key used to store the rest of the . */
  /** This is the key used to store this record. */
  private final long changeNumber;
  /** This is used on startup to recover the medium consistency point. */
  private final String previousCookie;
  /** The baseDN where the change happened. */
  private final DN baseDN;
  /** The CSN of the change. */
  private final CSN csn;
  /**
opends/src/server/org/opends/server/replication/server/changelog/je/DraftCNDB.java
@@ -329,13 +329,11 @@
    }
  }
  /**
   * {@inheritDoc}
   */
  /** {@inheritDoc} */
  @Override
  public String toString()
  {
    return "DraftCNDB";
    return getClass().getSimpleName();
  }
  /**
@@ -622,6 +620,12 @@
      }
    }
    /** {@inheritDoc} */
    @Override
    public String toString()
    {
      return getClass().getSimpleName() + " currentRecord=" + record;
    }
  }
  /**
opends/src/server/org/opends/server/util/RuntimeInformation.java
@@ -23,25 +23,27 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Copyright 2013 ForgeRock AS
 */
package org.opends.server.util;
 package org.opends.server.util;
 import static org.opends.server.loggers.ErrorLogger.logError;
 import static org.opends.messages.RuntimeMessages.*;
 import static org.opends.messages.CoreMessages.*;
 import static org.opends.server.util.DynamicConstants.*;
 import org.opends.server.core.DirectoryServer;
 import java.net.InetAddress;
import java.io.File;
 import java.lang.management.RuntimeMXBean;
 import java.lang.management.ManagementFactory;
 import java.util.List;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.net.InetAddress;
import java.util.List;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.opends.server.core.DirectoryServer;
import com.sleepycat.je.JEVersion;
import static org.opends.messages.CoreMessages.*;
import static org.opends.messages.RuntimeMessages.*;
import static org.opends.server.loggers.ErrorLogger.*;
import static org.opends.server.util.DynamicConstants.*;
 /**
  * This class is used to gather and display information from the runtime
@@ -85,7 +87,7 @@
     RuntimeMXBean rtBean = ManagementFactory.getRuntimeMXBean();
     StringBuilder argList = new StringBuilder();
     List<String> jvmArguments = rtBean.getInputArguments();
     if ((jvmArguments != null) && (! jvmArguments.isEmpty())) {
     if (jvmArguments != null && !jvmArguments.isEmpty()) {
       for (String jvmArg : jvmArguments) {
         if (argList.length() > 0)  {
           argList.append(" ");
@@ -124,12 +126,7 @@
             NOTE_JE_VERSION.get(JEVersion.CURRENT_VERSION.toString()));
     System.out.println(
             NOTE_CURRENT_DIRECTORY.get(System.getProperty("user.dir")));
     String installDir = DirectoryServer.getServerRoot();
     try
     {
       installDir = new File(installDir).getCanonicalPath();
     }
     catch (Exception e){}
     String installDir = toCanonicalPath(DirectoryServer.getServerRoot());
     if (installDir == null)
     {
       System.out.println(NOTE_UNKNOWN_INSTALL_DIRECTORY.get());
@@ -138,12 +135,7 @@
     {
       System.out.println(NOTE_INSTALL_DIRECTORY.get(installDir));
     }
     String instanceDir = DirectoryServer.getInstanceRoot();
     try
     {
       instanceDir = new File(instanceDir).getCanonicalPath();
     }
     catch (Exception e){}
     String instanceDir = toCanonicalPath(DirectoryServer.getInstanceRoot());
     if (instanceDir == null)
     {
       System.out.println(NOTE_UNKNOWN_INSTANCE_DIRECTORY.get());
@@ -181,6 +173,18 @@
             NOTE_FREE_MEMORY.get(Runtime.getRuntime().freeMemory()));
   }
  private static String toCanonicalPath(String path)
  {
    try
    {
      return new File(path).getCanonicalPath();
    }
    catch (Exception ignored)
    {
      return path;
    }
  }
   /**
     * Returns the physical memory size, in bytes, of the hardware we are
     * running on.
@@ -198,18 +202,13 @@
      // Check if this MXBean contains Sun's extension
      if (mbs.isInstanceOf(oname, "com.sun.management.OperatingSystemMXBean")) {
          // Get platform-specific attribute "TotalPhysicalMemorySize"
          Long l = (Long) mbs.getAttribute(oname, "TotalPhysicalMemorySize");
          return l ;
      }
      else
      {
        return -1;
          return (Long) mbs.getAttribute(oname, "TotalPhysicalMemorySize");
      }
    }
    catch (Exception e)
    catch (Exception ignored)
    {
      return -1;
    }
    return -1;
   }
   /**
@@ -219,14 +218,12 @@
    * string "unknown" if an exception was thrown.
    */
   private static String getHostName() {
     String host;
     try {
       host=InetAddress.getLocalHost().getCanonicalHostName();
       return InetAddress.getLocalHost().getCanonicalHostName();
     }
     catch (Exception e) {
       host="Unknown (" + e + ")";
       return "Unknown (" + e + ")";
     }
     return host;
   }
   /**
@@ -251,10 +248,10 @@
    */
   private static String getArch() {
     String sunOsArchDataModel = System.getProperty("sun.arch.data.model");
     if (sunOsArchDataModel != null) {
       if (! sunOsArchDataModel.toLowerCase().equals("unknown")) {
         return (sunOsArchDataModel + "-bit");
       }
     if (sunOsArchDataModel != null
         && !sunOsArchDataModel.toLowerCase().equals("unknown"))
     {
       return sunOsArchDataModel + "-bit";
     }
     return "unknown";
   }
@@ -263,12 +260,7 @@
    * Write runtime information to error log.
    */
   public static void logInfo() {
     String installDir = DirectoryServer.getServerRoot();
     try
     {
       installDir = new File(installDir).getCanonicalPath();
     }
     catch (Exception e){}
     String installDir = toCanonicalPath(DirectoryServer.getServerRoot());
     if (installDir == null)
     {
       logError(NOTE_UNKNOWN_INSTALL_DIRECTORY.get());
@@ -277,12 +269,7 @@
     {
       logError(NOTE_INSTALL_DIRECTORY.get(installDir));
     }
     String instanceDir = DirectoryServer.getInstanceRoot();
     try
     {
       instanceDir = new File(instanceDir).getCanonicalPath();
     }
     catch (Exception e){}
     String instanceDir = toCanonicalPath(DirectoryServer.getInstanceRoot());
     if (instanceDir == null)
     {
       logError(NOTE_UNKNOWN_INSTANCE_DIRECTORY.get());
@@ -294,7 +281,7 @@
    logError(NOTE_JVM_INFO.get(System.getProperty("java.runtime.version"),
                               System.getProperty("java.vendor"),
                               getArch(),Runtime.getRuntime().maxMemory()));
    Long physicalMemorySize = getPhysicalMemorySize();
    long physicalMemorySize = getPhysicalMemorySize();
    if (physicalMemorySize != -1)
    {
      logError(NOTE_JVM_HOST.get(getHostName(), getOSInfo(),
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/changelog/je/ChangeNumberIndexerTest.java
@@ -371,12 +371,14 @@
  private void waitForWaitingState(final Thread t)
  {
    State state = t.getState();
    while (!state.equals(State.WAITING) && !state.equals(State.TERMINATED))
    while (!state.equals(State.WAITING)
        && !state.equals(State.TIMED_WAITING)
        && !state.equals(State.TERMINATED))
    {
      Thread.yield();
      state = t.getState();
    }
    assertThat(state).isEqualTo(State.WAITING);
    assertThat(state).isIn(State.WAITING, State.TIMED_WAITING);
  }
  /**