Class BlobLeaseClient


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

    For more information about leasing see the container leasing or blob leasing documentation.

    See Also:
    BlobLeaseClientBuilder
    • Method Detail

      • 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:
        URL of the lease client.
      • getLeaseId

        public String getLeaseId()
        Get the lease ID for this lease.
        Returns:
        the lease ID.
      • acquireLease

        public String acquireLease​(int duration)
        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:
        duration - The duration of the lease between 15 to 60 seconds or -1 for an infinite duration.
        Returns:
        The lease ID.
      • acquireLeaseWithResponse

        public com.azure.core.http.rest.Response<String> acquireLeaseWithResponse​(int duration,
                                                                                  com.azure.core.http.RequestConditions modifiedRequestConditions,
                                                                                  Duration timeout,
                                                                                  com.azure.core.util.Context context)
        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:
        duration - The duration of the lease between 15 to 60 seconds or -1 for an infinite duration.
        modifiedRequestConditions - 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.
        Returns:
        The lease ID.
      • acquireLeaseWithResponse

        public com.azure.core.http.rest.Response<String> acquireLeaseWithResponse​(BlobAcquireLeaseOptions options,
                                                                                  Duration timeout,
                                                                                  com.azure.core.util.Context context)
        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:
        options - BlobAcquireLeaseOptions
        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.
      • renewLease

        public String renewLease()
        Renews the previously acquired lease.

        Code Samples

         System.out.printf("Renewed lease ID is %s%n", client.renewLease());
         
        Returns:
        The renewed lease ID.
      • renewLeaseWithResponse

        public com.azure.core.http.rest.Response<String> renewLeaseWithResponse​(com.azure.core.http.RequestConditions modifiedRequestConditions,
                                                                                Duration timeout,
                                                                                com.azure.core.util.Context context)
        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:
        modifiedRequestConditions - 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.
        Returns:
        The renewed lease ID.
      • renewLeaseWithResponse

        public com.azure.core.http.rest.Response<String> renewLeaseWithResponse​(BlobRenewLeaseOptions options,
                                                                                Duration timeout,
                                                                                com.azure.core.util.Context context)
        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:
        options - BlobRenewLeaseOptions
        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 renewed lease ID.
      • releaseLease

        public void releaseLease()
        Releases the previously acquired lease.

        Code Samples

         client.releaseLease();
         System.out.println("Release lease completed");
         
      • releaseLeaseWithResponse

        public com.azure.core.http.rest.Response<Void> releaseLeaseWithResponse​(com.azure.core.http.RequestConditions modifiedRequestConditions,
                                                                                Duration timeout,
                                                                                com.azure.core.util.Context context)
        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:
        modifiedRequestConditions - 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.
        Returns:
        A response containing status code and HTTP headers.
      • releaseLeaseWithResponse

        public com.azure.core.http.rest.Response<Void> releaseLeaseWithResponse​(BlobReleaseLeaseOptions options,
                                                                                Duration timeout,
                                                                                com.azure.core.util.Context context)
        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:
        options - BlobReleaseLeaseOptions
        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 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:
        The remaining time in the broken lease in seconds.
      • breakLeaseWithResponse

        public com.azure.core.http.rest.Response<Integer> breakLeaseWithResponse​(Integer breakPeriodInSeconds,
                                                                                 com.azure.core.http.RequestConditions modifiedRequestConditions,
                                                                                 Duration timeout,
                                                                                 com.azure.core.util.Context context)
        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:
        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.
        modifiedRequestConditions - 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.
        Returns:
        The remaining time in the broken lease in seconds.
      • breakLeaseWithResponse

        public com.azure.core.http.rest.Response<Integer> breakLeaseWithResponse​(BlobBreakLeaseOptions options,
                                                                                 Duration timeout,
                                                                                 com.azure.core.util.Context context)
        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:
        options - BlobBreakLeaseOptions
        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 remaining time in the broken lease in seconds.
      • 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 com.azure.core.http.rest.Response<String> changeLeaseWithResponse​(String proposedId,
                                                                                 com.azure.core.http.RequestConditions modifiedRequestConditions,
                                                                                 Duration timeout,
                                                                                 com.azure.core.util.Context context)
        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:
        proposedId - A new lease ID in a valid GUID format.
        modifiedRequestConditions - 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.
        Returns:
        The new lease ID.
      • changeLeaseWithResponse

        public com.azure.core.http.rest.Response<String> changeLeaseWithResponse​(BlobChangeLeaseOptions options,
                                                                                 Duration timeout,
                                                                                 com.azure.core.util.Context context)
        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:
        options - BlobChangeLeaseOptions
        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.