@Override public ServiceInformation findServiceInformation(final String serviceName, final String serviceType, final ServiceHint... hints) throws ServiceNotAvailableException { final ConsistentHashRing services = findRing(serviceName, serviceType); if (CollectionUtils.isEmpty(services)) { throw new ServiceNotAvailableException("No %s/%s service found", serviceName, serviceType); } final ServiceInformation service = selectHintedService(services, hints); if (service == null) { throw new ServiceNotAvailableException("No %s/%s service found", serviceName, serviceType); } return service; }
@Override @SuppressWarnings("PMD.PreserveStackTrace") public URI findServiceUri(final String serviceName, final String serviceType, final ServiceHint... hints) throws ServiceNotAvailableException { final ServiceInformation service = findServiceInformation(serviceName, serviceType, hints); final String locatedScheme = service .getProperty(ServiceInformation.PROP_SERVICE_SCHEME); final String locatedAddress = service .getProperty(ServiceInformation.PROP_SERVICE_ADDRESS); final String locatedPort = service .getProperty(ServiceInformation.PROP_SERVICE_PORT); if (StringUtils.isEmpty(locatedScheme) || StringUtils.isEmpty(locatedAddress) || StringUtils.isEmpty(locatedPort)) { throw new ServiceNotAvailableException( "Service %s/%s exists but misses address information (%s/%s)", serviceName, serviceType, locatedAddress, locatedPort); } try { return new URI(locatedScheme, null, locatedAddress, Integer.parseInt(locatedPort), "", null, null); } catch (URISyntaxException use) { throw new ServiceNotAvailableException( "Could not create URI from '%s'!", service); } }
throw new ServiceNotAvailableException("Service discovery is disabled!"); final String address = serviceInfo.getProperty(ServiceInformation.PROP_SERVICE_ADDRESS); if (StringUtils.isEmpty(scheme) || StringUtils.isEmpty(address)) { throw new ServiceNotAvailableException("Service Information %s is incomplete!", serviceInfo); throw new ServiceNotAvailableException("Bad port (%s) in Service Information %s is incomplete!", portStr, serviceInfo);