Class ShareLeaseClient

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

public final class ShareLeaseClient extends Object
This class provides a client that contains all the leasing operations for files. 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 this for additional ways to construct the client.

For more information about leasing see the Azure Docs.

See Also:
  • Method Details

    • getFileUrl

      @Deprecated public String getFileUrl()
      Deprecated.
      Please use getResourceUrl()
      Returns:
      URL of the lease client.
    • 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.
    • getLeaseId

      public String getLeaseId()
      Get the lease ID for this lease.
      Returns:
      the lease ID.
    • 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:
      options - ShareAcquireLeaseOptions
      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.
    • 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.
    • 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:
      options - ShareBreakLeaseOptions
      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.
    • 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.
    • getAccountName

      public String getAccountName()
      Get associated account name.
      Returns:
      account name associated with this storage resource.