Package com.mongodb

Class ServerAddress

java.lang.Object
com.mongodb.ServerAddress
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
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:
  • Constructor Details

    • 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 address
      port - mongod port
    • ServerAddress

      public ServerAddress(InetSocketAddress inetSocketAddress)
      Creates a ServerAddress
      Parameters:
      inetSocketAddress - inet socket address containing hostname and port
    • ServerAddress

      public ServerAddress(@Nullable String host, int port)
      Creates a ServerAddress
      Parameters:
      host - hostname
      port - mongod port
  • Method Details

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getHost

      public String getHost()
      Gets the hostname
      Returns:
      hostname
    • getPort

      public int getPort()
      Gets the port number
      Returns:
      port
    • getSocketAddress

      @Deprecated public InetSocketAddress getSocketAddress()
      Deprecated.
      Gets the underlying socket address
      Returns:
      socket address
    • getSocketAddresses

      @Deprecated public List<InetSocketAddress> getSocketAddresses()
      Gets all underlying socket addresses
      Returns:
      array of socket addresses
      Since:
      3.9
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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