hypercast
Class INETv4TwoPorts

java.lang.Object
  |
  +--hypercast.INETv4TwoPorts
All Implemented Interfaces:
I_Address, I_NetworkAddress, I_PhysicalAddress

public class INETv4TwoPorts
extends java.lang.Object
implements I_PhysicalAddress

This class implements a physical address which works on the TCP/IP networks and contains a IP version 4 address and two port numbers.


Field Summary
static int ADDRESS_SIZE
          The size of INETv4TwoPorts type physical address when carried in the packet.
 
Constructor Summary
INETv4TwoPorts(byte[] byteAddrPort)
          Constructs a INETv4TwoPorts object from a byte array.
INETv4TwoPorts(java.net.InetAddress a, int nodeport, int scktport)
          Constructs a INETv4AndOnePort object from an InetAddress instance and two port numbers.
INETv4TwoPorts(hypercast.INETv4TwoPorts a)
          Constructs a INETv4TwoPorts object with another INETv4TwoPorts object.
INETv4TwoPorts(int nodeport, int scktport)
          Constructs a INETv4TwoPorts object with two port numbers.
INETv4TwoPorts(java.lang.String addrAndPortsString)
          Constructs a INETv4TwoPorts object with a string representing address and two port numbers.
 
Method Summary
 boolean addressCheck(java.lang.Object obj)
          Test if the node adapter related part of two INETv4TwoPorts address are identical.
 boolean equals(java.lang.Object obj)
          Test if two INETv4TwoPorts address are identical.
 java.net.InetAddress getInetAddress()
          Gets INETv4 address of this object.
 int getNodeAdptPort()
          Return the first port number in ths physical address.
static java.lang.String[] getPartsFromAddrAndPortsString(java.lang.String addrAndPortString)
          Get different parts from a string which carries address and ports information.
 int getScktAdptPort()
          Return the second port number in ths physical address.
 int getSize()
          Returns the byte array size
 boolean greaterThan(hypercast.I_Address addr)
          Compares two INETv4TwoPorts address objects.
 int hashCode()
          Returns a hashcode of this object It is important that the argument is of type Object so that it can be used in a Hashtable.
 byte[] toByteArray()
          Converts the Address/Port1/Port2 to a 8 bytes array.
 java.lang.String toString()
          Converts the IP address object to string format "xxx.xxx.xxx.xxx/port1/port2" (e.g.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ADDRESS_SIZE

public static final int ADDRESS_SIZE
The size of INETv4TwoPorts type physical address when carried in the packet.

See Also:
Constant Field Values
Constructor Detail

INETv4TwoPorts

public INETv4TwoPorts(hypercast.INETv4TwoPorts a)
Constructs a INETv4TwoPorts object with another INETv4TwoPorts object.

Parameters:
a - An INETv4TwoPorts object.

INETv4TwoPorts

public INETv4TwoPorts(java.lang.String addrAndPortsString)
Constructs a INETv4TwoPorts object with a string representing address and two port numbers.

Parameters:
addrAndPortsString - An string representing an address and two port numbers.

INETv4TwoPorts

public INETv4TwoPorts(java.net.InetAddress a,
                      int nodeport,
                      int scktport)
Constructs a INETv4AndOnePort object from an InetAddress instance and two port numbers.

Parameters:
a - an instance of InetAddress
nodeport - port number for node adapter
scktport - port number for socket adapter

INETv4TwoPorts

public INETv4TwoPorts(int nodeport,
                      int scktport)
Constructs a INETv4TwoPorts object with two port numbers. The IP addeess is obtained from local host.

Parameters:
nodeport - port number for Node Adapter.
scktport - port number for Socket Adapter.

INETv4TwoPorts

public INETv4TwoPorts(byte[] byteAddrPort)
Constructs a INETv4TwoPorts object from a byte array.

Parameters:
byteAddrPort - a byte array storing IP address and two port numbers.
Method Detail

getPartsFromAddrAndPortsString

public static java.lang.String[] getPartsFromAddrAndPortsString(java.lang.String addrAndPortString)
Get different parts from a string which carries address and ports information. The address and ports string may have formats like "128.143.71.29:9800:9801", "0.0.0.0:0:0". It also may be in the format of "9800", i.e., only consists of a number. In this case, it is considered as the port number for Node Adapter. An example of this case is that when we start a DT server, the port number is specified in the commandline and is used to initialize the socket in the Node Adapter.

Parameters:
addrAndPortString - the string of address and ports.

getInetAddress

public java.net.InetAddress getInetAddress()
Gets INETv4 address of this object.


getNodeAdptPort

public int getNodeAdptPort()
Return the first port number in ths physical address.


getScktAdptPort

public int getScktAdptPort()
Return the second port number in ths physical address.


getSize

public int getSize()
Returns the byte array size

Specified by:
getSize in interface I_Address

toByteArray

public byte[] toByteArray()
Converts the Address/Port1/Port2 to a 8 bytes array. The format is |--------4-------|------2------|------2------| | IP |NodeAdpt port|ScktAdpt port| |----------------|-------------|-------------|

Specified by:
toByteArray in interface I_Address
Returns:
a 8 byte array where the first 4 bytes holds the address, the next 2 holds the Node Adapter port and the last 2 bytes holds the Socket Adapter port.

equals

public boolean equals(java.lang.Object obj)
Test if two INETv4TwoPorts address are identical.

Specified by:
equals in interface I_Address
Overrides:
equals in class java.lang.Object
Parameters:
obj - an object (should be of type INETv4TwoPorts.)
Throws:
java.lang.IllegalArgumentException - if obj is not of type INETv4TwoPorts.

addressCheck

public boolean addressCheck(java.lang.Object obj)
Test if the node adapter related part of two INETv4TwoPorts address are identical.

Specified by:
addressCheck in interface I_PhysicalAddress
Parameters:
obj - an object (should be of type INETv4TwoPorts.)
Throws:
java.lang.IllegalArgumentException - if obj is not of type INETv4TwoPorts.

greaterThan

public boolean greaterThan(hypercast.I_Address addr)
Compares two INETv4TwoPorts address objects.

Specified by:
greaterThan in interface I_Address
Parameters:
addr - an object of type I_Address
Returns:
true if (this > addr), otherwise false
Throws:
java.lang.IllegalArgumentException - if obj is not of type INETv4TwoPorts.

toString

public java.lang.String toString()
Converts the IP address object to string format "xxx.xxx.xxx.xxx/port1/port2" (e.g. "128.143.71.50/4747/5001")

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode of this object It is important that the argument is of type Object so that it can be used in a Hashtable.

Specified by:
hashCode in interface I_Address
Overrides:
hashCode in class java.lang.Object