/** * Releases the lease on the blob. * * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is * required to be set on the AccessCondition. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final void releaseLease(final AccessCondition accessCondition) throws StorageException { this.releaseLease(accessCondition, null /* options */, null /* opContext */); }
/** * Releases the lease on the blob. * * @param accessCondition * An {@link AccessCondition} object that represents the access conditions for the blob. The LeaseID is * required to be set on the AccessCondition. * * @throws StorageException * If a storage service error occurred. */ @DoesServiceRequest public final void releaseLease(final AccessCondition accessCondition) throws StorageException { this.releaseLease(accessCondition, null /* options */, null /* opContext */); }
/** * Free the lease and stop the keep-alive thread. * @throws StorageException Thrown when fail to free the lease. */ public void free() throws StorageException { AccessCondition accessCondition = AccessCondition.generateEmptyCondition(); accessCondition.setLeaseID(leaseID); try { blobWrapper.getBlob().releaseLease(accessCondition); } catch (StorageException e) { if ("BlobNotFound".equals(e.getErrorCode())) { // Don't do anything -- it's okay to free a lease // on a deleted file. The delete freed the lease // implicitly. } else { // This error is not anticipated, so re-throw it. LOG.warn("Unanticipated exception when trying to free lease " + leaseID + " on " + blobWrapper.getStorageUri()); throw(e); } } finally { // Even if releasing the lease fails (e.g. because the file was deleted), // make sure to record that we freed the lease, to terminate the // keep-alive thread. leaseFreed = true; LOG.debug("Freed lease " + leaseID + " on " + blobWrapper.getUri() + " managed by thread " + renewer.getName()); } }
AccessCondition accessCondition = AccessCondition.generateEmptyCondition(); accessCondition.setLeaseID(differentLeaseID); blob.releaseLease(accessCondition);
AccessCondition accessCondition = AccessCondition.generateEmptyCondition(); accessCondition.setLeaseID(differentLeaseID); blob.releaseLease(accessCondition);
@Test public void testBlobLeaseAcquireAndRelease() throws URISyntaxException, StorageException, IOException { final int length = 128; final CloudBlob blobRef = BlobTestHelper.uploadNewBlob(this.container, BlobType.BLOCK_BLOB, "test", 128, null); // Get Lease OperationContext operationContext = new OperationContext(); final String leaseID = blobRef.acquireLease(15, null /*proposed lease id */, null /*access condition*/, null/* BlobRequestOptions */, operationContext); final AccessCondition leaseCondition = AccessCondition.generateLeaseCondition(leaseID); assertTrue(operationContext.getLastResult().getStatusCode() == HttpURLConnection.HTTP_CREATED); tryUploadWithBadLease(length, blobRef, null, StorageErrorCodeStrings.LEASE_ID_MISSING); // Try to upload with lease blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1, leaseCondition, null, null); // Release lease blobRef.releaseLease(leaseCondition); // now upload with no lease specified. blobRef.upload(BlobTestHelper.getRandomDataStream(length), -1); }