All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyuncs.regions.RemoteEndpointsParser Maven / Gradle / Ivy

Go to download

Aliyun Open API SDK for Java Copyright (C) Alibaba Cloud Computing All rights reserved. 版权所有 (C)阿里云计算有限公司 http://www.aliyun.com

There is a newer version: 4.7.3
Show newest version
package com.aliyuncs.regions;

import com.aliyuncs.auth.Credential;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class RemoteEndpointsParser implements IEndpointsProvider {

    private ConcurrentMap> endpointMap = new ConcurrentHashMap>();

    private DescribeEndpointService               describeEndpointService;

    public void setDescribeEndpointService(DescribeEndpointService describeEndpointService) {
        this.describeEndpointService = describeEndpointService;
    }

    public static RemoteEndpointsParser initRemoteEndpointsParser() {
        RemoteEndpointsParser parser = new RemoteEndpointsParser();
        parser.setDescribeEndpointService(new DescribeEndpointServiceImpl());
        return parser;
    }

    @Override
    public List getEndpoints() throws ClientException {
        throw new UnsupportedOperationException();
    }

    @Override
    public List getEndpoints(String regionId, String serviceCode, String endpointType, Credential credential,
                                       LocationConfig locationConfig) throws ClientException {
        List endpoints = endpointMap.get(serviceCode);
        if (endpoints != null) {
            return endpoints;
        }

        DescribeEndpointResponse response = describeEndpointService.describeEndpoint(regionId, serviceCode,
                endpointType, credential, locationConfig);
        if (response == null) {
            return endpoints;
        }
        Set regionIds = new HashSet();
        regionIds.add(response.getRegionId());

        List productDomainList = Arrays.asList(new ProductDomain(response.getProduct(), response
                .getEndpoint()));
        Endpoint endpoint = new Endpoint(response.getRegionId(), regionIds, productDomainList);
        endpoints = Arrays.asList(endpoint);
        endpointMap.putIfAbsent(serviceCode, endpoints);
        return endpoints;
    }

    public static void main(String[] args) throws ClientException {

        IClientProfile profile= DefaultProfile.getProfile("cn-qingdao", "account", "secret");
        List list =  profile.getEndpoints("Ecs", "ecs", "");
        System.out.println(list.get(0));

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy