WSYD_SocketAddress: add constructor for InetSocketAddress, missing javadocs
authorEddie <dev@fun2be.me>
Sat, 6 Jun 2015 08:37:22 +0000 (09:37 +0100)
committerEddie <dev@fun2be.me>
Sat, 6 Jun 2015 09:36:42 +0000 (10:36 +0100)
Introduce WSYD_SocketAddress(InetSocketAddress socketAddress, Protocol protocol)
New constructor to support easier creation of object instances for
tracking hosts that are inserted into ServiceAddressMap.

src/uk/ac/ntu/n0521366/wsyd/libs/net/WSYD_SocketAddress.java

index d818632..2021d02 100644 (file)
@@ -28,8 +28,6 @@ import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
 import java.io.IOException;
 import java.text.MessageFormat;
-import uk.ac.ntu.n0521366.wsyd.libs.net.Network;
-
 
 /**
  * Network socket properties.
@@ -46,13 +44,48 @@ import uk.ac.ntu.n0521366.wsyd.libs.net.Network;
  * @author Eddie Berrisford-Lynch <dev@fun2be.me>
  */
 public class WSYD_SocketAddress implements java.io.Serializable {
+
+    /**
+     * true if this (UDP) socket should be part of a multicast group.
+     */
     Boolean _multicast;
+
+    /**
+     * true if the protocol:address:port combination is known to be responding.
+     */
     Boolean _isReachable;
+
+    /**
+     * The IP Protocol to use.
+     */
     Protocol _protocol;
+
+    /**
+     * The underlying socket address object.
+     */
     InetSocketAddress _socketAddress;
     
-    public static enum Protocol {TCP, UDP}
+    /**
+     * Use descriptive mnemonic for selection of the IP Protocol.
+     */
+    public static enum Protocol {
+        /**
+         * IP TCP protocol.
+         */
+        TCP,
+        /**
+         * IP UDP protocol. (Multicast uses UDP)
+         */
+        UDP
+    }
 
+    /**
+     * Convert an IPv4 String to a 4 byte (32-bit) representation.
+     * 
+     * @param ipv4 dotted-decimal string representation
+     * @return literal value used by other network socket class methods
+     * @throws IllegalArgumentException 
+     */
     public static byte[] stringIPv4ToBytes4(String ipv4) throws IllegalArgumentException {
         byte[] result = new byte[4];
         if (ipv4 == null)
@@ -90,7 +123,18 @@ public class WSYD_SocketAddress implements java.io.Serializable {
     }
 
     /**
-     * Construct a viable Socket.
+     * Construction viable socket from a SocketAddress.
+     * @param socketAddress the IP:port pair
+     * @param protocol
+     */
+    public WSYD_SocketAddress(InetSocketAddress socketAddress, Protocol protocol) {
+        this();
+        _socketAddress = socketAddress;
+        _protocol = protocol;
+    }
+
+    /**
+     * Construct viable Socket from component parts.
      * 
      * @param address host IP address
      * @param port number