Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2014 Google Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 
 package com.google.cloud.hadoop.gcsio;
 
 
 
 import java.util.List;
 import java.util.Set;

MetadataReadOnlyGoogleCloudStorage holds a collection of Storage object/bucket metadata entries and serves listObjectNames, listObjectInfo, getItemInfos, and getItemInfo exclusively from the in-memory cache. All other operations will throw an UnsupportedOperationException. For the time being, such unsupported operations include bucket info list operations like listBucketInfo and listBucketNames. This instance will supplement fake GoogleCloudStorageItemInfos for pure implicit directories if there is no metadata entry for the directory object itself. This means that some directory objects will list info that is inconsistent with an actual listing.
 
     implements GoogleCloudStorage {
   // Logger.
   public static final Logger LOG =
       LoggerFactory.getLogger(MetadataReadOnlyGoogleCloudStorage.class);
 
   // Immutable cache of all metadata held by this instance, populated at construction time.
 
 
   // TODO(user): Consolidate this with the equivalent object in LaggedGoogleCloudStorage.java.
   private static final Function<GoogleCloudStorageItemInfoStringITEM_INFO_TO_NAME =
       new Function<GoogleCloudStorageItemInfoString>() {
         @Override
         public String apply(GoogleCloudStorageItemInfo itemInfo) {
           return itemInfo.getObjectName();
         }
       };

  
Constructs a MetadataReadOnlyGoogleCloudStorage that can be used for temporary contexts where only object metadata read operations will be used through the GoogleCloudStorage interface.

Parameters:
itemInfos The collection of item infos with which to serve all list/get object requests.
 
       throws IOException {
     // Entries never expire for this use case.
 
     .debug("Populating cache with {} entries."itemInfos.size());
     for (GoogleCloudStorageItemInfo itemInfo : itemInfos) {
       .putResourceId(itemInfo.getResourceId()).setItemInfo(itemInfo);
     }
      = GoogleCloudStorageOptions.newBuilder().build(); // for getOptions
   }
 
   @Override
     return ;
   }
 
   @Override
   public WritableByteChannel create(final StorageResourceId resourceId)
       throws IOException {
     throw new UnsupportedOperationException();
   }
 
   @Override
   public WritableByteChannel create(StorageResourceId resourceIdCreateObjectOptions options)
       throws IOException {
     throw new UnsupportedOperationException();
  }
  public void createEmptyObject(StorageResourceId resourceId)
      throws IOException {
    throw new UnsupportedOperationException();
  }
  public void createEmptyObject(StorageResourceId resourceIdCreateObjectOptions options)
      throws IOException {
    throw new UnsupportedOperationException();
  }
  public void createEmptyObjects(List<StorageResourceIdresourceIds)
      throws IOException {
    throw new UnsupportedOperationException();
  }
  public void createEmptyObjects(List<StorageResourceIdresourceIdsCreateObjectOptions options)
      throws IOException {
    throw new UnsupportedOperationException();
  }
      throws IOException {
    throw new UnsupportedOperationException();
  }
  public void create(String bucketName)
      throws IOException {
    throw new UnsupportedOperationException();
  }
  public void deleteBuckets(List<StringbucketNames)
      throws IOException {
    throw new UnsupportedOperationException();
  }
  public void deleteObjects(List<StorageResourceIdfullObjectNames)
      throws IOException {
    throw new UnsupportedOperationException();
  }
  public void copy(String srcBucketNameList<StringsrcObjectNames,
      String dstBucketNameList<StringdstObjectNames)
      throws IOException {
    throw new UnsupportedOperationException();
  }
      throws IOException {
    throw new UnsupportedOperationException();
  }
      throws IOException {
    throw new UnsupportedOperationException();
  }
      String bucketNameString objectNamePrefixString delimiter)
      throws IOException {
    return listObjectNames(bucketNameobjectNamePrefixdelimiter,
  }
      String bucketNameString objectNamePrefixString delimiter,
      long maxResults)
      throws IOException {
    .debug("listObjectNames({}, {}, {}, {})",
        bucketNameobjectNamePrefixdelimitermaxResults);
    return Lists.transform(
        listObjectInfo(bucketNameobjectNamePrefixdelimitermaxResults),
        );
  }

  
Uses shared prefix-matching logic to filter entries from the metadata cache. For implicit prefix matches with no corresponding real directory object, adds a fake directory object with creationTime == 0.
      final String bucketNameString objectNamePrefixString delimiter)
      throws IOException {
    return listObjectInfo(bucketNameobjectNamePrefixdelimiter,
  }

  
Uses shared prefix-matching logic to filter entries from the metadata cache. For implicit prefix matches with no corresponding real directory object, adds a fake directory object with creationTime == 0.
      final String bucketNameString objectNamePrefixString delimiter,
      long maxResults)
      throws IOException {
    .debug("listObjectInfo({}, {}, {}, {})",
        bucketNameobjectNamePrefixdelimitermaxResults);
    List<GoogleCloudStorageItemInfoallObjectInfos = new ArrayList<>();
    Set<StringretrievedNames = new HashSet<>();
    Set<Stringprefixes = new HashSet<>();
    List<CacheEntrycachedObjects = .getObjectList(
        bucketNameobjectNamePrefixdelimiterprefixes);
    if (cachedObjects != null) {
      // Pull the itemInfos out of all the matched entries; in our usage here of DirectoryListCache,
      // we expect the info to *always* be available.
      for (CacheEntry entry : cachedObjects) {
        GoogleCloudStorageItemInfo info = entry.getItemInfo();
        Preconditions.checkState(
            info != null"Cache entry missing info for name '%s'!"entry.getResourceId());
        allObjectInfos.add(info);
        retrievedNames.add(entry.getResourceId().getObjectName());
      }
      // Check whether each raw prefix already had a valid real entry; if not, we'll add a fake
      // directory object, but we'll keep track of it.
      // We add these inferred directories without requiring options in which
      // isInferImplicitDirectoriesEnabled() is true
      // (to maintain historical behavior).
      for (String prefix : prefixes) {
        if (!retrievedNames.contains(prefix)) {
          .debug("Found implicit directory '{}'. Adding fake entry for it."prefix);
          GoogleCloudStorageItemInfo fakeInfo = new GoogleCloudStorageItemInfo(
              new StorageResourceId(bucketNameprefix), 0, 0, nullnull);
          allObjectInfos.add(fakeInfo);
          retrievedNames.add(prefix);
          // Also add a concrete object for each implicit directory, since the caller may decide
          // to call getItemInfo sometime later after listing it.
          .putResourceId(fakeInfo.getResourceId()).setItemInfo(fakeInfo);
        }
      }
    }
    return allObjectInfos;
  }

  
Pure fetch from cache.
      throws IOException {
    .debug("getItemInfos({})"resourceIds.toString());
    List<GoogleCloudStorageItemInfoinfos = new ArrayList<>();
    for (StorageResourceId resourceId : resourceIds) {
      infos.add(getItemInfo(resourceId));
    }
    return infos;
  }
      throws IOException {
    throw new UnsupportedOperationException();
  }

  
Pure fetch from cache.
      throws IOException {
    .debug("getItemInfo({})"resourceId);
    CacheEntry entry = .getCacheEntry(resourceId);
    if (entry == null) {
      // TODO(user): Move the createItemInfoForNotFound method into GoogleCloudStorageItemInfo.
      return GoogleCloudStorageImpl.createItemInfoForNotFound(resourceId);
    } else {
      GoogleCloudStorageItemInfo info = entry.getItemInfo();
      Preconditions.checkState(
          info != null"Cache entry missing info for name '%s'!"entry.getResourceId());
      return info;
    }
  }
  public void close() {
    .debug("close()");
  }
  public void waitForBucketEmpty(String bucketName)
      throws IOException {
    throw new UnsupportedOperationException();
  }
New to GrepCode? Check out our FAQ X