Package com.mongodb
Class ServerAddress
- java.lang.Object
-
- com.mongodb.ServerAddress
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DBAddress
,UnixServerAddress
@Immutable public class ServerAddress extends Object implements Serializable
Represents the location of a Mongo server - i.e. server name and port number- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ServerAddress()
Creates a ServerAddress with default host and portServerAddress(String host)
Creates a ServerAddress with default portServerAddress(String host, int port)
Creates a ServerAddressServerAddress(InetAddress inetAddress)
Creates a ServerAddress with default portServerAddress(InetAddress inetAddress, int port)
Creates a ServerAddressServerAddress(InetSocketAddress inetSocketAddress)
Creates a ServerAddress
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static String
defaultHost()
Returns the default database host: "127.0.0.1"static int
defaultPort()
Returns the default database port: 27017boolean
equals(Object o)
String
getHost()
Gets the hostnameint
getPort()
Gets the port numberInetSocketAddress
getSocketAddress()
Gets the underlying socket addressList<InetSocketAddress>
getSocketAddresses()
Gets all underlying socket addressesint
hashCode()
boolean
sameHost(String hostName)
Deprecated.use theequals(Object)
method insteadString
toString()
-
-
-
Constructor Detail
-
ServerAddress
public ServerAddress()
Creates a ServerAddress with default host and port
-
ServerAddress
public ServerAddress(@Nullable String host)
Creates a ServerAddress with default port- Parameters:
host
- hostname
-
ServerAddress
public ServerAddress(InetAddress inetAddress)
Creates a ServerAddress with default port- Parameters:
inetAddress
- host address
-
ServerAddress
public ServerAddress(InetAddress inetAddress, int port)
Creates a ServerAddress- Parameters:
inetAddress
- host addressport
- mongod port
-
ServerAddress
public ServerAddress(InetSocketAddress inetSocketAddress)
Creates a ServerAddress- Parameters:
inetSocketAddress
- inet socket address containing hostname and port
-
-
Method Detail
-
getHost
public String getHost()
Gets the hostname- Returns:
- hostname
-
getPort
public int getPort()
Gets the port number- Returns:
- port
-
getSocketAddress
public InetSocketAddress getSocketAddress()
Gets the underlying socket address- Returns:
- socket address
-
getSocketAddresses
public List<InetSocketAddress> getSocketAddresses()
Gets all underlying socket addresses- Returns:
- array of socket addresses
- Since:
- 3.9
-
defaultHost
public static String defaultHost()
Returns the default database host: "127.0.0.1"- Returns:
- IP address of default host.
-
defaultPort
public static int defaultPort()
Returns the default database port: 27017- Returns:
- the default port
-
sameHost
@Deprecated public boolean sameHost(String hostName)
Deprecated.use theequals(Object)
method insteadDetermines whether this address is the same as a given host.- Parameters:
hostName
- the address to compare- Returns:
- if they are the same
-
-