|
|
@ -57,8 +57,6 @@ public final class ServiceInstanceListSupplierBuilder { |
|
|
|
|
|
|
|
|
|
|
|
private Creator baseCreator; |
|
|
|
private Creator baseCreator; |
|
|
|
|
|
|
|
|
|
|
|
private DelegateCreator cachingCreator; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final List<DelegateCreator> creators = new ArrayList<>(); |
|
|
|
private final List<DelegateCreator> creators = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
ServiceInstanceListSupplierBuilder() { |
|
|
|
ServiceInstanceListSupplierBuilder() { |
|
|
@ -148,8 +146,10 @@ public final class ServiceInstanceListSupplierBuilder { |
|
|
|
* @return the {@link ServiceInstanceListSupplierBuilder} object |
|
|
|
* @return the {@link ServiceInstanceListSupplierBuilder} object |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ServiceInstanceListSupplierBuilder withSameInstancePreference() { |
|
|
|
public ServiceInstanceListSupplierBuilder withSameInstancePreference() { |
|
|
|
DelegateCreator creator = (context, |
|
|
|
DelegateCreator creator = (context, delegate) -> { |
|
|
|
delegate) -> new SameInstancePreferenceServiceInstanceListSupplier(delegate); |
|
|
|
LoadBalancerClientFactory loadBalancerClientFactory = context.getBean(LoadBalancerClientFactory.class); |
|
|
|
|
|
|
|
return new SameInstancePreferenceServiceInstanceListSupplier(delegate, loadBalancerClientFactory); |
|
|
|
|
|
|
|
}; |
|
|
|
this.creators.add(creator); |
|
|
|
this.creators.add(creator); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -191,8 +191,9 @@ public final class ServiceInstanceListSupplierBuilder { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ServiceInstanceListSupplierBuilder withZonePreference() { |
|
|
|
public ServiceInstanceListSupplierBuilder withZonePreference() { |
|
|
|
DelegateCreator creator = (context, delegate) -> { |
|
|
|
DelegateCreator creator = (context, delegate) -> { |
|
|
|
|
|
|
|
LoadBalancerClientFactory loadBalancerClientFactory = context.getBean(LoadBalancerClientFactory.class); |
|
|
|
LoadBalancerZoneConfig zoneConfig = context.getBean(LoadBalancerZoneConfig.class); |
|
|
|
LoadBalancerZoneConfig zoneConfig = context.getBean(LoadBalancerZoneConfig.class); |
|
|
|
return new ZonePreferenceServiceInstanceListSupplier(delegate, zoneConfig); |
|
|
|
return new ZonePreferenceServiceInstanceListSupplier(delegate, zoneConfig, loadBalancerClientFactory); |
|
|
|
}; |
|
|
|
}; |
|
|
|
this.creators.add(creator); |
|
|
|
this.creators.add(creator); |
|
|
|
return this; |
|
|
|
return this; |
|
|
@ -206,8 +207,9 @@ public final class ServiceInstanceListSupplierBuilder { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ServiceInstanceListSupplierBuilder withZonePreference(String zoneName) { |
|
|
|
public ServiceInstanceListSupplierBuilder withZonePreference(String zoneName) { |
|
|
|
DelegateCreator creator = (context, delegate) -> { |
|
|
|
DelegateCreator creator = (context, delegate) -> { |
|
|
|
|
|
|
|
LoadBalancerClientFactory loadBalancerClientFactory = context.getBean(LoadBalancerClientFactory.class); |
|
|
|
LoadBalancerZoneConfig zoneConfig = new LoadBalancerZoneConfig(zoneName); |
|
|
|
LoadBalancerZoneConfig zoneConfig = new LoadBalancerZoneConfig(zoneName); |
|
|
|
return new ZonePreferenceServiceInstanceListSupplier(delegate, zoneConfig); |
|
|
|
return new ZonePreferenceServiceInstanceListSupplier(delegate, zoneConfig, loadBalancerClientFactory); |
|
|
|
}; |
|
|
|
}; |
|
|
|
this.creators.add(creator); |
|
|
|
this.creators.add(creator); |
|
|
|
return this; |
|
|
|
return this; |
|
|
@ -228,19 +230,15 @@ public final class ServiceInstanceListSupplierBuilder { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* If {@link LoadBalancerCacheManager} is available in the context, wraps created |
|
|
|
* If {@link LoadBalancerCacheManager} is available in the context, adds a |
|
|
|
* {@link ServiceInstanceListSupplier} hierarchy with a |
|
|
|
* {@link CachingServiceInstanceListSupplier} instance to the |
|
|
|
* {@link CachingServiceInstanceListSupplier} instance to provide a caching mechanism |
|
|
|
* {@link ServiceInstanceListSupplier} hierarchy to provide a caching mechanism for |
|
|
|
* for service instances. Uses {@link ObjectProvider} to lazily resolve |
|
|
|
* service instances. Uses {@link ObjectProvider} to lazily resolve |
|
|
|
* {@link LoadBalancerCacheManager}. |
|
|
|
* {@link LoadBalancerCacheManager}. |
|
|
|
* @return the {@link ServiceInstanceListSupplierBuilder} object |
|
|
|
* @return the {@link ServiceInstanceListSupplierBuilder} object |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public ServiceInstanceListSupplierBuilder withCaching() { |
|
|
|
public ServiceInstanceListSupplierBuilder withCaching() { |
|
|
|
if (cachingCreator != null && LOG.isWarnEnabled()) { |
|
|
|
DelegateCreator creator = (context, delegate) -> { |
|
|
|
LOG.warn( |
|
|
|
|
|
|
|
"Overriding a previously set cachingCreator with a CachingServiceInstanceListSupplier-based cachingCreator."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.cachingCreator = (context, delegate) -> { |
|
|
|
|
|
|
|
ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context |
|
|
|
ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context |
|
|
|
.getBeanProvider(LoadBalancerCacheManager.class); |
|
|
|
.getBeanProvider(LoadBalancerCacheManager.class); |
|
|
|
if (cacheManagerProvider.getIfAvailable() != null) { |
|
|
|
if (cacheManagerProvider.getIfAvailable() != null) { |
|
|
@ -251,6 +249,7 @@ public final class ServiceInstanceListSupplierBuilder { |
|
|
|
} |
|
|
|
} |
|
|
|
return delegate; |
|
|
|
return delegate; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
creators.add(creator); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -297,9 +296,6 @@ public final class ServiceInstanceListSupplierBuilder { |
|
|
|
supplier = creator.apply(context, supplier); |
|
|
|
supplier = creator.apply(context, supplier); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (this.cachingCreator != null) { |
|
|
|
|
|
|
|
supplier = this.cachingCreator.apply(context, supplier); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return supplier; |
|
|
|
return supplier; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|