BlobLeaseClient Class
- java.
lang. Object - com.
azure. storage. blob. specialized. BlobLeaseClient
- com.
public final class BlobLeaseClient
This class provides a client that contains all the leasing operations for BlobContainerClient and BlobClient. This client acts as a supplement to those clients and only handles leasing operations.
Instantiating a BlobLeaseClient
BlobLeaseClient blobLeaseClient = new BlobLeaseClientBuilder()
.blobClient(blobClient)
.buildClient();
BlobLeaseClient blobLeaseClient = new BlobLeaseClientBuilder()
.containerClient(blobContainerClient)
.buildClient();
View BlobLeaseClientBuilder for additional ways to construct the client.
For more information about leasing see the container leasing or blob leasing documentation.
Method Summary
Methods inherited from java.lang.Object
Method Details
acquireLease
public String acquireLease(int durationInSeconds)
Acquires a lease for write and delete operations. The lease duration must be between 15 to 60 seconds or -1 for an infinite duration.
Code Samples
System.out.printf("Lease ID is %s%n", client.acquireLease(60));
Parameters:
Returns:
acquireLeaseWithResponse
public Response
Acquires a lease for write and delete operations. The lease duration must be between 15 to 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);
System.out.printf("Lease ID is %s%n", client
.acquireLeaseWithResponse(options, timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
acquireLeaseWithResponse
public Response
Acquires a lease for write and delete operations. The lease duration must be between 15 to 60 seconds or -1 for an infinite duration.
Code Samples
RequestConditions modifiedRequestConditions = new RequestConditions()
.setIfModifiedSince(OffsetDateTime.now().minusDays(3));
System.out.printf("Lease ID is %s%n", client
.acquireLeaseWithResponse(60, modifiedRequestConditions, timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
breakLease
public Integer breakLease()
Breaks the previously acquired lease, if it exists.
Code Samples
System.out.printf("The broken lease has %d seconds remaining on the lease", client.breakLease());
Returns:
breakLeaseWithResponse
public Response
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);
System.out.printf("The broken lease has %d seconds remaining on the lease", client
.breakLeaseWithResponse(options, timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
breakLeaseWithResponse
public Response
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));
System.out.printf("The broken lease has %d seconds remaining on the lease", client
.breakLeaseWithResponse(retainLeaseInSeconds, modifiedRequestConditions, timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
changeLease
public String changeLease(String proposedId)
Changes the lease ID.
Code Samples
System.out.printf("Changed lease ID is %s%n", client.changeLease("proposedId"));
Parameters:
Returns:
changeLeaseWithResponse
public Response
Changes the lease ID.
Code Samples
BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
BlobChangeLeaseOptions options = new BlobChangeLeaseOptions("proposedId")
.setRequestConditions(requestConditions);
System.out.printf("Changed lease ID is %s%n",
client.changeLeaseWithResponse(options, timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
changeLeaseWithResponse
public Response
Changes the lease ID.
Code Samples
RequestConditions modifiedRequestConditions = new RequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
System.out.printf("Changed lease ID is %s%n",
client.changeLeaseWithResponse("proposedId", modifiedRequestConditions, timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
getAccountName
public String getAccountName()
Get associated account name.
Returns:
getLeaseId
public String getLeaseId()
Get the lease ID for this lease.
Returns:
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:
releaseLease
public void releaseLease()
Releases the previously acquired lease.
Code Samples
client.releaseLease();
System.out.println("Release lease completed");
releaseLeaseWithResponse
public Response
Releases the previously acquired lease.
Code Samples
RequestConditions modifiedRequestConditions = new RequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
System.out.printf("Release lease completed with status %d%n",
client.releaseLeaseWithResponse(modifiedRequestConditions, timeout, new Context(key, value))
.getStatusCode());
Parameters:
Returns:
releaseLeaseWithResponse
public Response
Releases the previously acquired lease.
Code Samples
BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
.setIfModifiedSince(OffsetDateTime.now().minusDays(3));
BlobReleaseLeaseOptions options = new BlobReleaseLeaseOptions()
.setRequestConditions(requestConditions);
System.out.printf("Release lease completed with status %d%n",
client.releaseLeaseWithResponse(options, timeout, new Context(key, value))
.getStatusCode());
Parameters:
Returns:
renewLease
public String renewLease()
Renews the previously acquired lease.
Code Samples
System.out.printf("Renewed lease ID is %s%n", client.renewLease());
Returns:
renewLeaseWithResponse
public Response
Renews the previously-acquired lease.
Code Samples
RequestConditions modifiedRequestConditions = new RequestConditions()
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
System.out.printf("Renewed lease ID is %s%n",
client.renewLeaseWithResponse(modifiedRequestConditions, timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
renewLeaseWithResponse
public Response
Renews the previously-acquired lease.
Code Samples
BlobLeaseRequestConditions requestConditions = new BlobLeaseRequestConditions()
.setIfModifiedSince(OffsetDateTime.now().minusDays(3));
BlobRenewLeaseOptions options = new BlobRenewLeaseOptions()
.setRequestConditions(requestConditions);
System.out.printf("Renewed lease ID is %s%n",
client.renewLeaseWithResponse(options, timeout, new Context(key, value))
.getValue());
Parameters:
Returns: