本文整理汇总了Java中com.microsoft.azure.storage.AccessCondition.generateEmptyCondition方法的典型用法代码示例。如果您正苦于以下问题:Java AccessCondition.generateEmptyCondition方法的具体用法?Java AccessCondition.generateEmptyCondition怎么用?Java AccessCondition.generateEmptyCondition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.storage.AccessCondition
的用法示例。
在下文中一共展示了AccessCondition.generateEmptyCondition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: free
import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
/**
* Free the lease and stop the keep-alive thread.
* @throws StorageException
*/
public void free() throws StorageException {
AccessCondition accessCondition = AccessCondition.generateEmptyCondition();
accessCondition.setLeaseID(leaseID);
try {
blobWrapper.getBlob().releaseLease(accessCondition);
} catch (StorageException e) {
if (e.getErrorCode().equals("BlobNotFound")) {
// 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());
}
}
示例2: testSelfRenewingLease
import com.microsoft.azure.storage.AccessCondition; //导入方法依赖的package包/类
@Test
// Acquire and free a Lease object. Wait for more than the lease
// timeout, to make sure the lease renews itself.
public void testSelfRenewingLease() throws IllegalArgumentException, IOException,
InterruptedException, StorageException {
SelfRenewingLease lease;
final String FILE_KEY = "file";
fs.create(new Path(FILE_KEY));
NativeAzureFileSystem nfs = (NativeAzureFileSystem) fs;
String fullKey = nfs.pathToKey(nfs.makeAbsolute(new Path(FILE_KEY)));
AzureNativeFileSystemStore store = nfs.getStore();
lease = store.acquireLease(fullKey);
assertTrue(lease.getLeaseID() != null);
// The sleep time for the keep-alive thread is 40 seconds, so sleep just
// a little beyond that, to make sure the keep-alive thread wakes up
// and renews the lease.
Thread.sleep(42000);
lease.free();
// Check that the lease is really freed.
CloudBlob blob = lease.getCloudBlob();
// Try to acquire it again, using direct Azure blob access.
// If that succeeds, then the lease was already freed.
String differentLeaseID = null;
try {
differentLeaseID = blob.acquireLease(15, null);
} catch (Exception e) {
e.printStackTrace();
fail("Caught exception trying to directly re-acquire lease from Azure");
} finally {
assertTrue(differentLeaseID != null);
AccessCondition accessCondition = AccessCondition.generateEmptyCondition();
accessCondition.setLeaseID(differentLeaseID);
blob.releaseLease(accessCondition);
}
}