| | |
| | | * |
| | | * |
| | | * 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; |
| | | |
| | | /** |
| | |
| | | * @throws NullPointerException |
| | | * If {@code address} was {@code null}. |
| | | */ |
| | | public LDAPConnectionFactory(final SocketAddress address) { |
| | | public LDAPConnectionFactory(final InetSocketAddress address) { |
| | | this(address, new LDAPOptions()); |
| | | } |
| | | |
| | |
| | | * @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); |
| | | } |
| | |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | |
| | | * 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 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return The address that this LDAP listener is listening on. |
| | | */ |
| | | public SocketAddress getSocketAddress() { |
| | | public InetSocketAddress getSocketAddress() { |
| | | return impl.getSocketAddress(); |
| | | } |
| | | |