Search in sources :

Example 1 with MicroserviceInstanceResponse

use of org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceResponse in project incubator-servicecomb-java-chassis by apache.

the class ServiceRegistryClientImpl method findServiceInstance.

@Override
public MicroserviceInstance findServiceInstance(String serviceId, String instanceId) {
    try {
        Holder<MicroserviceInstanceResponse> holder = new Holder<>();
        IpPort ipPort = ipPortManager.getAvailableAddress();
        CountDownLatch countDownLatch = new CountDownLatch(1);
        RestUtils.get(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ONE, serviceId, instanceId), new RequestParam().addHeader("X-ConsumerId", serviceId), syncHandler(countDownLatch, MicroserviceInstanceResponse.class, holder));
        countDownLatch.await();
        if (null != holder.value) {
            return holder.value.getInstance();
        }
        return null;
    } catch (Exception e) {
        LOGGER.error("get instance from sc failed");
        return null;
    }
}
Also used : Holder(javax.xml.ws.Holder) IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) MicroserviceInstanceResponse(org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceResponse)

Example 2 with MicroserviceInstanceResponse

use of org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceResponse in project java-chassis by ServiceComb.

the class ServiceRegistryClientImpl method findServiceInstance.

@Override
public MicroserviceInstance findServiceInstance(String serviceId, String instanceId) {
    try {
        Holder<MicroserviceInstanceResponse> holder = new Holder<>();
        IpPort ipPort = ipPortManager.getAvailableAddress();
        CountDownLatch countDownLatch = new CountDownLatch(1);
        restClientUtil.get(ipPort, String.format(Const.REGISTRY_API.MICROSERVICE_INSTANCE_OPERATION_ONE, serviceId, instanceId), new RequestParam().addHeader("X-ConsumerId", serviceId).addQueryParam("global", "true"), syncHandler(countDownLatch, MicroserviceInstanceResponse.class, holder));
        countDownLatch.await();
        if (null != holder.value) {
            return holder.value.getInstance();
        }
        return null;
    } catch (Exception e) {
        LOGGER.error("get instance from sc failed");
        return null;
    }
}
Also used : IpPort(org.apache.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(org.apache.servicecomb.serviceregistry.client.ClientException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) MicroserviceInstanceResponse(org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceResponse)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)2 IpPort (org.apache.servicecomb.foundation.common.net.IpPort)2 MicroserviceInstanceResponse (org.apache.servicecomb.serviceregistry.api.response.MicroserviceInstanceResponse)2 ClientException (org.apache.servicecomb.serviceregistry.client.ClientException)2 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Holder (javax.xml.ws.Holder)1