public final class BlobLeaseClient extends Object
containers
and
blobs
. This client acts as a supplement to those clients and only handles leasing operations.
Instantiating a BlobLeaseClient
BlobLeaseClient
blobLeaseClient = newBlobLeaseClientBuilder
() .blobClient(blobClient) .buildClient();
BlobLeaseClient
blobLeaseClient = newBlobLeaseClientBuilder
() .containerClient(blobContainerClient) .buildClient();
View this
for additional ways to construct the client.
For more information about leasing see the container leasing or blob leasing documentation.
BlobLeaseClientBuilder
Modifier and Type | Method and Description |
---|---|
String |
acquireLease(int duration)
Acquires a lease for write and delete operations.
|
Response<String> |
acquireLeaseWithResponse(int duration,
RequestConditions modifiedAccessConditions,
Duration timeout,
Context context)
Acquires a lease for write and delete operations.
|
Integer |
breakLease()
Breaks the previously acquired lease, if it exists.
|
Response<Integer> |
breakLeaseWithResponse(Integer breakPeriodInSeconds,
RequestConditions modifiedAccessConditions,
Duration timeout,
Context context)
Breaks the previously acquired lease, if it exists.
|
String |
changeLease(String proposedId)
Changes the lease ID.
|
Response<String> |
changeLeaseWithResponse(String proposedId,
RequestConditions modifiedAccessConditions,
Duration timeout,
Context context)
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. |
void |
releaseLease()
Releases the previously acquired lease.
|
Response<Void> |
releaseLeaseWithResponse(RequestConditions modifiedAccessConditions,
Duration timeout,
Context context)
Releases the previously acquired lease.
|
String |
renewLease()
Renews the previously acquired lease.
|
Response<String> |
renewLeaseWithResponse(RequestConditions modifiedAccessConditions,
Duration timeout,
Context context)
Renews the previously-acquired lease.
|
public String getResourceUrl()
URL
of the lease client.
The lease will either be a container or blob URL depending on which the lease client is associated.
public String getLeaseId()
public String acquireLease(int duration)
Code Samples
System
.out.printf("Lease ID is %s%n", client.acquireLease(60));
duration
- The duration of the lease between 15 to 60 seconds or -1 for an infinite duration.public Response<String> acquireLeaseWithResponse(int duration, RequestConditions modifiedAccessConditions, Duration timeout, Context context)
Code Samples
RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfModifiedSince(OffsetDateTime
.now().minusDays(3));System
.out.printf("Lease ID is %s%n", client .acquireLeaseWithResponse(60, modifiedAccessConditions, timeout, newContext
(key, value)) .getValue());
duration
- The duration of the lease between 15 to 60 seconds or -1 for an infinite duration.modifiedAccessConditions
- 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.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public String renewLease()
Code Samples
System
.out.printf("Renewed lease ID is %s%n", client.renewLease());
public Response<String> renewLeaseWithResponse(RequestConditions modifiedAccessConditions, Duration timeout, Context context)
Code Samples
RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));System
.out.printf("Renewed lease ID is %s%n", client.renewLeaseWithResponse(modifiedAccessConditions, timeout, newContext
(key, value)) .getValue());
modifiedAccessConditions
- 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.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public void releaseLease()
Code Samples
client.releaseLease();
System
.out.println("Release lease completed");
public Response<Void> releaseLeaseWithResponse(RequestConditions modifiedAccessConditions, Duration timeout, Context context)
Code Samples
RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));System
.out.printf("Release lease completed with status %d%n", client.releaseLeaseWithResponse(modifiedAccessConditions, timeout, newContext
(key, value)) .getStatusCode());
modifiedAccessConditions
- 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.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public Integer breakLease()
Code Samples
System
.out.printf("The broken lease has %d seconds remaining on the lease", client.breakLease());
public Response<Integer> breakLeaseWithResponse(Integer breakPeriodInSeconds, RequestConditions modifiedAccessConditions, Duration timeout, Context context)
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
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));System
.out.printf("The broken lease has %d seconds remaining on the lease", client .breakLeaseWithResponse(retainLeaseInSeconds, modifiedAccessConditions, timeout, newContext
(key, value)) .getValue());
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.modifiedAccessConditions
- 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.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public String changeLease(String proposedId)
Code Samples
System
.out.printf("Changed lease ID is %s%n", client.changeLease("proposedId"));
proposedId
- A new lease ID in a valid GUID format.public Response<String> changeLeaseWithResponse(String proposedId, RequestConditions modifiedAccessConditions, Duration timeout, Context context)
Code Samples
RequestConditions
modifiedAccessConditions = newRequestConditions
() .setIfUnmodifiedSince(OffsetDateTime
.now().minusDays(3));System
.out.printf("Changed lease ID is %s%n", client.changeLeaseWithResponse("proposedId", modifiedAccessConditions, timeout, newContext
(key, value)) .getValue());
proposedId
- A new lease ID in a valid GUID format.modifiedAccessConditions
- 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.timeout
- An optional timeout value beyond which a RuntimeException
will be raised.context
- Additional context that is passed through the Http pipeline during the service call.public String getAccountName()
Copyright © 2019 Microsoft Corporation. All rights reserved.