ShareLeaseClient Class

  • java.lang.Object
    • com.azure.storage.file.share.specialized.ShareLeaseClient

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

Modifier and Type Method and Description
String acquireLease()

Acquires an infinite lease for write and delete operations.

Response<String> acquireLeaseWithResponse(Duration timeout, Context context)

Acquires an infinite lease for write and delete operations.

Response<String> acquireLeaseWithResponse(ShareAcquireLeaseOptions options, Duration timeout, Context context)

Acquires a lease for write and delete operations.

void breakLease()

Breaks the previously acquired lease, if it exists.

Response<Void> breakLeaseWithResponse(Duration timeout, Context context)

Breaks the previously acquired lease, if it exists.

Response<Void> breakLeaseWithResponse(ShareBreakLeaseOptions options, 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, Duration timeout, Context context)

Changes the lease ID.

String getAccountName()

Get associated account name.

String getFileUrl()

Deprecated

Please use getResourceUrl()
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(Duration timeout, Context context)

Releases the previously acquired lease.

String renewLease()

Renews the previously acquired lease on a share.

Response<String> renewLeaseWithResponse(Duration timeout, Context context)

Renews the previously acquired lease on a share.

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:

The lease ID.

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:

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.

Returns:

The lease ID.

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:

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.

Returns:

The lease ID.

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:

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.

Returns:

A response containing status code and HTTP headers.

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:

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.

Returns:

A response containing status code and HTTP headers.

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:

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

Returns:

The new lease ID.

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:

proposedId - A new lease ID in a valid GUID format.
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.

Returns:

The new lease ID.

getAccountName

public String getAccountName()

Get associated account name.

Returns:

account name associated with this storage resource.

getFileUrl

@Deprecated
public String getFileUrl()

Deprecated

Please use getResourceUrl()

Returns:

URL of the lease client.

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 share or share file URL depending on which the lease client is associated.

Returns:

URL of the lease client.

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:

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.

Returns:

A response containing status code and HTTP headers.

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:

A response containing the renewed lease ID.

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:

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.

Returns:

A response containing the renewed lease ID.

Applies to