Class ConnectionParams.Builder
- java.lang.Object
-
- com.google.android.things.iotcore.ConnectionParams.Builder
-
- Enclosing class:
- ConnectionParams
public static class ConnectionParams.Builder extends Object
Builder for ConnectionParams instances.
-
-
Constructor Summary
Constructors Constructor and Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description ConnectionParams
build()
Construct a new ConnectionParams instance with the parameters given to this Builder.ConnectionParams.Builder
setAuthTokenLifetime(long duration, TimeUnit unit)
Set the amount of time authentication tokens used for connecting to Cloud IoT Core remain valid.ConnectionParams.Builder
setBridgeHostname(String bridgeHostname)
Set the MQTT bridge hostname to use when connecting to Cloud IoT Core.ConnectionParams.Builder
setBridgePort(int bridgePort)
Set the MQTT bridge port number to use when connecting to Cloud IoT Core.ConnectionParams.Builder
setDeviceId(String deviceId)
Set the device ID used to register this device in Cloud IoT Core.ConnectionParams.Builder
setProjectId(String projectId)
Set the Google Cloud project ID.ConnectionParams.Builder
setRegistry(String registryId, String cloudRegion)
Set the Cloud IoT Core registry.
-
-
-
Method Detail
-
setProjectId
public ConnectionParams.Builder setProjectId(@NonNull String projectId)
Set the Google Cloud project ID.This parameter is required.
- Parameters:
projectId
- the Google Cloud project ID for these connection parameters- Returns:
- this builder
-
setRegistry
public ConnectionParams.Builder setRegistry(@NonNull String registryId, @NonNull String cloudRegion)
Set the Cloud IoT Core registry.This parameter is required.
- Parameters:
registryId
- the registry's IDcloudRegion
- the registry's cloud region- Returns:
- this builder
-
setDeviceId
public ConnectionParams.Builder setDeviceId(@NonNull String deviceId)
Set the device ID used to register this device in Cloud IoT Core.This parameter is required.
- Parameters:
deviceId
- the Cloud IoT Core device ID to use for these connection parameters- Returns:
- this builder
-
setBridgeHostname
public ConnectionParams.Builder setBridgeHostname(@NonNull String bridgeHostname)
Set the MQTT bridge hostname to use when connecting to Cloud IoT Core.This parameter is optional. If no MQTT bridge hostname is specified, the Google MQTT bridge, mqtt.googleapis.com, is used by default.
- Parameters:
bridgeHostname
- the MQTT bridge hostname to use for these connection parameters- Returns:
- this builder
-
setBridgePort
public ConnectionParams.Builder setBridgePort(int bridgePort)
Set the MQTT bridge port number to use when connecting to Cloud IoT Core.This parameter is optional. If no MQTT bridge port number is specified, port 8883 is used by default.
If port 8883 is blocked by your firewall, you also can use port 443 to connect to the default MQTT bridge, mqtt.googleapis.com.
- Parameters:
bridgePort
- the MQTT bridge port number to use in these connection parameters- Returns:
- this builder
-
setAuthTokenLifetime
public ConnectionParams.Builder setAuthTokenLifetime(long duration, @NonNull TimeUnit unit)
Set the amount of time authentication tokens used for connecting to Cloud IoT Core remain valid.Cloud IoT Core authenticates devices using JSON web tokens (JWTs) that devices send when they initiate a connection with Cloud IoT Core. Those tokens are valid for a limited period of time before they expire. Cloud IoT Core allows a maximum lifetime of 24 hours. The Cloud IoT Core documentation has more information.
This parameter is optional. If no authentication token lifetime is specified, the default lifetime is one hour.
- Parameters:
duration
- duration before explicitly refreshing authorization credentialunit
- the time units for the duration- Returns:
- this builder
-
build
public ConnectionParams build()
Construct a new ConnectionParams instance with the parameters given to this Builder.- Returns:
- a new ConnectionParams instance
- Throws:
IllegalStateException
- if this builder's parameters are invalid
-
-