ShareLeaseClient Class
- java.
lang. Object - com.
azure. storage. file. share. specialized. ShareLeaseClient
- com.
public final class ShareLeaseClient
This class provides a client that contains all the leasing operations for ShareFileClient. This client acts as a supplement to that client and only handles leasing operations.
Instantiating a ShareLeaseClient
ShareLeaseClient fileLeaseClient = new ShareLeaseClientBuilder()
.fileClient(shareFileClient)
.buildClient();
View ShareLeaseClientBuilder for additional ways to construct the client.
For more information about leasing see the Azure Docs.
Method Summary
Methods inherited from java.lang.Object
Method Details
acquireLease
public String acquireLease()
Acquires an infinite lease for write and delete operations.
Code Samples
System.out.printf("Lease ID is %s%n", client.acquireLease());
Returns:
acquireLeaseWithResponse
public Response<String> acquireLeaseWithResponse(Duration timeout, Context context)
Acquires an infinite lease for write and delete operations.
Code Samples
System.out.printf("Lease ID is %s%n", client
.acquireLeaseWithResponse(timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
acquireLeaseWithResponse
public Response<String> acquireLeaseWithResponse(ShareAcquireLeaseOptions options, Duration timeout, Context context)
Acquires a lease for write and delete operations. Note: Share files only support infinite lease.
Code Samples
System.out.printf("Lease ID is %s%n", client
.acquireLeaseWithResponse(new ShareAcquireLeaseOptions().setDuration(10), timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
breakLease
public void breakLease()
Breaks the previously acquired lease, if it exists. Leases will break immediately.
Code Samples
client.breakLease();
System.out.println("The lease has been successfully broken");
breakLeaseWithResponse
public Response<Void> breakLeaseWithResponse(Duration timeout, Context context)
Breaks the previously acquired lease, if it exists. Leases will break immediately.
Code Samples
client.breakLeaseWithResponse(timeout, new Context(key, value));
System.out.println("The lease has been successfully broken");
Parameters:
Returns:
breakLeaseWithResponse
public Response<Void> breakLeaseWithResponse(ShareBreakLeaseOptions options, Duration timeout, Context context)
Breaks the previously acquired lease, if it exists. Leases will break immediately.
Code Samples
client.breakLeaseWithResponse(new ShareBreakLeaseOptions().setBreakPeriod(Duration.ofSeconds(25)),
timeout, new Context(key, value));
System.out.println("The lease has been successfully broken");
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<String> changeLeaseWithResponse(String proposedId, Duration timeout, Context context)
Changes the lease ID.
Code Samples
System.out.printf("Changed lease ID is %s%n",
client.changeLeaseWithResponse("proposedId", timeout, new Context(key, value))
.getValue());
Parameters:
Returns:
getAccountName
public String getAccountName()
Get associated account name.
Returns:
getFileUrl
@Deprecated
public String getFileUrl()
Deprecated
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 share or share file 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<Void> releaseLeaseWithResponse(Duration timeout, Context context)
Releases the previously acquired lease.
Code Samples
System.out.printf("Release lease completed with status %d%n",
client.releaseLeaseWithResponse(timeout, new Context(key, value))
.getStatusCode());
Parameters:
Returns:
renewLease
public String renewLease()
Renews the previously acquired lease on a share.
Code Samples
System.out.printf("Renewed lease ID is %s%n", client.renewLease());
Returns:
renewLeaseWithResponse
public Response<String> renewLeaseWithResponse(Duration timeout, Context context)
Renews the previously acquired lease on a share.
Code Samples
System.out.printf("Renewed lease ID is %s%n",
client.releaseLeaseWithResponse(timeout, new Context(key, value))
.getValue());
Parameters:
Returns: