com.amazonaws.partitions.PartitionMetadataProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ibm-cos-java-sdk-bundle Show documentation
Show all versions of ibm-cos-java-sdk-bundle Show documentation
A single bundled dependency that includes all service and dependent JARs with third-party libraries relocated to different namespaces.
/*
* Copyright 2016-2017 Amazon.com, Inc. or its affiliates. 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.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file 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.amazonaws.partitions;
import com.amazonaws.annotation.SdkInternalApi;
import com.amazonaws.partitions.model.Partition;
import com.amazonaws.regions.AbstractRegionMetadataProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.util.ValidationUtils;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Region metadata provider based on partitions.
*/
@SdkInternalApi
public class PartitionMetadataProvider extends AbstractRegionMetadataProvider {
private final Map partitionMap = new HashMap();
private final Map regionCache = new ConcurrentHashMap();
public PartitionMetadataProvider(List partitions) {
ValidationUtils.assertNotNull(partitions, "partitions");
for (Partition p : partitions) {
partitionMap.put(p.getPartition(), p);
}
}
@Override
public List getRegions() {
final List regions = new ArrayList();
for (Partition p : partitionMap.values()) {
for (Map.Entry
entry : p.getRegions().entrySet()) {
regions.add(new Region(new PartitionRegionImpl(entry.getKey(),
p)));
}
}
return Collections.unmodifiableList(regions);
}
@Override
public Region getRegion(String regionName) {
if (regionName == null) return null;
final Region regionFromCache = getRegionFromCache(regionName);
if (regionFromCache != null) {
return regionFromCache;
}
return createNewRegion(regionName);
}
private Region createNewRegion(String regionName) {
for (Partition p : partitionMap.values()) {
if (p.hasRegion(regionName)) {
return cacheRegion(new PartitionRegionImpl(regionName, p));
}
}
return null;
}
private Region getRegionFromCache(String regionName) {
return regionCache.get(regionName);
}
private Region cacheRegion(PartitionRegionImpl regionImpl) {
final Region region = new Region(regionImpl);
regionCache.put(region.getName(), region);
return region;
}
@Override
public List getRegionsForService(String serviceName) {
final List allRegions = getRegions();
final List serviceSupportedRegions = new ArrayList();
for (Region r : allRegions) {
if (r.isServiceSupported(serviceName)) {
serviceSupportedRegions.add(r);
}
}
return serviceSupportedRegions;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy