Class ConnectionPolicy


  • public final class ConnectionPolicy
    extends Object
    Represents the Connection policy associated with a DocumentClient in the Azure Cosmos DB database service.
    • Constructor Detail

      • ConnectionPolicy

        public ConnectionPolicy()
        Constructor.
    • Method Detail

      • defaultPolicy

        public static ConnectionPolicy defaultPolicy()
        Gets the default connection policy.
        Returns:
        the default connection policy.
      • requestTimeoutInMillis

        public int requestTimeoutInMillis()
        Gets the request timeout (time to wait for response from network peer) in milliseconds.
        Returns:
        the request timeout in milliseconds.
      • requestTimeoutInMillis

        public ConnectionPolicy requestTimeoutInMillis​(int requestTimeoutInMillis)
        Sets the request timeout (time to wait for response from network peer) in milliseconds. The default is 60 seconds.
        Parameters:
        requestTimeoutInMillis - the request timeout in milliseconds.
        Returns:
        the ConnectionPolicy.
      • connectionMode

        public ConnectionMode connectionMode()
        Gets the connection mode used in the client.
        Returns:
        the connection mode.
      • connectionMode

        public ConnectionPolicy connectionMode​(ConnectionMode connectionMode)
        Sets the connection mode used in the client.
        Parameters:
        connectionMode - the connection mode.
        Returns:
        the ConnectionPolicy.
      • maxPoolSize

        public int maxPoolSize()
        Gets the value of the connection pool size the client is using.
        Returns:
        connection pool size.
      • maxPoolSize

        public ConnectionPolicy maxPoolSize​(int maxPoolSize)
        Sets the value of the connection pool size, the default is 1000.
        Parameters:
        maxPoolSize - The value of the connection pool size.
        Returns:
        the ConnectionPolicy.
      • idleConnectionTimeoutInMillis

        public int idleConnectionTimeoutInMillis()
        Gets the value of the timeout for an idle connection, the default is 60 seconds.
        Returns:
        Idle connection timeout.
      • idleConnectionTimeoutInMillis

        public ConnectionPolicy idleConnectionTimeoutInMillis​(int idleConnectionTimeoutInMillis)
        sets the value of the timeout for an idle connection. After that time, the connection will be automatically closed.
        Parameters:
        idleConnectionTimeoutInMillis - the timeout for an idle connection in seconds.
        Returns:
        the ConnectionPolicy.
      • userAgentSuffix

        public String userAgentSuffix()
        Gets the value of user-agent suffix.
        Returns:
        the value of user-agent suffix.
      • userAgentSuffix

        public ConnectionPolicy userAgentSuffix​(String userAgentSuffix)
        sets the value of the user-agent suffix.
        Parameters:
        userAgentSuffix - The value to be appended to the user-agent header, this is used for monitoring purposes.
        Returns:
        the ConnectionPolicy.
      • retryOptions

        public RetryOptions retryOptions()
        Gets the retry policy options associated with the DocumentClient instance.
        Returns:
        the RetryOptions instance.
      • retryOptions

        public ConnectionPolicy retryOptions​(RetryOptions retryOptions)
        Sets the retry policy options associated with the DocumentClient instance.

        Properties in the RetryOptions class allow application to customize the built-in retry policies. This property is optional. When it's not set, the SDK uses the default values for configuring the retry policies. See RetryOptions class for more details.

        Parameters:
        retryOptions - the RetryOptions instance.
        Returns:
        the ConnectionPolicy.
      • enableEndpointDiscovery

        public boolean enableEndpointDiscovery()
        Gets the flag to enable endpoint discovery for geo-replicated database accounts.
        Returns:
        whether endpoint discovery is enabled.
      • enableEndpointDiscovery

        public ConnectionPolicy enableEndpointDiscovery​(boolean enableEndpointDiscovery)
        Sets the flag to enable endpoint discovery for geo-replicated database accounts.

        When EnableEndpointDiscovery is true, the SDK will automatically discover the current write and read regions to ensure requests are sent to the correct region based on the capability of the region and the user's preference.

        The default value for this property is true indicating endpoint discovery is enabled.

        Parameters:
        enableEndpointDiscovery - true if EndpointDiscovery is enabled.
        Returns:
        the ConnectionPolicy.
      • usingMultipleWriteLocations

        public boolean usingMultipleWriteLocations()
        Gets the flag to enable writes on any locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service. When the value of this property is true, the SDK will direct write operations to available writable locations of geo-replicated database account. Writable locations are ordered by PreferredLocations property. Setting the property value to true has no effect until EnableMultipleWriteLocations in DatabaseAccount is also set to true. DEFAULT value is false indicating that writes are only directed to first region in PreferredLocations property.
        Returns:
        flag to enable writes on any locations (regions) for geo-replicated database accounts.
      • enableReadRequestsFallback

        public Boolean enableReadRequestsFallback()
        Gets whether to allow for reads to go to multiple regions configured on an account of Azure Cosmos DB service. DEFAULT value is null. If this property is not set, the default is true for all Consistency Levels other than Bounded Staleness, The default is false for Bounded Staleness. 1. enableEndpointDiscovery is true 2. the Azure Cosmos DB account has more than one region
        Returns:
        flag to allow for reads to go to multiple regions configured on an account of Azure Cosmos DB service.
      • usingMultipleWriteLocations

        public ConnectionPolicy usingMultipleWriteLocations​(boolean usingMultipleWriteLocations)
        Sets the flag to enable writes on any locations (regions) for geo-replicated database accounts in the Azure Cosmos DB service. When the value of this property is true, the SDK will direct write operations to available writable locations of geo-replicated database account. Writable locations are ordered by PreferredLocations property. Setting the property value to true has no effect until EnableMultipleWriteLocations in DatabaseAccount is also set to true. DEFAULT value is false indicating that writes are only directed to first region in PreferredLocations property.
        Parameters:
        usingMultipleWriteLocations - flag to enable writes on any locations (regions) for geo-replicated database accounts.
        Returns:
        the ConnectionPolicy.
      • enableReadRequestsFallback

        public ConnectionPolicy enableReadRequestsFallback​(Boolean enableReadRequestsFallback)
        Sets whether to allow for reads to go to multiple regions configured on an account of Azure Cosmos DB service. DEFAULT value is null. If this property is not set, the default is true for all Consistency Levels other than Bounded Staleness, The default is false for Bounded Staleness. 1. enableEndpointDiscovery is true 2. the Azure Cosmos DB account has more than one region
        Parameters:
        enableReadRequestsFallback - flag to enable reads to go to multiple regions configured on an account of Azure Cosmos DB service.
        Returns:
        the ConnectionPolicy.
      • preferredLocations

        public List<String> preferredLocations()
        Gets the preferred locations for geo-replicated database accounts
        Returns:
        the list of preferred location.
      • preferredLocations

        public ConnectionPolicy preferredLocations​(List<String> preferredLocations)
        Sets the preferred locations for geo-replicated database accounts. For example, "East US" as the preferred location.

        When EnableEndpointDiscovery is true and PreferredRegions is non-empty, the SDK will prefer to use the locations in the collection in the order they are specified to perform operations.

        If EnableEndpointDiscovery is set to false, this property is ignored.

        Parameters:
        preferredLocations - the list of preferred locations.
        Returns:
        the ConnectionPolicy.
      • proxy

        public InetSocketAddress proxy()
        Gets the InetSocketAddress of proxy server.
        Returns:
        the value of proxyHost.
      • proxy

        public ConnectionPolicy proxy​(String proxyHost,
                                      int proxyPort)
        This will create the InetSocketAddress for proxy server, all the requests to cosmoDB will route from this address.
        Parameters:
        proxyHost - The proxy server host.
        proxyPort - The proxy server port.
        Returns:
        the ConnectionPolicy.