From 4ca2a9a3650344ed74e55c1bdb646dc88cf91965 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 08 Jan 2014 14:23:51 +0000
Subject: [PATCH] Fix OPENDJ-1270: Avoid unnecessary DNS lookups when performing bind requests

---
 opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java |   49 ++++++++++++++++---------------------------------
 1 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java
index 043e489..b6da837 100644
--- a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java
+++ b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/LDAPConnectionFactory.java
@@ -22,16 +22,16 @@
  *
  *
  *      Copyright 2009-2010 Sun Microsystems, Inc.
- *      Portions copyright 2011-2013 ForgeRock AS.
+ *      Portions copyright 2011-2014 ForgeRock AS.
  */
 
 package org.forgerock.opendj.ldap;
 
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
-import java.net.SocketAddress;
 
 import com.forgerock.opendj.ldap.LDAPConnectionFactoryImpl;
+import com.forgerock.opendj.util.StaticUtils;
 import com.forgerock.opendj.util.Validator;
 
 /**
@@ -54,7 +54,7 @@
      * @throws NullPointerException
      *             If {@code address} was {@code null}.
      */
-    public LDAPConnectionFactory(final SocketAddress address) {
+    public LDAPConnectionFactory(final InetSocketAddress address) {
         this(address, new LDAPOptions());
     }
 
@@ -69,7 +69,7 @@
      * @throws NullPointerException
      *             If {@code address} or {@code options} was {@code null}.
      */
-    public LDAPConnectionFactory(final SocketAddress address, final LDAPOptions options) {
+    public LDAPConnectionFactory(final InetSocketAddress address, final LDAPOptions options) {
         Validator.ensureNotNull(address, options);
         this.impl = new LDAPConnectionFactoryImpl(address, options);
     }
@@ -106,7 +106,7 @@
      */
     public LDAPConnectionFactory(final String host, final int port, final LDAPOptions options) {
         Validator.ensureNotNull(host, options);
-        final SocketAddress address = new InetSocketAddress(host, port);
+        final InetSocketAddress address = new InetSocketAddress(host, port);
         this.impl = new LDAPConnectionFactoryImpl(address, options);
     }
 
@@ -117,13 +117,7 @@
      *         or {@code null} if it is unknown.
      */
     public InetAddress getAddress() {
-        final SocketAddress socketAddress = getSocketAddress();
-        if (socketAddress instanceof InetSocketAddress) {
-            final InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
-            return inetSocketAddress.getAddress();
-        } else {
-            return null;
-        }
+        return getSocketAddress().getAddress();
     }
 
     @Override
@@ -143,35 +137,24 @@
     }
 
     /**
-     * Returns the host name that this LDAP listener is listening on.
+     * Returns the host name that this LDAP listener is listening on. The
+     * returned host name is the same host name that was provided during
+     * construction and may be an IP address. More specifically, this method
+     * will not perform a reverse DNS lookup.
      *
-     * @return The host name that this LDAP listener is listening on, or
-     *         {@code null} if it is unknown.
+     * @return The host name that this LDAP listener is listening on.
      */
-    public String getHostname() {
-        final SocketAddress socketAddress = getSocketAddress();
-        if (socketAddress instanceof InetSocketAddress) {
-            final InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
-            return inetSocketAddress.getHostName();
-        } else {
-            return null;
-        }
+    public String getHostName() {
+        return StaticUtils.getHostName(getSocketAddress());
     }
 
     /**
      * Returns the port that this LDAP listener is listening on.
      *
-     * @return The port that this LDAP listener is listening on, or {@code -1}
-     *         if it is unknown.
+     * @return The port that this LDAP listener is listening on.
      */
     public int getPort() {
-        final SocketAddress socketAddress = getSocketAddress();
-        if (socketAddress instanceof InetSocketAddress) {
-            final InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress;
-            return inetSocketAddress.getPort();
-        } else {
-            return -1;
-        }
+        return getSocketAddress().getPort();
     }
 
     /**
@@ -179,7 +162,7 @@
      *
      * @return The address that this LDAP listener is listening on.
      */
-    public SocketAddress getSocketAddress() {
+    public InetSocketAddress getSocketAddress() {
         return impl.getSocketAddress();
     }
 

--
Gitblit v1.10.0