org.apache.hadoop.registry.client.binding
Class RegistryTypeUtils

java.lang.Object
  extended by org.apache.hadoop.registry.client.binding.RegistryTypeUtils

@InterfaceAudience.Public
@InterfaceStability.Evolving
public class RegistryTypeUtils
extends Object

Static methods to work with registry types —primarily endpoints and the list representation of addresses.


Constructor Summary
RegistryTypeUtils()
           
 
Method Summary
static String getAddressField(Map<String,String> address, String field)
          Get a specific field from an address -raising an exception if the field is not present
static Map<String,String> hostnamePortPair(InetSocketAddress address)
          Create a (hostname, port) address pair
static Map<String,String> hostnamePortPair(String hostname, int port)
          Create a (hostname, port) address pair
static Endpoint inetAddrEndpoint(String api, String protocolType, String hostname, int port)
          Create an internet address endpoint from a list of URIs
static Endpoint ipcEndpoint(String api, InetSocketAddress address)
          Create an IPC endpoint
static Map<String,String> map(String key, String val)
          Create a single entry map
static void requireAddressType(String required, Endpoint epr)
          Require a specific address type on an endpoint
static Endpoint restEndpoint(String api, URI... uris)
          Create a REST endpoint from a list of URIs
static List<String> retrieveAddressesUriType(Endpoint epr)
          Get a single URI endpoint
static List<URL> retrieveAddressURLs(Endpoint epr)
          Get the address URLs.
static Map<String,String> uri(String uri)
          Create a URI
static Endpoint urlEndpoint(String api, String protocolType, URI... uris)
          Create a URL endpoint from a list of URIs
static void validateEndpoint(String path, Endpoint endpoint)
          Validate the endpoint by checking for null fields and other invalid conditions
static void validateServiceRecord(String path, ServiceRecord record)
          Validate the record by checking for null fields and other invalid conditions
static Endpoint webEndpoint(String api, URI... uris)
          Create a Web UI endpoint from a list of URIs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegistryTypeUtils

public RegistryTypeUtils()
Method Detail

urlEndpoint

public static Endpoint urlEndpoint(String api,
                                   String protocolType,
                                   URI... uris)
Create a URL endpoint from a list of URIs

Parameters:
api - implemented API
protocolType - protocol type
uris - URIs
Returns:
a new endpoint

restEndpoint

public static Endpoint restEndpoint(String api,
                                    URI... uris)
Create a REST endpoint from a list of URIs

Parameters:
api - implemented API
uris - URIs
Returns:
a new endpoint

webEndpoint

public static Endpoint webEndpoint(String api,
                                   URI... uris)
Create a Web UI endpoint from a list of URIs

Parameters:
api - implemented API
uris - URIs
Returns:
a new endpoint

inetAddrEndpoint

public static Endpoint inetAddrEndpoint(String api,
                                        String protocolType,
                                        String hostname,
                                        int port)
Create an internet address endpoint from a list of URIs

Parameters:
api - implemented API
protocolType - protocol type
hostname - hostname/FQDN
port - port
Returns:
a new endpoint

ipcEndpoint

public static Endpoint ipcEndpoint(String api,
                                   InetSocketAddress address)
Create an IPC endpoint

Parameters:
api - API
address - the address as a tuple of (hostname, port)
Returns:
the new endpoint

map

public static Map<String,String> map(String key,
                                     String val)
Create a single entry map

Parameters:
key - map entry key
val - map entry value
Returns:
a 1 entry map.

uri

public static Map<String,String> uri(String uri)
Create a URI

Parameters:
uri - value
Returns:
a 1 entry map.

hostnamePortPair

public static Map<String,String> hostnamePortPair(String hostname,
                                                  int port)
Create a (hostname, port) address pair

Parameters:
hostname - hostname
port - port
Returns:
a 1 entry map.

hostnamePortPair

public static Map<String,String> hostnamePortPair(InetSocketAddress address)
Create a (hostname, port) address pair

Parameters:
address - socket address whose hostname and port are used for the generated address.
Returns:
a 1 entry map.

requireAddressType

public static void requireAddressType(String required,
                                      Endpoint epr)
                               throws InvalidRecordException
Require a specific address type on an endpoint

Parameters:
required - required type
epr - endpoint
Throws:
InvalidRecordException - if the type is wrong

retrieveAddressesUriType

public static List<String> retrieveAddressesUriType(Endpoint epr)
                                             throws InvalidRecordException
Get a single URI endpoint

Parameters:
epr - endpoint
Returns:
the uri of the first entry in the address list. Null if the endpoint itself is null
Throws:
InvalidRecordException - if the type is wrong, there are no addresses or the payload ill-formatted

getAddressField

public static String getAddressField(Map<String,String> address,
                                     String field)
                              throws InvalidRecordException
Get a specific field from an address -raising an exception if the field is not present

Parameters:
address - address to query
field - field to resolve
Returns:
the resolved value. Guaranteed to be non-null.
Throws:
InvalidRecordException - if the field did not resolve

retrieveAddressURLs

public static List<URL> retrieveAddressURLs(Endpoint epr)
                                     throws InvalidRecordException,
                                            MalformedURLException
Get the address URLs. Guranteed to return at least one address.

Parameters:
epr - endpoint
Returns:
the address as a URL
Throws:
InvalidRecordException - if the type is wrong, there are no addresses or the payload ill-formatted
MalformedURLException - address can't be turned into a URL

validateServiceRecord

public static void validateServiceRecord(String path,
                                         ServiceRecord record)
                                  throws InvalidRecordException
Validate the record by checking for null fields and other invalid conditions

Parameters:
path - path for exceptions
record - record to validate. May be null
Throws:
InvalidRecordException - on invalid entries

validateEndpoint

public static void validateEndpoint(String path,
                                    Endpoint endpoint)
                             throws InvalidRecordException
Validate the endpoint by checking for null fields and other invalid conditions

Parameters:
path - path for exceptions
endpoint - endpoint to validate. May be null
Throws:
InvalidRecordException - on invalid entries


Copyright © 2014 Apache Software Foundation. All Rights Reserved.