类 ClientConfiguration

java.lang.Object
com.baidu.mochow.client.ClientConfiguration

@NotThreadSafe public class ClientConfiguration extends Object
Basic client configurations for Mochow clients.
  • 字段详细资料

    • DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS

      public static final int DEFAULT_CONNECTION_TIMEOUT_IN_MILLIS
      The default timeout for creating new connections.
      另请参阅:
    • DEFAULT_SOCKET_TIMEOUT_IN_MILLIS

      public static final int DEFAULT_SOCKET_TIMEOUT_IN_MILLIS
      The default timeout for reading from a connected socket.
      另请参阅:
    • DEFAULT_MAX_CONNECTIONS

      public static final int DEFAULT_MAX_CONNECTIONS
      The default max connection pool size.
      另请参阅:
    • defaultProtocol

      public static Protocol defaultProtocol
      The default protocol.
  • 构造器详细资料

    • ClientConfiguration

      public ClientConfiguration()
      Constructs a new ClientConfiguration instance with default settings.
    • ClientConfiguration

      public ClientConfiguration(ClientConfiguration other)
      Constructs a new ClientConfiguration instance with the same settings as the specified configuration.
      参数:
      other - the configuration to copy settings from.
    • ClientConfiguration

      public ClientConfiguration(ClientConfiguration other, String endpoint)
      Constructs a new ClientConfiguration instance with the same settings as the specified configuration. This constructor is used to create a client configuration from one SDK to another SDK. e.g. from VOD to BOS. In this case endpoint should be changed while other attributes keep same.
      参数:
      other - the configuration to copy settings from.
      endpoint - the endpoint
  • 方法详细资料

    • setProtocol

      public void setProtocol(Protocol protocol)
      Sets the protocol (HTTP/HTTPS) to use when connecting to Mochow services.
      参数:
      protocol - the protocol (HTTP/HTTPS) to use when connecting to Mochow services.
    • withProtocol

      public ClientConfiguration withProtocol(Protocol protocol)
      Sets the protocol (HTTP/HTTPS) to use when connecting to Mochow services, and returns the updated configuration instance.
      参数:
      protocol - the protocol (HTTP/HTTPS) to use when connecting to Mochow services.
      返回:
      the updated configuration instance.
    • setMaxConnections

      public void setMaxConnections(int maxConnections)
      Sets the maximum number of open HTTP connections.
      参数:
      maxConnections - the maximum number of open HTTP connections.
      抛出:
      IllegalArgumentException - if maxConnections is negative.
    • withMaxConnections

      public ClientConfiguration withMaxConnections(int maxConnections)
      Sets the maximum number of open HTTP connections, and returns the updated configuration instance.
      参数:
      maxConnections - the maximum number of open HTTP connections.
      返回:
      the updated configuration instance.
      抛出:
      IllegalArgumentException - if maxConnections is negative.
    • setIoThreadCount

      public void setIoThreadCount(int ioThreadCount)
      Sets the maximum number of open io thread.
      参数:
      ioThreadCount - the maximum number of open HTTP connections.
      抛出:
      IllegalArgumentException - if ioThreadCount is negative.
    • withIoThreadCount

      public ClientConfiguration withIoThreadCount(int ioThreadCount)
      Sets the maximum number of io thread, and returns the updated configuration instance.
      参数:
      ioThreadCount - the maximum number of io thread.
      返回:
      the updated configuration instance.
      抛出:
      IllegalArgumentException - if ioThreadCount is negative.
    • withLocalAddress

      public ClientConfiguration withLocalAddress(InetAddress localAddress)
      Sets the optional local address to bind when connecting to Mochow services, and returns the updated configuration instance.
      参数:
      localAddress - the optional local address to bind when connecting to Mochow services.
      返回:
      the updated configuration instance.
    • setRetryPolicy

      public void setRetryPolicy(RetryPolicy retryPolicy)
      Sets the retry policy for failed requests.
      参数:
      retryPolicy - the retry policy for failed requests.
    • withRetryPolicy

      public ClientConfiguration withRetryPolicy(RetryPolicy retryPolicy)
      Sets the retry policy for failed requests, and returns the updated configuration instance.
      参数:
      retryPolicy - the retry policy for failed requests.
      返回:
      the updated configuration instance.
    • setSocketTimeoutInMillis

      public void setSocketTimeoutInMillis(int socketTimeoutInMillis)
      Sets the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets. A value of 0 means infinity, and is not recommended.
      参数:
      socketTimeoutInMillis - the socket timeout (SO_TIMEOUT) in milliseconds.
      抛出:
      IllegalArgumentException - if socketTimeoutInMillis is negative.
    • withSocketTimeoutInMillis

      public ClientConfiguration withSocketTimeoutInMillis(int socketTimeoutInMillis)
      Sets the socket timeout (SO_TIMEOUT) in milliseconds, which is a maximum period inactivity between two consecutive data packets, and returns the updated configuration instance. A value of 0 means infinity, and is not recommended.
      参数:
      socketTimeoutInMillis - the socket timeout (SO_TIMEOUT) in milliseconds.
      返回:
      the updated configuration instance.
      抛出:
      IllegalArgumentException - if socketTimeoutInMillis is negative.
    • setConnectionTimeoutInMillis

      public void setConnectionTimeoutInMillis(int connectionTimeoutInMillis)
      Sets the connection timeout in milliseconds. A value of 0 means infinity, and is not recommended.
      参数:
      connectionTimeoutInMillis - the connection timeout in milliseconds.
      抛出:
      IllegalArgumentException - if connectionTimeoutInMillis is negative.
    • withConnectionTimeoutInMillis

      public ClientConfiguration withConnectionTimeoutInMillis(int connectionTimeoutInMillis)
      Sets the connection timeout in milliseconds, and returns the updated configuration instance. A value of 0 means infinity, and is not recommended.
      参数:
      connectionTimeoutInMillis - the connection timeout in milliseconds.
      返回:
      the updated configuration instance.
      抛出:
      IllegalArgumentException - if connectionTimeoutInMillis is negative.
    • withSocketBufferSizeInBytes

      public ClientConfiguration withSocketBufferSizeInBytes(int socketBufferSizeInBytes)
      Sets the optional size (in bytes) for the low level TCP socket buffer, and returns the updated configuration instance. This is an advanced option for advanced users who want to tune low level TCP parameters to try and squeeze out more performance. Ignored if not positive.
      参数:
      socketBufferSizeInBytes - the optional size (in bytes) for the low level TCP socket buffer.
      返回:
      the updated configuration instance.
    • getEndpoint

      public String getEndpoint()
      Returns the service endpoint URL to which the client will connect.
      返回:
      the service endpoint URL to which the client will connect.
    • setEndpoint

      public void setEndpoint(String endpoint)
      Sets the service endpoint URL to which the client will connect.
      参数:
      endpoint - the service endpoint URL to which the client will connect.
      抛出:
      IllegalArgumentException - if endpoint is not a valid URL.
      NullPointerException - if endpoint is null.
    • withEndpoint

      public ClientConfiguration withEndpoint(String endpoint)
      Sets the service endpoint URL to which the client will connect, and returns the updated configuration instance.
      参数:
      endpoint - the service endpoint URL to which the client will connect.
      返回:
      the updated configuration instance.
      抛出:
      IllegalArgumentException - if endpoint is not a valid URL.
      NullPointerException - if endpoint is null.
    • setCredentials

      public void setCredentials(Credentials credentials)
      Sets the Mochow credentials used by the client to sign HTTP requests.
      参数:
      credentials - the Mochow credentials used by the client to sign HTTP requests.
      抛出:
      NullPointerException - if credentials is null.
    • withCredentials

      public ClientConfiguration withCredentials(Credentials credentials)
      Sets the Mochow credentials used by the client to sign HTTP requests, and returns the updated configuration instance.
      参数:
      credentials - the Mochow credentials used by the client to sign HTTP requests.
      返回:
      the updated configuration instance.
      抛出:
      NullPointerException - if credentials is null.
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object