p2ps.imp.net
Class NetworkFactory

java.lang.Object
  extended byp2ps.imp.net.NetworkFactory

public class NetworkFactory
extends java.lang.Object

A factory for interfacing the network architecture. The network factory allows different network implementations to be plugged in rather than assuming everything runs on top of the Internet as Java does.

Version:
$Revision: 295 $
Author:
Ian Wang

Field Summary
static NetworkInterface factory
           
static java.lang.String LOCALHOST
           
 
Constructor Summary
NetworkFactory()
           
 
Method Summary
static DatagramSocket createDatagramSocket(java.net.SocketAddress addr)
           
static DatagramSocket createDatagramSocket(java.net.SocketAddress addr, java.lang.String type, java.util.Map properties)
           
static java.net.SocketAddress createDiscoveryAddress()
           
static java.net.SocketAddress createGroupAddress(int port)
           
static MulticastSocket createMulticastSocket(java.net.SocketAddress addr)
           
static MulticastSocket createMulticastSocket(java.net.SocketAddress addr, java.lang.String type, java.util.Map properties)
           
static ServerSocket createServerSocket(java.net.SocketAddress addr)
           
static ServerSocket createServerSocket(java.net.SocketAddress addr, java.lang.String type, java.util.Map properties)
           
static Socket createSocket(java.net.SocketAddress addr)
           
static Socket createSocket(java.net.SocketAddress addr, java.lang.String type, java.util.Map properties)
           
static java.net.SocketAddress createSocketAddress(java.lang.String addr, int port)
           
static java.lang.String getHostAddress(java.net.SocketAddress address)
           
static java.lang.String getLocalHostAddress()
           
static java.net.NetworkInterface getNetworkInterface(java.net.SocketAddress addr)
           
static int getPort(java.net.SocketAddress address)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALHOST

public static final java.lang.String LOCALHOST
See Also:
Constant Field Values

factory

public static NetworkInterface factory
Constructor Detail

NetworkFactory

public NetworkFactory()
Method Detail

getLocalHostAddress

public static java.lang.String getLocalHostAddress()
                                            throws java.net.UnknownHostException
Returns:
the address of the local host as a String
Throws:
java.net.UnknownHostException

getNetworkInterface

public static java.net.NetworkInterface getNetworkInterface(java.net.SocketAddress addr)
                                                     throws java.net.SocketException
Returns:
the java.net network interface that owns the specified socket address. In non-java.net interfaces this method can probably return null.
Throws:
java.net.SocketException

createSocketAddress

public static java.net.SocketAddress createSocketAddress(java.lang.String addr,
                                                         int port)
Returns:
a new socket address

createGroupAddress

public static java.net.SocketAddress createGroupAddress(int port)
Returns:
a group address with the specified port

createDiscoveryAddress

public static java.net.SocketAddress createDiscoveryAddress()
Returns:
a group address with the specified port

getHostAddress

public static java.lang.String getHostAddress(java.net.SocketAddress address)
Returns:
the host address from a socket address

getPort

public static int getPort(java.net.SocketAddress address)
Returns:
the port from a socket address

createServerSocket

public static ServerSocket createServerSocket(java.net.SocketAddress addr)
                                       throws java.io.IOException
Parameters:
addr - the address the socket is bound to
Returns:
a default server socket bound to the specified port
Throws:
java.io.IOException

createServerSocket

public static ServerSocket createServerSocket(java.net.SocketAddress addr,
                                              java.lang.String type,
                                              java.util.Map properties)
                                       throws java.io.IOException
Parameters:
addr - the address the socket is bound to
type - the type of server socket
properties - properties of the server socket
Returns:
a server socket bound to the specified port
Throws:
java.io.IOException

createSocket

public static Socket createSocket(java.net.SocketAddress addr)
                           throws java.io.IOException
Parameters:
addr - the address the socket is bound to
Returns:
a socket instance
Throws:
java.io.IOException

createSocket

public static Socket createSocket(java.net.SocketAddress addr,
                                  java.lang.String type,
                                  java.util.Map properties)
                           throws java.io.IOException
Parameters:
addr - the address the socket is bound to
type - the type of socket instance
properties - properties of the socket instance
Returns:
a socket instance
Throws:
java.io.IOException

createDatagramSocket

public static DatagramSocket createDatagramSocket(java.net.SocketAddress addr)
                                           throws java.io.IOException
Parameters:
addr - the address the socket is bound to
Returns:
a datagram socket instance bound to the specified address
Throws:
java.io.IOException

createDatagramSocket

public static DatagramSocket createDatagramSocket(java.net.SocketAddress addr,
                                                  java.lang.String type,
                                                  java.util.Map properties)
                                           throws java.io.IOException
Parameters:
addr - the address the socket is bound to
type - the type of datagram socket instance
properties - properties of the datagram socket instance
Returns:
a datagram socket instance
Throws:
java.io.IOException

createMulticastSocket

public static MulticastSocket createMulticastSocket(java.net.SocketAddress addr)
                                             throws java.io.IOException
Parameters:
addr - the address the socket is bound to
Returns:
a multicast socket instance bound to the specified address
Throws:
java.io.IOException

createMulticastSocket

public static MulticastSocket createMulticastSocket(java.net.SocketAddress addr,
                                                    java.lang.String type,
                                                    java.util.Map properties)
                                             throws java.io.IOException
Parameters:
addr - the address the socket is bound to
type - the type of multicast socket instance
properties - properties of the multicast socket instance
Returns:
a multicast socket instance
Throws:
java.io.IOException