import org.dasein.cloud.dc.Region; //导入方法依赖的package包/类
@Override
public Collection listRegions() throws InternalException, CloudException {
APITrace.begin(provider, "listRegions");
try {
if( logger.isTraceEnabled() ) {
logger.trace("ENTER: " + DataCenters.class.getName() + ".listRegions()");
}
try {
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
logger.warn("Attempt to fetch regions with no context");
throw new NoContextException();
}
Cache cache = Cache.getInstance(provider, "regions", Region.class, CacheLevel.CLOUD_ACCOUNT, new TimePeriod(10, TimePeriod.HOUR));
Collection regions = (Collection)cache.get(ctx);
if( regions != null ) {
if( logger.isDebugEnabled() ) {
logger.debug("listRegions()=" + regions);
}
return regions;
}
regions = new ArrayList();
Region region = new Region();
region.setActive(true);
region.setAvailable(true);
String ctry = Locale.getDefault().getCountry();
if( ctry == null || ctry.equals("") ) {
ctry = "US";
}
try {
Jurisdiction.valueOf(ctry);
}
catch( Throwable ignore ) {
ctry = "US";
}
region.setJurisdiction(ctry);
region.setName(ctry);
region.setProviderRegionId(ctry);
regions.add(region);
cache.put(ctx, regions);
if( logger.isDebugEnabled() ) {
logger.debug("listRegions()=" + regions);
}
return regions;
}
finally {
if( logger.isTraceEnabled() ) {
logger.trace("EXIT: " + DataCenters.class.getName() + ".listRegions()");
}
}
}
finally {
APITrace.end();
}
}