Package com.mongodb

Class ServerAddress

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    UnixServerAddress

    @Immutable
    public class ServerAddress
    extends java.lang.Object
    implements java.io.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 port
      ServerAddress​(java.lang.String host)
      Creates a ServerAddress with default port
      ServerAddress​(java.lang.String host, int port)
      Creates a ServerAddress
      ServerAddress​(java.net.InetAddress inetAddress)
      Creates a ServerAddress with default port
      ServerAddress​(java.net.InetAddress inetAddress, int port)
      Creates a ServerAddress
      ServerAddress​(java.net.InetSocketAddress inetSocketAddress)
      Creates a ServerAddress
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String defaultHost()
      Returns the default database host: "127.0.0.1"
      static int defaultPort()
      Returns the default database port: 27017
      boolean equals​(java.lang.Object o)  
      java.lang.String getHost()
      Gets the hostname
      int getPort()
      Gets the port number
      java.net.InetSocketAddress getSocketAddress()
      Gets the underlying socket address
      java.util.List<java.net.InetSocketAddress> getSocketAddresses()
      Gets all underlying socket addresses
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ServerAddress

        public ServerAddress()
        Creates a ServerAddress with default host and port
      • ServerAddress

        public ServerAddress​(@Nullable
                             java.lang.String host)
        Creates a ServerAddress with default port
        Parameters:
        host - hostname
      • ServerAddress

        public ServerAddress​(java.net.InetAddress inetAddress)
        Creates a ServerAddress with default port
        Parameters:
        inetAddress - host address
      • ServerAddress

        public ServerAddress​(java.net.InetAddress inetAddress,
                             int port)
        Creates a ServerAddress
        Parameters:
        inetAddress - host address
        port - mongod port
      • ServerAddress

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

        public ServerAddress​(@Nullable
                             java.lang.String host,
                             int port)
        Creates a ServerAddress
        Parameters:
        host - hostname
        port - mongod port
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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

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

        public java.net.InetSocketAddress getSocketAddress()
        Gets the underlying socket address
        Returns:
        socket address
      • getSocketAddresses

        public java.util.List<java.net.InetSocketAddress> getSocketAddresses()
        Gets all underlying socket addresses
        Returns:
        array of socket addresses
        Since:
        3.9
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • defaultHost

        public static java.lang.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