NetworkMessage: introduce _sendersUniqueID, _receivedFrom, fix serialize length issue...
authorEddie <dev@fun2be.me>
Sat, 6 Jun 2015 07:54:03 +0000 (08:54 +0100)
committerEddie <dev@fun2be.me>
Sat, 6 Jun 2015 09:34:15 +0000 (10:34 +0100)
commit4f0912bc8443b28e2f9b051d95b8b2234291e7bb
tree2bbe2b9b81979da15a573a2bdc0fe7e603bddfc7
parentee33999f4338567c1fb03e7bc525035c29b4d3b4
NetworkMessage: introduce _sendersUniqueID, _receivedFrom, fix serialize length issues, log Exceptions

 * introduce _sendersUniqueID, _receivedFrom
 * remove _class
 * fix serialize length issue
 * logging of Exceptions

_sendersUniqueID solves the issue of accurately detecting packets that
have looped back which can happen with UDP multicast unless the socket
is configured with MulitcastSocket.setLoopbackMode(false).
It is set by each object that sends messages. Those objects allocate themselves
a random, final, unique ID during construction.
Loopback was previously detected using _sender but that was fragile and had
unpredictable failures.

Introduced getReceivedFrom()
_receivedFrom is filled in by the receiving network service using the Protocol
IP:port of the sender. This solves a big issue with accurately
maintaining the ServiceAddressMap with correct IP:port tupals for
neighbour service discovery. That functionality sends MessagePresence
objects that are supposed to contain the senders IP:port.
In the case of sender services that bind to their local wildcard address
(0.0.0.0/0.0.0.0) that is the address received in the MessagePresence object,
and does not identify the true sending interface address, only the port number.

_class has been removed since it is no longer used. There is no need to
store a class type descriptor for the enclosed MessageAbstract object
since Java's streamed object serialization deals with that issue
internally.

Introduced deserialize(byte[] bytes, int length)
Serialized length. In some circumstances a NetworkMessage _serializedLength would
be set to the maximum size of a UDP packet payload (65507 bytes) rather
than its true size. This was caused by the backing byte[] buffer being
allocated that amount of memory and the deserialize code not being able
to detect the true size of the object within the buffer.

The new method allows the size of a received DatagramPacket payload to
be passed into the deserialize() method and used to control the size of
the backing buffer of the ByteArrayInputStream. Additional checks are
done to ensure that the size of the deserialized object is obtained from
the number of bytes read out of the ByteArrayInputStream.

Exception logging. This will create a local logger to report the issue.
This could be improved by finding a way to get the application's
logger so that exceptions are logged to the network Log Service when it
is active.
src/uk/ac/ntu/n0521366/wsyd/libs/net/NetworkMessage.java