com.twitter.common.net
Class InetSocketAddressHelper

java.lang.Object
  extended by com.twitter.common.net.InetSocketAddressHelper

public final class InetSocketAddressHelper
extends Object

A utility that can parse [host]:[port] pairs or :[port] designators into instances of InetSocketAddress. The literal '*' can be specified for port as an alternative to '0' to indicate any local port.


Field Summary
static Function<InetSocketAddress,String> INET_TO_STR
           
static Function<Integer,InetSocketAddress> INT_TO_INET
          A function that uses getLocalAddress(int) to map a local port number to an InetSocketAddress.
static Function<String,InetSocketAddress> STR_TO_INET
          A function that uses parse(String) to map an endpoint spec to an InetSocketAddress.
 
Method Summary
static Set<InetSocketAddress> convertToSockets(Iterable<String> backends)
          Converts backend definitions (in host:port form) a set of socket addresses.
static InetSocketAddress getLocalAddress(int port)
           
static InetSocketAddress parse(String value)
          Attempts to parse an endpoint spec into an InetSocketAddress.
static String toString(InetSocketAddress value)
          Attempts to return a usable String given an InetSocketAddress.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STR_TO_INET

public static final Function<String,InetSocketAddress> STR_TO_INET
A function that uses parse(String) to map an endpoint spec to an InetSocketAddress.


INT_TO_INET

public static final Function<Integer,InetSocketAddress> INT_TO_INET
A function that uses getLocalAddress(int) to map a local port number to an InetSocketAddress. If an UnknownHostException is thrown, it will be propagated as a RuntimeException.


INET_TO_STR

public static final Function<InetSocketAddress,String> INET_TO_STR
Method Detail

parse

public static InetSocketAddress parse(String value)
Attempts to parse an endpoint spec into an InetSocketAddress.


toString

public static String toString(InetSocketAddress value)
Attempts to return a usable String given an InetSocketAddress.

Parameters:
value - the InetSocketAddress.
Returns:
the String representation of the InetSocketAddress.

getLocalAddress

public static InetSocketAddress getLocalAddress(int port)
                                         throws UnknownHostException
Throws:
UnknownHostException

convertToSockets

public static Set<InetSocketAddress> convertToSockets(Iterable<String> backends)
Converts backend definitions (in host:port form) a set of socket addresses.

Parameters:
backends - Backends to convert.
Returns:
Sockets representing the provided backends.