你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

JobClient Class

  • java.lang.Object
    • com.microsoft.azure.sdk.iot.service.jobs.JobClient

public class JobClient

JobClient enables service client to schedule and cancel jobs for a group of devices using the IoTHub.

Constructor Summary

Modifier Constructor Description
protected JobClient()
JobClient(String connectionString)

Constructor to create instance from connection string

JobClient(String hostName, AzureSasCredential azureSasCredential)

Create a new JobClient instance.

JobClient(String hostName, AzureSasCredential azureSasCredential, JobClientOptions options)

Create a new JobClient instance.

JobClient(String hostName, TokenCredential credential)

Create a new JobClient instance.

JobClient(String hostName, TokenCredential credential, JobClientOptions options)

Create a new JobClient instance.

JobClient(String connectionString, JobClientOptions options)

Constructor to create instance from connection string

Method Summary

Modifier and Type Method and Description
synchronized JobResult cancelJob(String jobId)

Cancel a current jod on the IoTHub

static JobClient createFromConnectionString(String connectionString)

Deprecated

because this method declares a thrown IOException even though it never throws an IOException. Users are recommended to use JobClient(String connectionString) instead since it does not declare this exception even though it constructs the same JobClient.

Static constructor to create instance from connection string

synchronized JobResult getJob(String jobId)

Get the current job on the iotHub.

synchronized JobResult getNextJob(Query query)

returns the next job result in response.

synchronized boolean hasNextJob(Query query)

returns the availability of next job result in response.

synchronized Query queryDeviceJob(String sqlQuery)

Query for device Job limited by default page size of 100 for response

synchronized Query queryDeviceJob(String sqlQuery, Integer pageSize)

Query for device Job

synchronized Query queryJobResponse(JobType jobType, JobStatus jobStatus)

Query the iot hub for a jobs response.

synchronized Query queryJobResponse(JobType jobType, JobStatus jobStatus, Integer pageSize)

Query the iot hub for a jobs response.

synchronized JobResult scheduleDeviceMethod(String jobId, String queryCondition, String methodName, Long responseTimeoutInSeconds, Long connectTimeoutInSeconds, Object payload, Date startTimeUtc, long maxExecutionTimeInSeconds)

Creates a new Job to invoke method on one or multiple devices

synchronized JobResult scheduleUpdateTwin(String jobId, String queryCondition, DeviceTwinDevice updateTwin, Date startTimeUtc, long maxExecutionTimeInSeconds)

Creates a new Job to update twin tags and desired properties on one or multiple devices

Methods inherited from java.lang.Object

java.lang.Object.clone java.lang.Object.equals java.lang.Object.finalize java.lang.Object.getClass java.lang.Object.hashCode java.lang.Object.notify java.lang.Object.notifyAll java.lang.Object.toString java.lang.Object.wait java.lang.Object.wait java.lang.Object.wait

Constructor Details

JobClient

protected JobClient()

JobClient

public JobClient(String connectionString)

Constructor to create instance from connection string

Parameters:

connectionString - The iot hub connection string

JobClient

public JobClient(String hostName, AzureSasCredential azureSasCredential)

Create a new JobClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
azureSasCredential - The SAS token provider that will be used for authentication.

JobClient

public JobClient(String hostName, AzureSasCredential azureSasCredential, JobClientOptions options)

Create a new JobClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
azureSasCredential - The SAS token provider that will be used for authentication.
options - The connection options to use when connecting to the service.

JobClient

public JobClient(String hostName, TokenCredential credential)

Create a new JobClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
credential - The custom TokenCredential that will provide authentication tokens to this library when they are needed. The provided tokens must be Json Web Tokens.

JobClient

public JobClient(String hostName, TokenCredential credential, JobClientOptions options)

Create a new JobClient instance.

Parameters:

hostName - The hostname of your IoT Hub instance (For instance, "your-iot-hub.azure-devices.net")
credential - The custom TokenCredential that will provide authentication tokens to this library when they are needed. The provided tokens must be Json Web Tokens.
options - The connection options to use when connecting to the service.

JobClient

public JobClient(String connectionString, JobClientOptions options)

Constructor to create instance from connection string

Parameters:

connectionString - The iot hub connection string
options - The connection options to use when connecting to the service.

Method Details

cancelJob

public synchronized JobResult cancelJob(String jobId)

Cancel a current jod on the IoTHub

Parameters:

jobId - Unique Job Id for this job

Returns:

a jobResult object

Throws:

java.lang.IllegalArgumentException - if the jobId is invalid
java.io.IOException - if the jobId is invalid
IotHubException - if the jobId is invalid

createFromConnectionString


public static JobClient createFromConnectionString(String connectionString)

Deprecated

because this method declares a thrown IOException even though it never throws an IOException. Users are recommended to use JobClient(String connectionString) instead since it does not declare this exception even though it constructs the same JobClient.

Static constructor to create instance from connection string

Parameters:

connectionString - The iot hub connection string

Returns:

The instance of JobClient

Throws:

java.io.IOException - This exception is never thrown.
java.lang.IllegalArgumentException - This exception is never thrown.

getJob

public synchronized JobResult getJob(String jobId)

Get the current job on the iotHub.

Parameters:

jobId - Unique Job Id for this job

Returns:

a jobResult object

Throws:

java.lang.IllegalArgumentException - if the jobId is invalid
java.io.IOException - if the jobId is invalid
IotHubException - if the jobId is invalid

getNextJob

public synchronized JobResult getNextJob(Query query)

returns the next job result in response. Query's further if page size has been met and has next is not called

Parameters:

query - Query for which to look for next job response by

Returns:

next job result if available

Throws:

java.io.IOException - When IotHub fails to respond
IotHubException - When IotHub fails to respond
java.util.NoSuchElementException - When IotHub fails to respond

hasNextJob

public synchronized boolean hasNextJob(Query query)

returns the availability of next job result in response. Query's further if page size has been met

Parameters:

query - Query for which to look for next job response by

Returns:

true if next job result is available , false otherwise

Throws:

IotHubException - When IotHub fails to respond
java.io.IOException - When IotHub fails to respond

queryDeviceJob

public synchronized Query queryDeviceJob(String sqlQuery)

Query for device Job limited by default page size of 100 for response

Parameters:

sqlQuery - sql style query over device.jobs

Returns:

Query object for this query

Throws:

IotHubException - When IotHub fails to respond
java.io.IOException - When IotHub fails to respond

queryDeviceJob

public synchronized Query queryDeviceJob(String sqlQuery, Integer pageSize)

Query for device Job

Parameters:

sqlQuery - sql style query over device.jobs
pageSize - the value per which to limit the size of query response by.

Returns:

Query object for this query

Throws:

IotHubException - When IotHub fails to respond
java.io.IOException - When IotHub fails to respond

queryJobResponse

public synchronized Query queryJobResponse(JobType jobType, JobStatus jobStatus)

Query the iot hub for a jobs response. Query response are limited by default page size per attempt

Parameters:

jobType - The type of job to query for
jobStatus - The status of the job to query for

Returns:

A query object on which to look for responses by

Throws:

IotHubException - If any of the input parameters are incorrect
java.io.IOException - If any of the input parameters are incorrect

queryJobResponse

public synchronized Query queryJobResponse(JobType jobType, JobStatus jobStatus, Integer pageSize)

Query the iot hub for a jobs response. Query response are limited by page size per attempt

Parameters:

jobType - The type of job to query for
jobStatus - The status of the job to query for
pageSize - The value to which to limit the job response size by

Returns:

A query object on which to look for responses by

Throws:

java.io.IOException - If any of the input parameters are incorrect
IotHubException - If any of the input parameters are incorrect

scheduleDeviceMethod

public synchronized JobResult scheduleDeviceMethod(String jobId, String queryCondition, String methodName, Long responseTimeoutInSeconds, Long connectTimeoutInSeconds, Object payload, Date startTimeUtc, long maxExecutionTimeInSeconds)

Creates a new Job to invoke method on one or multiple devices

Parameters:

jobId - Unique Job Id for this job
queryCondition - Query condition to evaluate which devices to run the job on. It can be null or empty
methodName - Method name to be invoked
responseTimeoutInSeconds - Maximum interval of time, in seconds, that the Direct Method will wait for answer. It can be null.
connectTimeoutInSeconds - Maximum interval of time, in seconds, that the Direct Method will wait for the connection. It can be null.
payload - Object that contains the payload defined by the user. It can be null.
startTimeUtc - Date time in Utc to start the job
maxExecutionTimeInSeconds - Max execution time in seconds, i.e., ttl duration the job can run

Returns:

a jobResult object

Throws:

java.lang.IllegalArgumentException - if one of the provided parameters is invalid
java.io.IOException - if one of the provided parameters is invalid
IotHubException - if one of the provided parameters is invalid

scheduleUpdateTwin

public synchronized JobResult scheduleUpdateTwin(String jobId, String queryCondition, DeviceTwinDevice updateTwin, Date startTimeUtc, long maxExecutionTimeInSeconds)

Creates a new Job to update twin tags and desired properties on one or multiple devices

Parameters:

jobId - Unique Job Id for this job
queryCondition - Query condition to evaluate which devices to run the job on. It can be null or empty
updateTwin - Twin object to use for the update
startTimeUtc - Date time in Utc to start the job
maxExecutionTimeInSeconds - Max execution time in seconds, i.e., ttl duration the job can run

Returns:

a jobResult object

Throws:

java.lang.IllegalArgumentException - if one of the provided parameters is invalid
java.io.IOException - if one of the provided parameters is invalid
IotHubException - if one of the provided parameters is invalid

Applies to