java.util.concurrent.ConcurrentHashMap.KeySetView Java Examples

The following examples show how to use java.util.concurrent.ConcurrentHashMap.KeySetView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleCloudStorageImpl.java    From hadoop-connectors with Apache License 2.0 6 votes vote down vote up
/** Processes failed copy requests */
private void onCopyFailure(
    KeySetView<IOException, Boolean> innerExceptions,
    GoogleJsonError jsonError,
    HttpHeaders responseHeaders,
    String srcBucketName,
    String srcObjectName) {
  GoogleJsonResponseException cause = createJsonResponseException(jsonError, responseHeaders);
  innerExceptions.add(
      errorExtractor.itemNotFound(cause)
          ? createFileNotFoundException(srcBucketName, srcObjectName, cause)
          : new IOException(
              String.format(
                  "Error copying '%s'", StringPaths.fromComponents(srcBucketName, srcObjectName)),
              cause));
}
 
Example #2
Source File: GoogleCloudStorageImpl.java    From hadoop-connectors with Apache License 2.0 4 votes vote down vote up
/**
 * See {@link GoogleCloudStorage#copy(String, List, String, List)} for details about expected
 * behavior.
 */
@Override
public void copy(
    String srcBucketName, List<String> srcObjectNames,
    String dstBucketName, List<String> dstObjectNames)
    throws IOException {
  validateCopyArguments(srcBucketName, srcObjectNames, dstBucketName, dstObjectNames, this);

  if (srcObjectNames.isEmpty()) {
    return;
  }

  // Gather FileNotFoundExceptions for individual objects,
  // but only throw a single combined exception at the end.
  KeySetView<IOException, Boolean> innerExceptions = ConcurrentHashMap.newKeySet();

  // Perform the copy operations.
  BatchHelper batchHelper =
      batchFactory.newBatchHelper(
          httpRequestInitializer,
          gcs,
          storageOptions.getCopyMaxRequestsPerBatch(),
          srcObjectNames.size(),
          storageOptions.getCopyBatchThreads());

  for (int i = 0; i < srcObjectNames.size(); i++) {
    if (storageOptions.isCopyWithRewriteEnabled()) {
      // Rewrite request has the same effect as Copy, but it can handle moving
      // large objects that may potentially timeout a Copy request.
      rewriteInternal(
          batchHelper,
          innerExceptions,
          srcBucketName, srcObjectNames.get(i),
          dstBucketName, dstObjectNames.get(i));
    } else {
      copyInternal(
          batchHelper,
          innerExceptions,
          srcBucketName, srcObjectNames.get(i),
          dstBucketName, dstObjectNames.get(i));
    }
  }

  // Execute any remaining requests not divisible by the max batch size.
  batchHelper.flush();

  if (!innerExceptions.isEmpty()) {
    throw GoogleCloudStorageExceptions.createCompositeException(innerExceptions);
  }
}