com.netflix.client
Class ClientFactory

java.lang.Object
  extended by com.netflix.client.ClientFactory

public class ClientFactory
extends java.lang.Object

A factory that creates client, load balancer and client configuration instances from properties. It also keeps mappings of client names to the created instances.


Constructor Summary
ClientFactory()
           
 
Method Summary
static IClient createNamedClient(java.lang.String name, java.lang.Class<? extends IClientConfig> configClass)
          Creates a named client using a IClientConfig instance created off the configClass class object passed in as the parameter.
static IClient getNamedClient(java.lang.String name)
          Return the named client from map if already created.
static IClientConfig getNamedConfig(java.lang.String name)
          Get the client configuration given the name or create one with DefaultClientConfigImpl if it does not exist.
static IClientConfig getNamedConfig(java.lang.String name, java.lang.Class<? extends IClientConfig> clientConfigClass)
          Get the client configuration given the name or create one with clientConfigClass if it does not exist.
static ILoadBalancer getNamedLoadBalancer(java.lang.String name)
          Get the load balancer associated with the name, or create one with an instance DefaultClientConfigImpl if does not exist
static ILoadBalancer getNamedLoadBalancer(java.lang.String name, java.lang.Class<? extends IClientConfig> configClass)
          Get the load balancer associated with the name, or create one with an instance of configClass if does not exist
static java.lang.Object instantiateInstanceWithClientConfig(java.lang.String className, IClientConfig clientConfig)
          Creates instance related to client framework using reflection.
static IClient<?,?> registerClientFromProperties(java.lang.String restClientName, IClientConfig clientConfig)
          Utility method to create client and load balancer (if enabled in client config) given the name and client config.
static ILoadBalancer registerNamedLoadBalancerFromclientConfig(java.lang.String name, IClientConfig clientConfig)
          Create and register a load balancer with the name and given the class of configClass.
static ILoadBalancer registerNamedLoadBalancerFromProperties(java.lang.String name, java.lang.Class<? extends IClientConfig> configClass)
          Create and register a load balancer with the name and given the class of configClass.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientFactory

public ClientFactory()
Method Detail

registerClientFromProperties

public static IClient<?,?> registerClientFromProperties(java.lang.String restClientName,
                                                        IClientConfig clientConfig)
                                                 throws ClientException
Utility method to create client and load balancer (if enabled in client config) given the name and client config. Instances are created using reflection (see instantiateInstanceWithClientConfig(String, IClientConfig)

Parameters:
restClientName -
clientConfig -
Returns:
Throws:
ClientException - if any errors occurs in the process, or if the client with the same name already exists

getNamedClient

public static IClient getNamedClient(java.lang.String name)
Return the named client from map if already created. Otherwise creates the client using the configuration returned by getNamedConfig(String).

Throws:
java.lang.RuntimeException - if an error occurs in creating the client.

createNamedClient

public static IClient createNamedClient(java.lang.String name,
                                        java.lang.Class<? extends IClientConfig> configClass)
                                 throws ClientException
Creates a named client using a IClientConfig instance created off the configClass class object passed in as the parameter.

Throws:
ClientException - if any error occurs, or if the client with the same name already exists

getNamedLoadBalancer

public static ILoadBalancer getNamedLoadBalancer(java.lang.String name)
Get the load balancer associated with the name, or create one with an instance DefaultClientConfigImpl if does not exist

Throws:
java.lang.RuntimeException - if any error occurs

getNamedLoadBalancer

public static ILoadBalancer getNamedLoadBalancer(java.lang.String name,
                                                 java.lang.Class<? extends IClientConfig> configClass)
Get the load balancer associated with the name, or create one with an instance of configClass if does not exist

Throws:
java.lang.RuntimeException - if any error occurs
See Also:
registerNamedLoadBalancerFromProperties(String, Class)

registerNamedLoadBalancerFromclientConfig

public static ILoadBalancer registerNamedLoadBalancerFromclientConfig(java.lang.String name,
                                                                      IClientConfig clientConfig)
                                                               throws ClientException
Create and register a load balancer with the name and given the class of configClass.

Throws:
ClientException - if load balancer with the same name already exists or any error occurs
See Also:
instantiateInstanceWithClientConfig(String, IClientConfig)

registerNamedLoadBalancerFromProperties

public static ILoadBalancer registerNamedLoadBalancerFromProperties(java.lang.String name,
                                                                    java.lang.Class<? extends IClientConfig> configClass)
                                                             throws ClientException
Create and register a load balancer with the name and given the class of configClass.

Throws:
ClientException - if load balancer with the same name already exists or any error occurs
See Also:
instantiateInstanceWithClientConfig(String, IClientConfig)

instantiateInstanceWithClientConfig

public static java.lang.Object instantiateInstanceWithClientConfig(java.lang.String className,
                                                                   IClientConfig clientConfig)
                                                            throws java.lang.InstantiationException,
                                                                   java.lang.IllegalAccessException,
                                                                   java.lang.ClassNotFoundException
Creates instance related to client framework using reflection. It first checks if the object is an instance of IClientConfigAware and if so invoke IClientConfigAware.initWithNiwsConfig(IClientConfig). If that does not apply, it tries to find if there is a constructor with IClientConfig as a parameter and if so invoke that constructor. If neither applies, it simply invokes the no-arg constructor and ignores the clientConfig parameter.

Parameters:
className - Class name of the object
clientConfig - IClientConfig object used for initialization.
Returns:
Throws:
java.lang.InstantiationException
java.lang.IllegalAccessException
java.lang.ClassNotFoundException

getNamedConfig

public static IClientConfig getNamedConfig(java.lang.String name)
Get the client configuration given the name or create one with DefaultClientConfigImpl if it does not exist.

See Also:
getNamedConfig(String, Class)

getNamedConfig

public static IClientConfig getNamedConfig(java.lang.String name,
                                           java.lang.Class<? extends IClientConfig> clientConfigClass)
Get the client configuration given the name or create one with clientConfigClass if it does not exist. An instance of IClientConfig is created and IClientConfig.loadProperties(String) will be called.