• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AccessCondition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.microsoft.azure.storage.AccessCondition的典型用法代码示例。如果您正苦于以下问题:Java AccessCondition类的具体用法?Java AccessCondition怎么用?Java AccessCondition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AccessCondition类属于com.microsoft.azure.storage包,在下文中一共展示了AccessCondition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: publishJobModel

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Writes the job model to the blob.
 * Write is successful only if the lease ID passed is valid and the processor holds the lease.
 * Called by the leader.
 * @param prevJM Previous job model version that the processor was operating on.
 * @param currJM Current job model version that the processor is operating on.
 * @param prevJMV Previous job model version that the processor was operating on.
 * @param currJMV Current job model version that the processor is operating on.
 * @param leaseId LeaseID of the lease that the processor holds on the blob. Null if there is no lease.
 * @return true if write to the blob is successful, false if leaseID is null or an Azure storage service error or IO exception occurred.
 */
public boolean publishJobModel(JobModel prevJM, JobModel currJM, String prevJMV, String currJMV, String leaseId) {
  try {
    if (leaseId == null) {
      return false;
    }
    JobModelBundle bundle = new JobModelBundle(prevJM, currJM, prevJMV, currJMV);
    byte[] data = SamzaObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsBytes(bundle);
    byte[] pageData = Arrays.copyOf(data, (int) JOB_MODEL_BLOCK_SIZE);
    InputStream is = new ByteArrayInputStream(pageData);
    blob.uploadPages(is, 0, JOB_MODEL_BLOCK_SIZE, AccessCondition.generateLeaseCondition(leaseId), null, null);
    LOG.info("Uploaded {} jobModel to blob", bundle.getCurrJobModel());
    return true;
  } catch (StorageException | IOException e) {
    LOG.error("JobModel publish failed for version = " + currJMV, e);
    return false;
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:29,代码来源:BlobUtils.java


示例2: publishBarrierState

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Writes the barrier state to the blob.
 * Write is successful only if the lease ID passed is valid and the processor holds the lease.
 * Called only by the leader.
 * @param state Barrier state to be published to the blob.
 * @param leaseId LeaseID of the valid lease that the processor holds on the blob. Null if there is no lease.
 * @return true if write to the blob is successful, false if leaseID is null or an Azure storage service error or IO exception occurred.
 */
public boolean publishBarrierState(String state, String leaseId) {
  try {
    if (leaseId == null) {
      return false;
    }
    byte[] data = SamzaObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsBytes(state);
    byte[] pageData = Arrays.copyOf(data, (int) BARRIER_STATE_BLOCK_SIZE);
    InputStream is = new ByteArrayInputStream(pageData);

    //uploadPages is only successful when the AccessCondition provided has an active and valid lease ID. It fails otherwise.
    blob.uploadPages(is, JOB_MODEL_BLOCK_SIZE, BARRIER_STATE_BLOCK_SIZE, AccessCondition.generateLeaseCondition(leaseId), null, null);
    LOG.info("Uploaded barrier state {} to blob", state);
    return true;
  } catch (StorageException | IOException e) {
    LOG.error("Barrier state " + state + " publish failed", e);
    return false;
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:27,代码来源:BlobUtils.java


示例3: publishLiveProcessorList

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Writes the list of live processors in the system to the blob.
 * Write is successful only if the lease ID passed is valid and the processor holds the lease.
 * Called only by the leader.
 * @param processors List of live processors to be published on the blob.
 * @param leaseId LeaseID of the valid lease that the processor holds on the blob. Null if there is no lease.
 * @return true if write to the blob is successful, false if leaseID is null or an Azure storage service error or IO exception occurred.
 */
public boolean publishLiveProcessorList(List<String> processors, String leaseId) {
  try {
    if (leaseId == null) {
      return false;
    }
    byte[] data = SamzaObjectMapper.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsBytes(processors);
    byte[] pageData = Arrays.copyOf(data, (int) BARRIER_STATE_BLOCK_SIZE);
    InputStream is = new ByteArrayInputStream(pageData);
    blob.uploadPages(is, JOB_MODEL_BLOCK_SIZE + BARRIER_STATE_BLOCK_SIZE, PROCESSOR_LIST_BLOCK_SIZE, AccessCondition.generateLeaseCondition(leaseId), null, null);
    LOG.info("Uploaded list of live processors to blob.");
    return true;
  } catch (StorageException | IOException e) {
    LOG.error("Processor list: " + processors + "publish failed", e);
    return false;
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:25,代码来源:BlobUtils.java


示例4: downloadRangeInternal

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Downloads a range of bytes from the blob to the given byte buffer.
 *
 * @param blobOffset
 *            A <code>long</code> which represents the offset within the blob to begin downloading.
 * @param length
 *            A <code>Long</code> which represents the number of bytes to read.
 * @param buffer
 *            A <code>byte</code> array which represents the buffer to write to.
 * @param bufferOffset
 *            An <code>int</code> which represents the offset in the byte buffer to begin writing.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * @returns The total number of bytes read into the buffer.
 * 
 * @throws StorageException
 *             an exception representing any error which occurred during the operation.
 */
@DoesServiceRequest
protected final int downloadRangeInternal(final long blobOffset, final Long length, final byte[] buffer,
        final int bufferOffset, final AccessCondition accessCondition, BlobRequestOptions options,
        OperationContext opContext) throws StorageException {

    if (bufferOffset < 0 || blobOffset < 0 || (length != null && length <= 0)) {
        throw new IndexOutOfBoundsException();
    }

    if (opContext == null) {
        opContext = new OperationContext();
    }

    options = BlobRequestOptions.populateAndApplyDefaults(options, this.properties.getBlobType(), this.blobServiceClient);

    if (options.getUseTransactionalContentMD5() && (length != null && length > 4 * Constants.MB)) {
        throw new IllegalArgumentException(SR.INVALID_RANGE_CONTENT_MD5_HEADER);
    }

    WrappedByteArrayOutputStream outputStream = new WrappedByteArrayOutputStream(buffer, bufferOffset);
    ExecutionEngine.executeWithRetry(this.blobServiceClient, this,
            this.downloadToStreamImpl(blobOffset, length, outputStream, accessCondition, options, opContext),
            options.getRetryPolicyFactory(), opContext);
    return outputStream.getPosition();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:48,代码来源:CloudBlob.java


示例5: BlobOutputStream

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Initializes a new instance of the BlobOutputStream class for a CloudAppendBlob
 * 
 * @param parentBlob
 *            A {@link CloudAppendBlob} object which represents the blob that this stream is associated with.
 * @param accessCondition
 *            An {@link AccessCondition} object which represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object which specifies any additional options for the request
 * @param opContext
 *            An {@link OperationContext} object which is used to track the execution of the operation
 * 
 * @throws StorageException
 *             An exception representing any error which occurred during the operation.
 */
@DoesServiceRequest
protected BlobOutputStream(final CloudAppendBlob parentBlob, final AccessCondition accessCondition, 
        final BlobRequestOptions options, final OperationContext opContext)
        throws StorageException {
    this((CloudBlob)parentBlob, accessCondition, options, opContext);
    this.streamType = BlobType.APPEND_BLOB;
    
    this.accessCondition = accessCondition != null ? accessCondition : new AccessCondition();
    if (this.accessCondition.getIfAppendPositionEqual() != null) {
        this.currentBlobOffset = this.accessCondition.getIfAppendPositionEqual();
    } 
    else {
        // If this is an existing blob, we've done a downloadProperties to get the length
        // If this is a new blob, getLength will correctly return 0
        this.currentBlobOffset = parentBlob.getProperties().getLength();
    }
    
    this.internalWriteThreshold = this.parentBlobRef.getStreamWriteSizeInBytes();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:35,代码来源:BlobOutputStream.java


示例6: setAcl

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Sets the ACL for the container. Sign with length of aclBytes.
 * 
 * @param uri
 *            A <code>java.net.URI</code> object that specifies the absolute URI.
 * @param blobOptions
 *            A {@link BlobRequestOptions} object that specifies execution options such as retry policy and timeout
 *            settings for the operation. Specify <code>null</code> to use the request options specified on the
 *            {@link CloudBlobClient}.
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the container.
 * @param publicAccess
 *            The type of public access to allow for the container.
 * @return a HttpURLConnection configured for the operation.
 * @throws StorageException
 * */
public static HttpURLConnection setAcl(final URI uri, final BlobRequestOptions blobOptions,
        final OperationContext opContext, final AccessCondition accessCondition,
        final BlobContainerPublicAccessType publicAccess) throws IOException, URISyntaxException, StorageException {
    final UriQueryBuilder builder = getContainerUriQueryBuilder();
    builder.add(Constants.QueryConstants.COMPONENT, Constants.QueryConstants.ACL);

    final HttpURLConnection request = createURLConnection(uri, builder, blobOptions, opContext);

    request.setRequestMethod(Constants.HTTP_PUT);
    request.setDoOutput(true);

    if (publicAccess != BlobContainerPublicAccessType.OFF) {
        request.setRequestProperty(BlobConstants.BLOB_PUBLIC_ACCESS_HEADER, publicAccess.toString().toLowerCase());
    }

    if (accessCondition != null && !Utility.isNullOrEmpty(accessCondition.getLeaseID())) {
        BaseRequest.addLeaseId(request, accessCondition.getLeaseID());
    }

    return request;
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:42,代码来源:BlobRequest.java


示例7: deleteIfExists

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Deletes the directory if it exists using the specified request options and operation context.
 * 
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the directory.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the directory existed and was deleted; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 * @throws URISyntaxException 
 */
@DoesServiceRequest
public boolean deleteIfExists(AccessCondition accessCondition, FileRequestOptions options,
        OperationContext opContext) throws StorageException, URISyntaxException {
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);

    boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.RESOURCE_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
    else {
        return false;
    }
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:46,代码来源:CloudFileDirectory.java


示例8: deleteIfExists

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Deletes the container if it exists using the specified request options and operation context.
 * 
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the container.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @return <code>true</code> if the container existed and was deleted; otherwise, <code>false</code>.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public boolean deleteIfExists(AccessCondition accessCondition, BlobRequestOptions options,
        OperationContext opContext) throws StorageException {
    options = BlobRequestOptions.applyDefaults(options, BlobType.UNSPECIFIED, this.blobServiceClient);

    boolean exists = this.exists(true /* primaryOnly */, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.CONTAINER_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }
    }
    else {
        return false;
    }
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:45,代码来源:CloudBlobContainer.java


示例9: downloadRange

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Downloads the contents of a blob to a stream using the specified request options and operation context.
 *
 * @param offset
 *            A <code>long</code> which represents the offset to use as the starting point for the source.
 * @param length
 *            A <code>Long</code> which represents the number of bytes to read or <code>null</code>.
 * @param outStream
 *            An <code>{@link OutputStream}</code> object that represents the target stream.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public final void downloadRange(final long offset, final Long length, final OutputStream outStream,
        final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext)
        throws StorageException {
    if (offset < 0 || (length != null && length <= 0)) {
        throw new IndexOutOfBoundsException();
    }

    if (opContext == null) {
        opContext = new OperationContext();
    }

    opContext.initialize();
    options = BlobRequestOptions.applyDefaults(options, this.properties.getBlobType(), this.blobServiceClient);

    if (options.getUseTransactionalContentMD5() && (length != null && length > 4 * Constants.MB)) {
        throw new IllegalArgumentException(SR.INVALID_RANGE_CONTENT_MD5_HEADER);
    }

    ExecutionEngine.executeWithRetry(this.blobServiceClient, this,
            this.downloadToStreamImpl(offset, length, outStream, accessCondition, options, opContext),
            options.getRetryPolicyFactory(), opContext);
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:46,代码来源:CloudBlob.java


示例10: downloadRangeInternal

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Downloads a range of bytes from the blob to the given byte buffer.
 *
 * @param blobOffset
 *            A <code>long</code> which represents the offset within the blob to begin downloading.
 * @param length
 *            A <code>Long</code> which represents the number of bytes to read.
 * @param buffer
 *            A <code>byte</code> array which represents the buffer to write to.
 * @param bufferOffset
 *            An <code>int</code> which represents the offset in the byte buffer to begin writing.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request.
 * @param opContext
 *            An {@link OperationContext} object used to track the execution of the operation.
 * @throws StorageException
 *             an exception representing any error which occurred during the operation.
 */
@DoesServiceRequest
protected final int downloadRangeInternal(final long blobOffset, final Long length, final byte[] buffer,
        final int bufferOffset, final AccessCondition accessCondition, BlobRequestOptions options,
        OperationContext opContext) throws StorageException {

    if (bufferOffset < 0 || blobOffset < 0 || (length != null && length <= 0)) {
        throw new IndexOutOfBoundsException();
    }

    if (opContext == null) {
        opContext = new OperationContext();
    }

    options = BlobRequestOptions.applyDefaults(options, this.properties.getBlobType(), this.blobServiceClient);

    if (options.getUseTransactionalContentMD5() && (length != null && length > 4 * Constants.MB)) {
        throw new IllegalArgumentException(SR.INVALID_RANGE_CONTENT_MD5_HEADER);
    }

    return ExecutionEngine.executeWithRetry(this.blobServiceClient, this, this.downloadToByteArrayImpl(blobOffset,
            length, buffer, bufferOffset, accessCondition, options, opContext), options.getRetryPolicyFactory(),
            opContext);
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:44,代码来源:CloudBlob.java


示例11: downloadRange

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Downloads the contents of a blob to a stream using the specified request options and operation context.
 *
 * @param offset
 *            A <code>long</code> which represents the offset to use as the starting point for the source.
 * @param length
 *            A <code>Long</code> which represents the number of bytes to read or <code>null</code>.
 * @param outStream
 *            An <code>{@link OutputStream}</code> object that represents the target stream.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public final void downloadRange(final long offset, final Long length, final OutputStream outStream,
        final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext)
        throws StorageException {
    if (offset < 0 || (length != null && length <= 0)) {
        throw new IndexOutOfBoundsException();
    }

    if (opContext == null) {
        opContext = new OperationContext();
    }

    opContext.initialize();
    options = BlobRequestOptions.populateAndApplyDefaults(options, this.properties.getBlobType(), this.blobServiceClient);

    if (options.getUseTransactionalContentMD5() && (length != null && length > 4 * Constants.MB)) {
        throw new IllegalArgumentException(SR.INVALID_RANGE_CONTENT_MD5_HEADER);
    }

    ExecutionEngine.executeWithRetry(this.blobServiceClient, this,
            this.downloadToStreamImpl(offset, length, outStream, accessCondition, options, opContext),
            options.getRetryPolicyFactory(), opContext);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:46,代码来源:CloudBlob.java


示例12: testBlobLeaseAcquireAndRelease

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
@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);
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:24,代码来源:LeaseTests.java


示例13: getLeaseCondition

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Return and access condition for this lease, or else null if
 * there's no lease.
 */
private AccessCondition getLeaseCondition(SelfRenewingLease lease) {
  AccessCondition leaseCondition = null;
  if (lease != null) {
    leaseCondition = AccessCondition.generateLeaseCondition(lease.getLeaseID());
  }
  return leaseCondition;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:12,代码来源:StorageInterfaceImpl.java


示例14: 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());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:33,代码来源:SelfRenewingLease.java


示例15: 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);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:NativeAzureFileSystemBaseTest.java


示例16: renewLease

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Renews the lease on the blob.
 * @param leaseId ID of the lease to be renewed.
 * @return True if lease was renewed successfully, false otherwise.
 */
public boolean renewLease(String leaseId) {
  try {
    leaseBlob.renewLease(AccessCondition.generateLeaseCondition(leaseId));
    return true;
  } catch (StorageException storageException) {
    LOG.error("Wasn't able to renew lease with lease id: " + leaseId, storageException);
    return false;
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:15,代码来源:LeaseBlobManager.java


示例17: releaseLease

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Releases the lease on the blob.
 * @param leaseId ID of the lease to be released.
 * @return True if released successfully, false otherwise.
 */
public boolean releaseLease(String leaseId) {
  try {
    leaseBlob.releaseLease(AccessCondition.generateLeaseCondition(leaseId));
    return true;
  } catch (StorageException storageException) {
    LOG.error("Wasn't able to release lease with lease id: " + leaseId, storageException);
    return false;
  }
}
 
开发者ID:apache,项目名称:samza,代码行数:15,代码来源:LeaseBlobManager.java


示例18: downloadToByteArray

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Downloads a range of bytes from the file to the given byte buffer, using the specified request options and
 * operation context.
 * 
 * @param buffer
 *            A <code>byte</code> array which represents the buffer to which the file bytes are downloaded.
 * @param bufferOffset
 *            A <code>long</code> which represents the byte offset to use as the starting point for the target.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the file.
 * @param options
 *            A {@link FileRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudFileClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * 
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public final int downloadToByteArray(final byte[] buffer, final int bufferOffset,
        final AccessCondition accessCondition, FileRequestOptions options, OperationContext opContext)
        throws StorageException {

    Utility.assertNotNull("buffer", buffer);
    if (bufferOffset < 0) {
        throw new IndexOutOfBoundsException();
    }

    if (bufferOffset >= buffer.length) {
        throw new IndexOutOfBoundsException();
    }

    if (opContext == null) {
        opContext = new OperationContext();
    }

    opContext.initialize();
    options = FileRequestOptions.populateAndApplyDefaults(options, this.fileServiceClient);
    
    WrappedByteArrayOutputStream outputStream = new WrappedByteArrayOutputStream(buffer, bufferOffset);
    ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
            this.downloadToStreamImpl(null, null, outputStream, accessCondition, options, opContext),
            options.getRetryPolicyFactory(), opContext);
    return outputStream.getPosition();
}
 
开发者ID:Azure,项目名称:azure-storage-android,代码行数:50,代码来源:CloudFile.java


示例19: exists

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
@DoesServiceRequest
private final boolean exists(final boolean primaryOnly, final AccessCondition accessCondition,
        FileRequestOptions options, OperationContext opContext) throws StorageException {
    if (opContext == null) {
        opContext = new OperationContext();
    }

    opContext.initialize();
    options = FileRequestOptions.applyDefaults(options, this.fileServiceClient);

    return ExecutionEngine.executeWithRetry(this.fileServiceClient, this,
            this.existsImpl(primaryOnly, accessCondition, options), options.getRetryPolicyFactory(), opContext);
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:14,代码来源:CloudFile.java


示例20: deleteIfExists

import com.microsoft.azure.storage.AccessCondition; //导入依赖的package包/类
/**
 * Deletes the blob if it exists, using the specified snapshot and request options, and operation context.
 * <p>
 * A blob that has snapshots cannot be deleted unless the snapshots are also deleted. If a blob has snapshots, use
 * the {@link DeleteSnapshotsOption#DELETE_SNAPSHOTS_ONLY} or {@link DeleteSnapshotsOption#INCLUDE_SNAPSHOTS} value
 * in the <code>deleteSnapshotsOption</code> parameter to specify how the snapshots should be handled when the blob
 * is deleted.
 *
 * @param deleteSnapshotsOption
 *            A {@link DeleteSnapshotsOption} object that indicates whether to delete only snapshots, or the blob
 *            and its snapshots.
 * @param accessCondition
 *            An {@link AccessCondition} object that represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object that represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 *
 * @return <code>true</code> if the blob existed and was deleted; otherwise, <code>false</code>
 *
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public final boolean deleteIfExists(final DeleteSnapshotsOption deleteSnapshotsOption,
        final AccessCondition accessCondition, BlobRequestOptions options, OperationContext opContext)
        throws StorageException {
    options = BlobRequestOptions.applyDefaults(options, this.properties.getBlobType(), this.blobServiceClient);

    boolean exists = this.exists(true, accessCondition, options, opContext);
    if (exists) {
        try {
            this.delete(deleteSnapshotsOption, accessCondition, options, opContext);
            return true;
        }
        catch (StorageException e) {
            if (e.getHttpStatusCode() == HttpURLConnection.HTTP_NOT_FOUND
                    && StorageErrorCodeStrings.BLOB_NOT_FOUND.equals(e.getErrorCode())) {
                return false;
            }
            else {
                throw e;
            }
        }

    }
    else {
        return false;
    }
}
 
开发者ID:horizon-institute,项目名称:runspotrun-android-client,代码行数:55,代码来源:CloudBlob.java



注:本文中的com.microsoft.azure.storage.AccessCondition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Http2ConnectionDecoder类代码示例发布时间:2022-05-23
下一篇:
Java BuildFeature类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap