ConnectionMigrationOptions.Builder

public class ConnectionMigrationOptions.Builder


Builder for ConnectionMigrationOptions.

Summary

Public methods

ConnectionMigrationOptions.Builder

Sets whether connections can be migrated to an alternate network when Cronet detects a degradation of the path currently in use.

ConnectionMigrationOptions.Builder

Enables the possibility of migrating connections to an alternate server address at the server's request.

ConnectionMigrationOptions

Creates and returns the final ConnectionMigrationOptions instance, based on the values in this builder.

ConnectionMigrationOptions.Builder
enableDefaultNetworkMigration(
    boolean enableDefaultNetworkConnectionMigration
)

Enables the possibility of migrating connections on default network change.

ConnectionMigrationOptions.Builder

Enables the possibility of migrating connections if the current path is performing poorly.

ConnectionMigrationOptions.Builder

Configures whether migration of idle connections should be enabled or not.

ConnectionMigrationOptions.Builder
@ConnectionMigrationOptions.Experimental
retryPreHandshakeErrorsOnNonDefaultNetwork(
    boolean retryPreHandshakeErrorsOnAlternateNetwork
)

Sets whether connections with pre-handshake errors should be retried on an alternative network.

ConnectionMigrationOptions.Builder
@ConnectionMigrationOptions.Experimental
setIdleConnectionMigrationPeriodSeconds(
    long idleConnectionMigrationPeriodSeconds
)

Sets the maximum idle period for which connections will still be migrated, in seconds.

ConnectionMigrationOptions.Builder

Sets the maximum number of migrations to the non-default network upon encountering path degradation for the existing connection.

ConnectionMigrationOptions.Builder
@ConnectionMigrationOptions.Experimental
setMaxTimeOnNonDefaultNetworkSeconds(
    long maxTimeOnNonDefaultNetworkSeconds
)

Sets the maximum period for which eagerly migrated connections should remain on the non-default network before they're migrated back.

ConnectionMigrationOptions.Builder

Sets the maximum number of migrations to the non-default network upon encountering write errors.

Public methods

allowNonDefaultNetworkUsage

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder allowNonDefaultNetworkUsage(boolean enable)

Sets whether connections can be migrated to an alternate network when Cronet detects a degradation of the path currently in use.

Note: This setting can result in requests being sent on non-default metered networks. Make sure you're using metered networks sparingly, and fine tune parameters like setMaxPathDegradingNonDefaultNetworkMigrationsCount and setMaxTimeOnNonDefaultNetworkSeconds to limit the time on non-default networks.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

allowServerMigration

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder allowServerMigration(boolean allowServerMigration)

Enables the possibility of migrating connections to an alternate server address at the server's request.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

build

public ConnectionMigrationOptions build()

Creates and returns the final ConnectionMigrationOptions instance, based on the values in this builder.

enableDefaultNetworkMigration

public ConnectionMigrationOptions.Builder enableDefaultNetworkMigration(
    boolean enableDefaultNetworkConnectionMigration
)

Enables the possibility of migrating connections on default network change. If enabled, active QUIC connections will be migrated onto the new network when the platform indicates that the default network is changing.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

enablePathDegradationMigration

public ConnectionMigrationOptions.Builder enablePathDegradationMigration(boolean enable)

Enables the possibility of migrating connections if the current path is performing poorly.

Depending on other configuration, this can result to migrating the connections within the same default network, or to a non-default network.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

migrateIdleConnections

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder migrateIdleConnections(boolean migrateIdleConnections)

Configures whether migration of idle connections should be enabled or not.

If set to true, idle connections will be migrated too, as long as they haven't been idle for too long. The setting is shared for all connection migration types. The maximum idle period for which connections will still be migrated can be customized using setIdleConnectionMigrationPeriodSeconds.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

retryPreHandshakeErrorsOnNonDefaultNetwork

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder retryPreHandshakeErrorsOnNonDefaultNetwork(
    boolean retryPreHandshakeErrorsOnAlternateNetwork
)

Sets whether connections with pre-handshake errors should be retried on an alternative network.

If true, a new connection may be established an alternate network if it fails on the default network before handshake is confirmed.

Note: similarly to allowNonDefaultNetworkUsage this setting can result in requests being sent on non-default metered networks. Use with caution!

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

setIdleConnectionMigrationPeriodSeconds

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder setIdleConnectionMigrationPeriodSeconds(
    long idleConnectionMigrationPeriodSeconds
)

Sets the maximum idle period for which connections will still be migrated, in seconds. The setting is shared for all connection migration types.

Only relevant if migrateIdleConnections is enabled.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

setMaxPathDegradingNonDefaultNetworkMigrationsCount

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder setMaxPathDegradingNonDefaultNetworkMigrationsCount(
    int maxPathDegradingEagerMigrationsCount
)

Sets the maximum number of migrations to the non-default network upon encountering path degradation for the existing connection. Counted cumulatively per network per connection.

Only relevant if allowNonDefaultNetworkUsage is enabled.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

setMaxTimeOnNonDefaultNetworkSeconds

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder setMaxTimeOnNonDefaultNetworkSeconds(
    long maxTimeOnNonDefaultNetworkSeconds
)

Sets the maximum period for which eagerly migrated connections should remain on the non-default network before they're migrated back. This time is not cumulative - each migration off the default network for each connection measures and compares to this value separately.

Only relevant if allowNonDefaultNetworkUsage is enabled.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining

setMaxWriteErrorNonDefaultNetworkMigrationsCount

@ConnectionMigrationOptions.Experimental
public ConnectionMigrationOptions.Builder setMaxWriteErrorNonDefaultNetworkMigrationsCount(
    int maxWriteErrorEagerMigrationsCount
)

Sets the maximum number of migrations to the non-default network upon encountering write errors. Counted cumulatively per network per connection.

Only relevant if allowNonDefaultNetworkUsage is enabled.

Returns
ConnectionMigrationOptions.Builder

this builder for chaining