BlobLeaseAsyncClient Class

  • java.lang.Object
    • com.azure.storage.blob.specialized.BlobLeaseAsyncClient

public final class BlobLeaseAsyncClient

This class provides a client that contains all the leasing operations for BlobContainerAsyncClient and BlobAsyncClient. This client acts as a supplement to those clients and only handles leasing operations.

Instantiating a BlobLeaseAsyncClient

BlobLeaseAsyncClient blobLeaseAsyncClient = new BlobLeaseClientBuilder()
     .blobAsyncClient(blobAsyncClient)
     .buildAsyncClient();
BlobLeaseAsyncClient blobLeaseAsyncClient = new BlobLeaseClientBuilder()
     .containerAsyncClient(blobContainerAsyncClient)
     .buildAsyncClient();

View BlobLeaseClientBuilder for additional ways to construct the client.

For more information about leasing see the container leasing or blob leasing documentation.

Method Summary

Modifier and Type Method and Description
Mono<String> acquireLease(int durationInSeconds)

Acquires a lease for write and delete operations.

Mono<Response<String>> acquireLeaseWithResponse(BlobAcquireLeaseOptions options)

Acquires a lease for write and delete operations.

Mono<Response<String>> acquireLeaseWithResponse(int durationInSeconds, RequestConditions modifiedRequestConditions)

Acquires a lease for write and delete operations.

Mono<Integer> breakLease()

Breaks the previously acquired lease, if it exists.

Mono<Response<Integer>> breakLeaseWithResponse(BlobBreakLeaseOptions options)

Breaks the previously acquired lease, if it exists.

Mono<Response<Integer>> breakLeaseWithResponse(Integer breakPeriodInSeconds, RequestConditions modifiedRequestConditions)

Breaks the previously acquired lease, if it exists.

Mono<String> changeLease(String proposedId)

Changes the lease ID.

Mono<Response<String>> changeLeaseWithResponse(BlobChangeLeaseOptions options)

Changes the lease ID.

Mono<Response<String>> changeLeaseWithResponse(String proposedId, RequestConditions modifiedRequestConditions)

Changes the lease ID.

String getAccountName()

Get associated account name.

String getLeaseId()

Get the lease ID for this lease.

String getResourceUrl()

Gets the URL of the lease client.

Mono<Void> releaseLease()

Releases the previously acquired lease.

Mono<Response<Void>> releaseLeaseWithResponse(RequestConditions modifiedRequestConditions)

Releases the previously acquired lease.

Mono<Response<Void>> releaseLeaseWithResponse(BlobReleaseLeaseOptions options)

Releases the previously acquired lease.

Mono<String> renewLease()

Renews the previously acquired lease.

Mono<Response<String>> renewLeaseWithResponse(RequestConditions modifiedRequestConditions)

Renews the previously acquired lease.

Mono<Response<String>> renewLeaseWithResponse(BlobRenewLeaseOptions options)

Renews the previously acquired lease.

Methods inherited from java.lang.Object

Method Details

acquireLease

public Mono acquireLease(int durationInSeconds)

Acquires a lease for write and delete operations. The lease duration must be between 15 and 60 seconds or -1 for an infinite duration.

Code Samples

client.acquireLease(60).subscribe(response -> System.out.printf("Lease ID is %s%n", response));

Parameters:

durationInSeconds - The duration of the lease between 15 and 60 seconds or -1 for an infinite duration.

Returns:

A reactive response containing the lease ID.

acquireLeaseWithResponse

public Mono> acquireLeaseWithResponse(BlobAcquireLeaseOptions options)

Acquires a lease for write and delete operations. The lease duration must be between 15 and 60 seconds, or -1 for an infinite duration.

Code Samples

BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
     .setIfModifiedSince(OffsetDateTime.now().minusDays(3));

 BlobAcquireLeaseOptions options = new BlobAcquireLeaseOptions(60)
     .setRequestConditions(requestConditions);

 client.acquireLeaseWithResponse(options).subscribe(response ->
     System.out.printf("Lease ID is %s%n", response.getValue()));

Parameters:

Returns:

A reactive response containing the lease ID.

acquireLeaseWithResponse

public Mono> acquireLeaseWithResponse(int durationInSeconds, RequestConditions modifiedRequestConditions)

Acquires a lease for write and delete operations. The lease duration must be between 15 and 60 seconds, or -1 for an infinite duration.

Code Samples

RequestConditions modifiedRequestConditions = new RequestConditions()
     .setIfModifiedSince(OffsetDateTime.now().minusDays(3));

 client.acquireLeaseWithResponse(60, modifiedRequestConditions).subscribe(response ->
     System.out.printf("Lease ID is %s%n", response.getValue()));

Parameters:

durationInSeconds - The duration of the lease between 15 and 60 seconds or -1 for an infinite duration.
modifiedRequestConditions - Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions related to when the resource was changed relative to the given request. The request will fail if the specified condition is not satisfied.

Returns:

A reactive response containing the lease ID.

breakLease

public Mono breakLease()

Breaks the previously acquired lease, if it exists.

Code Samples

client.breakLease().subscribe(response ->
     System.out.printf("The broken lease has %d seconds remaining on the lease", response));

Returns:

A reactive response containing the remaining time in the broken lease in seconds.

breakLeaseWithResponse

public Mono> breakLeaseWithResponse(BlobBreakLeaseOptions options)

Breaks the previously acquired lease, if it exists.

If null is passed for breakPeriodInSeconds a fixed duration lease will break after the remaining lease period elapses and an infinite lease will break immediately.

Code Samples

Integer retainLeaseInSeconds = 5;
 BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 BlobBreakLeaseOptions options = new BlobBreakLeaseOptions()
     .setBreakPeriod(Duration.ofSeconds(retainLeaseInSeconds))
     .setRequestConditions(requestConditions);

 client.breakLeaseWithResponse(options).subscribe(response ->
     System.out.printf("The broken lease has %d seconds remaining on the lease", response.getValue()));

Parameters:

Returns:

A reactive response containing the remaining time in the broken lease in seconds.

breakLeaseWithResponse

public Mono> breakLeaseWithResponse(Integer breakPeriodInSeconds, RequestConditions modifiedRequestConditions)

Breaks the previously acquired lease, if it exists.

If null is passed for breakPeriodInSeconds a fixed duration lease will break after the remaining lease period elapses and an infinite lease will break immediately.

Code Samples

Integer retainLeaseInSeconds = 5;
 RequestConditions modifiedRequestConditions = new RequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.breakLeaseWithResponse(retainLeaseInSeconds, modifiedRequestConditions).subscribe(response ->
     System.out.printf("The broken lease has %d seconds remaining on the lease", response.getValue()));

Parameters:

breakPeriodInSeconds - An optional duration, between 0 and 60 seconds, that the lease should continue before it is broken. If the break period is longer than the time remaining on the lease the remaining time on the lease is used. A new lease will not be available before the break period has expired, but the lease may be held for longer than the break period.
modifiedRequestConditions - Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions related to when the resource was changed relative to the given request. The request will fail if the specified condition is not satisfied.

Returns:

A reactive response containing the remaining time in the broken lease in seconds.

changeLease

public Mono changeLease(String proposedId)

Changes the lease ID.

Code Samples

client.changeLease("proposedId").subscribe(response -> System.out.printf("Changed lease ID is %s%n", response));

Parameters:

proposedId - A new lease ID in a valid GUID format.

Returns:

A reactive response containing the new lease ID.

changeLeaseWithResponse

public Mono> changeLeaseWithResponse(BlobChangeLeaseOptions options)

Changes the lease ID.

Code Samples

BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 BlobChangeLeaseOptions options = new BlobChangeLeaseOptions("proposedId")
     .setRequestConditions(requestConditions);

 client.changeLeaseWithResponse(options).subscribe(response ->
     System.out.printf("Changed lease ID is %s%n", response.getValue()));

Parameters:

Returns:

A reactive response containing the new lease ID.

changeLeaseWithResponse

public Mono> changeLeaseWithResponse(String proposedId, RequestConditions modifiedRequestConditions)

Changes the lease ID.

Code Samples

RequestConditions modifiedRequestConditions = new RequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.changeLeaseWithResponse("proposedId", modifiedRequestConditions).subscribe(response ->
     System.out.printf("Changed lease ID is %s%n", response.getValue()));

Parameters:

proposedId - A new lease ID in a valid GUID format.
modifiedRequestConditions - Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions related to when the resource was changed relative to the given request. The request will fail if the specified condition is not satisfied.

Returns:

A reactive response containing the new lease ID.

getAccountName

public String getAccountName()

Get associated account name.

Returns:

account name associated with this storage resource.

getLeaseId

public String getLeaseId()

Get the lease ID for this lease.

Returns:

the lease ID.

getResourceUrl

public String getResourceUrl()

Gets the URL of the lease client.

The lease will either be a container or blob URL depending on which the lease client is associated.

Returns:

URL of the lease client.

releaseLease

public Mono releaseLease()

Releases the previously acquired lease.

Code Samples

client.releaseLease().subscribe(response -> System.out.println("Completed release lease"));

Returns:

A reactive response signalling completion.

releaseLeaseWithResponse

public Mono> releaseLeaseWithResponse(RequestConditions modifiedRequestConditions)

Releases the previously acquired lease.

Code Samples

RequestConditions modifiedRequestConditions = new RequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.releaseLeaseWithResponse(modifiedRequestConditions).subscribe(response ->
     System.out.printf("Release lease completed with status %d%n", response.getStatusCode()));

Parameters:

modifiedRequestConditions - Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions related to when the resource was changed relative to the given request. The request will fail if the specified condition is not satisfied.

Returns:

A reactive response signalling completion.

releaseLeaseWithResponse

public Mono> releaseLeaseWithResponse(BlobReleaseLeaseOptions options)

Releases the previously acquired lease.

Code Samples

BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
     .setIfModifiedSince(OffsetDateTime.now().minusDays(3));

 BlobReleaseLeaseOptions options = new BlobReleaseLeaseOptions()
     .setRequestConditions(requestConditions);

 client.releaseLeaseWithResponse(options).subscribe(response ->
     System.out.printf("Release lease completed with status %d%n", response.getStatusCode()));

Parameters:

Returns:

A reactive response signalling completion.

renewLease

public Mono renewLease()

Renews the previously acquired lease.

Code Samples

client.renewLease().subscribe(response -> System.out.printf("Renewed lease ID is %s%n", response));

Returns:

A reactive response containing the renewed lease ID.

renewLeaseWithResponse

public Mono> renewLeaseWithResponse(RequestConditions modifiedRequestConditions)

Renews the previously acquired lease.

Code Samples

RequestConditions modifiedRequestConditions = new RequestConditions()
     .setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));

 client.renewLeaseWithResponse(modifiedRequestConditions).subscribe(response ->
     System.out.printf("Renewed lease ID is %s%n", response.getValue()));

Parameters:

modifiedRequestConditions - Standard HTTP Access conditions related to the modification of data. ETag and LastModifiedTime are used to construct conditions related to when the resource was changed relative to the given request. The request will fail if the specified condition is not satisfied.

Returns:

A reactive response containing the renewed lease ID.

renewLeaseWithResponse

public Mono> renewLeaseWithResponse(BlobRenewLeaseOptions options)

Renews the previously acquired lease.

Code Samples

BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
     .setIfModifiedSince(OffsetDateTime.now().minusDays(3));

 BlobRenewLeaseOptions options = new BlobRenewLeaseOptions()
     .setRequestConditions(requestConditions);

 client.renewLeaseWithResponse(options).subscribe(response ->
     System.out.printf("Lease ID is %s%n", response.getValue()));

Parameters:

Returns:

A reactive response containing the renewed lease ID.

Applies to