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

Jean-Noel Rouvignac
07.51.2013 6b867820726b09d56252cdf58abeac6cd90d0901
Installer.java, InstallerHelper.java:
Used StaticUtils.close() and StaticUtils.sleep() methods.

StaticUtils.java:
Added close(InitialLdapContext...).
added null checks in other close() methods.
3 files modified
204 ■■■■ changed files
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java 154 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java 11 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/StaticUtils.java 39 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -98,6 +98,7 @@
import org.opends.quicksetup.installer.ui.ServerSettingsPanel;
import org.opends.quicksetup.installer.ui.SuffixesToReplicatePanel;
import org.opends.server.util.SetupUtils;
import org.opends.server.util.StaticUtils;
import org.opends.messages.Message;
import org.opends.messages.MessageBuilder;
import static org.opends.messages.QuickSetupMessages.*;
@@ -315,6 +316,7 @@
  /**
   * {@inheritDoc}
   */
  @Override
  public boolean isSubStep(WizardStep step)
  {
    return SUBSTEPS.contains(step);
@@ -1675,16 +1677,7 @@
      }
      finally
      {
        if (ctx != null)
        {
          try
          {
            ctx.close();
          }
          catch (Throwable t)
          { /* do nothing */
          }
        }
        StaticUtils.close(ctx);
      }
    }
    InstallerHelper helper = new InstallerHelper();
@@ -1705,16 +1698,7 @@
      {
        notifyListeners(getFormattedError(ae, true));
      }
      if (ctx != null)
      {
        try
        {
          ctx.close();
        }
        catch (Throwable t)
        { /* do nothing */
        }
      }
      StaticUtils.close(ctx);
      notifyListeners(getFormattedDoneWithLineBreak());
    }
  }
@@ -1856,16 +1840,7 @@
    }
    finally
    {
      try
      {
        if (ctx != null)
        {
          ctx.close();
        }
      }
      catch (Throwable t)
      { /* do nothing */
      }
      StaticUtils.close(ctx);
    }
    notifyListeners(getFormattedDoneWithLineBreak());
@@ -2005,16 +1980,7 @@
    }
    finally
    {
      try
      {
        if (ctx != null)
        {
          ctx.close();
        }
      }
      catch (Throwable t)
      { /* do nothing */
      }
      StaticUtils.close(ctx);
    }
    notifyListeners(getFormattedDoneWithLineBreak());
    checkAbort();
@@ -2131,13 +2097,7 @@
        hmConfiguredRemoteReplication.put(server, repl);
        try
        {
          ctx.close();
        }
        catch (Throwable t)
        { /* do nothing */
        }
        StaticUtils.close(ctx);
        notifyListeners(getFormattedDoneWithLineBreak());
        checkAbort();
      }
@@ -2314,16 +2274,7 @@
    }
    finally
    {
      try
      {
        if (writer != null)
        {
          writer.close();
        }
      }
      catch (Exception ex)
      { /* do nothing */
      }
      StaticUtils.close(writer);
    }
  }
@@ -2484,16 +2435,7 @@
    {
      Message failedMsg =
              getThrowableMsg(INFO_ERROR_CONNECTING_TO_LOCAL.get(), t);
      try
      {
        if (ctx != null)
        {
          ctx.close();
        }
      }
      catch (Throwable t1)
      { /* do nothing */
      }
      StaticUtils.close(ctx);
      throw new ApplicationException(
          ReturnCode.CONFIGURATION_ERROR, failedMsg, t);
    }
@@ -2546,8 +2488,7 @@
      }
      finally
      {
        try{ rCtx.close(); }
        catch (Throwable t){ /* do nothing */ }
        StaticUtils.close(rCtx);
      }
    }
@@ -2627,13 +2568,7 @@
          }
          finally
          {
            try
            {
              rCtx.close();
            }
            catch (Throwable t)
            { /* do nothing */
            }
            StaticUtils.close(rCtx);
          }
        }
        if (replicationId == -1)
@@ -2642,11 +2577,7 @@
              ReturnCode.APPLICATION_ERROR,
              ERR_COULD_NOT_FIND_REPLICATIONID.get(dn), null);
        }
        try
        {
          Thread.sleep(3000);
        }
        catch (Throwable t) { /* do nothing */ }
        StaticUtils.sleep(3000);
        int nTries = 5;
        boolean initDone = false;
        while (!initDone)
@@ -2670,29 +2601,14 @@
                  ReturnCode.APPLICATION_ERROR,
                  pnfe.getMessageObject(), null);
            }
            try
            {
              Thread.sleep((5 - nTries) * 3000);
            }
            catch (Throwable t)
            { /* do nothing */
            }
            StaticUtils.sleep((5 - nTries) * 3000);
          }
          nTries--;
        }
      }
      catch (ApplicationException ae)
      {
        try
        {
          if (ctx != null)
          {
            ctx.close();
          }
        }
        catch (Throwable t1)
        { /* do nothing */
        }
        StaticUtils.close(ctx);
        throw ae;
      }
      if ((isADS || isSchema) && isVerbose())
@@ -2885,12 +2801,7 @@
    }
    finally
    {
      if (null != remoteCtx)
        try { remoteCtx.close(); }
        catch (NamingException x){ /* do nothing */ }
      if (null != localCtx)
        try { localCtx.close(); }
        catch (NamingException x){ /* do nothing */ }
      StaticUtils.close(remoteCtx, localCtx);
    }
  }
@@ -3904,16 +3815,7 @@
    }
    finally
    {
      if (ctx != null)
      {
        try
        {
          ctx.close();
        }
        catch (Throwable t)
        { /* do nothing */
        }
      }
      StaticUtils.close(ctx);
    }
  }
@@ -4672,13 +4574,7 @@
        // server will receive a connect error.
        checkAbort();
      }
      try
      {
        Thread.sleep(500);
      }
      catch (Throwable t)
      { /* do nothing */
      }
      StaticUtils.sleep(500);
      if (canceled)
      {
        // TODO: we should try to cleanly abort the initialize.  As we have
@@ -4973,13 +4869,7 @@
    String lastLogMsg = null;
    while (!isOver)
    {
      try
      {
        Thread.sleep(500);
      }
      catch (Throwable t)
      { /* do nothing */
      }
      StaticUtils.sleep(500);
      try
      {
        NamingEnumeration<SearchResult> res =
@@ -5087,13 +4977,7 @@
        }
        else
        {
          try
          {
            Thread.sleep(100);
          }
          catch (Throwable t)
          { /* do nothing */
          }
          StaticUtils.sleep(100);
        }
      }
      if (thread.getException() != null)
opends/src/quicksetup/org/opends/quicksetup/installer/InstallerHelper.java
@@ -1095,16 +1095,7 @@
    }
    finally
    {
      if (fs != null)
      {
        try
        {
          fs.close();
        }
        catch (Throwable t)
        { /* do nothing */
        }
      }
      StaticUtils.close(fs);
    }
    return fileProperties;
  }
opends/src/server/org/opends/server/util/StaticUtils.java
@@ -64,6 +64,9 @@
import java.util.StringTokenizer;
import java.util.TimeZone;
import javax.naming.NamingException;
import javax.naming.ldap.InitialLdapContext;
import org.opends.messages.Message;
import org.opends.messages.MessageBuilder;
import org.opends.messages.MessageDescriptor;
@@ -4669,6 +4672,10 @@
   */
  public static void close(Selector... selectors)
  {
    if (selectors == null)
    {
      return;
    }
    for (Selector selector : selectors)
    {
      if (selector != null)
@@ -4696,6 +4703,10 @@
   */
  public static void close(Socket... sockets)
  {
    if (sockets == null)
    {
      return;
    }
    for (Socket socket : sockets)
    {
      if (socket != null)
@@ -4713,6 +4724,34 @@
  }
  /**
   * Closes the provided {@link InitialLdapContext}s ignoring any errors which
   * occurred.
   *
   * @param ctxs
   *          The contexts to be closed, which may be <code>null</code>.
   */
  public static void close(InitialLdapContext... ctxs)
  {
    if (ctxs == null)
    {
      return;
    }
    for (InitialLdapContext ctx : ctxs)
    {
      if (ctx != null)
      {
        try
        {
          ctx.close();
        }
        catch (NamingException ignored)
        {
        }
      }
    }
  }
  /**
   * Calls {@link Thread#sleep(long)}, surrounding it with the mandatory
   * <code>try</code> / <code>catch(InterruptedException)</code> block.
   *