use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.
the class CseDiscoveryClient method getInstances.
@Override
public List<ServiceInstance> getInstances(final String serviceId) {
List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
ServiceRegistryClient client = RegistryClientFactory.getRegistryClient();
String appId = DynamicPropertyFactory.getInstance().getStringProperty("APPLICATION_ID", "default").get();
ReferenceConfig referenceConfig = consumerProviderManager.getReferenceConfig(serviceId);
String versionRule = referenceConfig.getMicroserviceVersionRule();
String cseServiceID = client.getMicroserviceId(appId, serviceId, versionRule);
List<MicroserviceInstance> cseServices = client.getMicroserviceInstance(cseServiceID, cseServiceID);
if (null != cseServices && !cseServices.isEmpty()) {
for (MicroserviceInstance instance : cseServices) {
List<String> eps = instance.getEndpoints();
for (String ep : eps) {
URIEndpointObject uri = new URIEndpointObject(ep);
instances.add(new DefaultServiceInstance(instance.getServiceId(), uri.getHostOrIp(), uri.getPort(), false));
}
}
}
return instances;
}
use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.
the class IpPortManager method get.
public IpPort get() {
List<CacheEndpoint> addresses = getAddressCaches();
if (addresses == null || addresses.size() == 0) {
return getDefaultIpPort();
}
synchronized (lockObj) {
int id = indexForAuto.get();
addressCanUsed.putIfAbsent(id, true);
return new URIEndpointObject(addresses.get(id).getEndpoint());
}
}
use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.
the class IpPortManager method next.
public IpPort next() {
List<CacheEndpoint> addresses = getAddressCaches();
if ((addresses == null || addresses.size() == 0)) {
return nextDefaultIpPort();
}
synchronized (lockObj) {
int id = indexForAuto.get();
// 重置可用的地址为false
if (addressCanUsed.get(id) != null && addressCanUsed.get(id)) {
addressCanUsed.put(id, false);
if (id == addresses.size() - 1) {
indexForAuto.set(0);
// 重新轮询
addressCanUsed.clear();
LOGGER.warn("service center has no available instance");
return null;
} else {
indexForAuto.getAndIncrement();
}
LOGGER.warn("service center instance {} is unreachable, try another instance {}", addresses.get(id).getEndpoint(), addresses.get(indexForAuto.get()).getEndpoint());
}
return new URIEndpointObject(addresses.get(indexForAuto.get()).getEndpoint());
}
}
use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.
the class ServletRestTransport method send.
@Override
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
RestTransportClient client = RestTransportClientManager.INSTANCE.getRestTransportClient(endpoint.isSslEnabled());
client.send(invocation, asyncResp);
}
use of io.servicecomb.foundation.common.net.URIEndpointObject in project java-chassis by ServiceComb.
the class HighwayTransport method send.
@Override
public void send(Invocation invocation, AsyncResponse asyncResp) throws Exception {
URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
HighwayClient client = HighwayClientManager.INSTANCE.getHighwayClient(endpoint.isSslEnabled());
client.send(invocation, asyncResp);
}
Aggregations