Browse Source

Tidy up generics a bit

pull/6/head
Dave Syer 10 years ago
parent
commit
66b4d4c6b5
  1. 15
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java
  2. 3
      spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java

15
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java

@ -52,12 +52,12 @@ public class SpringClientFactory { @@ -52,12 +52,12 @@ public class SpringClientFactory {
loadBalancer = getNamedLoadBalancer(restClientName, clientConfig.getClass());
}
if (client instanceof AbstractLoadBalancerAwareClient) {
((AbstractLoadBalancerAwareClient) client).setLoadBalancer(loadBalancer);
((AbstractLoadBalancerAwareClient<?,?>) client).setLoadBalancer(loadBalancer);
}
} catch (Throwable e) {
String message = "Unable to InitializeAndAssociateNFLoadBalancer set for RestClient:"
+ restClientName;
log.warn(message, e);
log.warn(message);
throw new ClientException(ClientException.ErrorType.CONFIGURATION,
message, e);
}
@ -74,11 +74,11 @@ public class SpringClientFactory { @@ -74,11 +74,11 @@ public class SpringClientFactory {
*
* @throws RuntimeException if an error occurs in creating the client.
*/
public synchronized IClient getNamedClient(String name) {
public synchronized IClient<?,?> getNamedClient(String name) {
return getNamedClient(name, DefaultClientConfigImpl.class);
}
public synchronized <C extends IClient> C namedClient(String name, Class<C> clientClass) {
public synchronized <C extends IClient<?,?>> C namedClient(String name, Class<C> clientClass) {
return clientClass.cast(getNamedClient(name, DefaultClientConfigImpl.class));
}
@ -87,7 +87,7 @@ public class SpringClientFactory { @@ -87,7 +87,7 @@ public class SpringClientFactory {
*
* @throws RuntimeException if an error occurs in creating the client.
*/
public synchronized IClient getNamedClient(String name, Class<? extends IClientConfig> configClass) {
public synchronized IClient<?,?> getNamedClient(String name, Class<? extends IClientConfig> configClass) {
if (simpleClientMap.get(name) != null) {
return simpleClientMap.get(name);
}
@ -103,7 +103,7 @@ public class SpringClientFactory { @@ -103,7 +103,7 @@ public class SpringClientFactory {
*
* @throws ClientException if any error occurs, or if the client with the same name already exists
*/
public synchronized IClient createNamedClient(String name, Class<? extends IClientConfig> configClass) throws ClientException {
public synchronized IClient<?,?> createNamedClient(String name, Class<? extends IClientConfig> configClass) throws ClientException {
IClientConfig config = getNamedConfig(name, configClass);
return registerClientFromProperties(name, config);
}
@ -183,10 +183,9 @@ public class SpringClientFactory { @@ -183,10 +183,9 @@ public class SpringClientFactory {
* @param className Class name of the object
* @param clientConfig IClientConfig object used for initialization.
*/
@SuppressWarnings("unchecked")
public Object instantiateInstanceWithClientConfig(String className, IClientConfig clientConfig)
throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Class clazz = Class.forName(className);
Class<?> clazz = Class.forName(className);
if (IClientConfigAware.class.isAssignableFrom(clazz)) {
IClientConfigAware obj = (IClientConfigAware) clazz.newInstance();
obj.initWithNiwsConfig(clientConfig);

3
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/eureka/EurekaRibbonClientPreprocessor.java

@ -21,7 +21,7 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList; @@ -21,7 +21,7 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
/**
* Preprocessor that configures defaults for eureka-discovered ribbon clients.
* Such as: @zone, NIWSServerListClassName, DeploymentContextBasedVipAddresses,
* Such as: <code>@zone</code>, NIWSServerListClassName, DeploymentContextBasedVipAddresses,
* NFLoadBalancerRuleClassName, NIWSServerListFilterClassName and more
*
* @author Spencer Gibb
@ -58,6 +58,7 @@ public class EurekaRibbonClientPreprocessor implements RibbonClientPreprocessor @@ -58,6 +58,7 @@ public class EurekaRibbonClientPreprocessor implements RibbonClientPreprocessor
setProp(serviceId, DeploymentContextBasedVipAddresses.key(), serviceId);
setProp(serviceId, NFLoadBalancerRuleClassName.key(),
ZoneAvoidanceRule.class.getName());
// TODO: use bean name indirection to get this filter to be a @Bean
setProp(serviceId, NIWSServerListFilterClassName.key(),
ZonePreferenceServerListFilter.class.getName());
setProp(serviceId, EnableZoneAffinity.key(), "true");

Loading…
Cancel
Save