Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----mil.navy.nps.dis.PduElement | +----mil.navy.nps.dis.ProtocolDataUnit
I generally declare instance variables to be protected, which means that they are directly accessible from this class and all subclasses. Those who believe in full-jackboot mode will want them declared private, so subclasses can't access them either.
The accessor methods (getProtocolVersion et al) are declared public, so that anyone, including those outside this package, can access them. You should always go through accessor methods when setting values inside an object. Direct access from outside the class can cause mysterious errors that are very hard to track down.
Note that, due to garbage collection, we don't have to worry about the status of orphaned instance variables. For example, this operation will cause memory leaks in C++ or Obj-C:
protocolVersion = newProtocolVersion;In C++, this operation would leave an orphaned object; the _old_ object that was held by protocolVersion would have no valid pointers to it, but would still take up memory. With GC, the old, orphaned protocolVersion's memory will be scavanged and returned to use.
Accessor methods return a copy of the thing they're getting, not the actual thing. This prevents violations of encapsulation. If this weren't the case, we might see something like this:
this would return another pointer to the same object contained inside of
aPdu. addOne() would modify the value inside of aPdu, a violation of
encapsulation. So instead we implement getLength() like this:
myLength = aPdu.getLength();
myLength.addOne();
this creates an identical copy of length and returns that. The calling
method can modify that to its heart's content without affecting aPdu.
For the same reason, the clone() method should make copies of all the
instance variables. Otherwise, the "new" object will have pointers
shared with the old object. The clone() operation also helps prevent
big dependency meshes for GC.
public UnsignedByte getLength()
{ return (UnsignedByte)length.clone();
}
Serialization should make a call to the superclass before it does its own instance variables.
Note that we do not include the padding variables in the instance variables of objects. Padding is used only in the serialized, external representation of a PDU. The user would have no reason to do anything with padding in an object. Since it is only an artifact of serialization, references to padding are limited to the serialization/deserialization methods.
Also, the length, a field in the header portion, is calculated on the fly rather than saved and set. The header has a fixed length, 18 bytes. To find the size of a PDU, implement the length() method in all the subclasses. This should make a call to super, do any local calculations required, then return the correct number. Your code might look like :
public int length() {
return super.length() + 110 + aVector.size * anElement.length();
}
This adds up the length of the superclass, such as the PDU header, the basic length of the subclass (such as the entity state PDU), and adds the length of any variable number of parameters attached to the PDU.
Field Summary | |
static boolean | DEBUG
|
mil.navy.nps.util.UnsignedByte | exerciseID
|
mil.navy.nps.util.UnsignedByte | pduType
|
mil.navy.nps.util.UnsignedByte | protocolFamily
|
mil.navy.nps.util.UnsignedByte | protocolVersion
|
static int | sizeOf
sizeOf = 12 bytes .
|
mil.navy.nps.util.UnsignedInt | timestamp
|
Constructor Summary | |
ProtocolDataUnit()
|
Method Summary | |
static void | |
java.lang.Object | clone()
|
static ProtocolDataUnit | datagramToPdu(java.net.DatagramPacket pDatagramPacket)
|
void | deSerialize(java.io.DataInputStream inputStream)
|
mil.navy.nps.util.UnsignedByte | getExerciseID()
|
mil.navy.nps.util.UnsignedByte | getPduType()
|
mil.navy.nps.util.UnsignedByte | getProtocolFamily()
|
mil.navy.nps.util.UnsignedByte | getProtocolVersion()
|
mil.navy.nps.util.UnsignedInt | getTimestamp()
|
double | getVRMLTimestamp()
|
int | length()
|
void | makeTimestampCurrent()
|
java.lang.String | PDUName()
|
void | printValues(int indentLevel,
java.io.PrintStream printStream)
|
void | serialize(java.io.DataOutputStream outputStream)
|
void | setExerciseID(mil.navy.nps.util.UnsignedByte pExerciseID)
|
void | setExerciseID(int pExerciseID)
|
void | setPduType(mil.navy.nps.util.UnsignedByte pPduType)
|
void | setPduType(short pPduType)
|
void | setProtocolFamily(mil.navy.nps.util.UnsignedByte pProtocolFamily)
|
void | setProtocolFamily(int pProtocolFamily)
|
void | setProtocolVersion(mil.navy.nps.util.UnsignedByte pProtocolVersion)
|
void | setProtocolVersion(int pProtocolVersion)
|
static void | setSimulationStartTime(long pStartTime)
|
void | setTimestamp(mil.navy.nps.util.UnsignedInt pTimestamp)
|
void | setTimestamp(long pTimestamp)
|
Methods inherited from class mil.navy.nps.dis.PduElement |
clone, deSerialize, length, printValues, serialize |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final boolean DEBUG
protected mil.navy.nps.util.UnsignedByte protocolVersion
protocolVersion=5
No default value is set.
protected mil.navy.nps.util.UnsignedByte exerciseID
protected mil.navy.nps.util.UnsignedByte pduType
protected mil.navy.nps.util.UnsignedByte protocolFamily
protected mil.navy.nps.util.UnsignedInt timestamp
public static final int sizeOf
sizeOf = 12 bytes
.Constructor Detail |
public ProtocolDataUnit()
Method Detail |
static void()
public java.lang.Object clone()
public void printValues(int indentLevel, java.io.PrintStream printStream)
public void makeTimestampCurrent()
public double getVRMLTimestamp()
public static void setSimulationStartTime(long pStartTime)
public abstract java.lang.String PDUName()
String
public mil.navy.nps.util.UnsignedByte getProtocolVersion()
public void setProtocolVersion(mil.navy.nps.util.UnsignedByte pProtocolVersion)
public void setProtocolVersion(int pProtocolVersion)
public mil.navy.nps.util.UnsignedByte getExerciseID()
public void setExerciseID(mil.navy.nps.util.UnsignedByte pExerciseID)
public void setExerciseID(int pExerciseID)
public mil.navy.nps.util.UnsignedByte getPduType()
public void setPduType(mil.navy.nps.util.UnsignedByte pPduType)
public void setPduType(short pPduType)
public mil.navy.nps.util.UnsignedByte getProtocolFamily()
public void setProtocolFamily(mil.navy.nps.util.UnsignedByte pProtocolFamily)
public void setProtocolFamily(int pProtocolFamily)
public mil.navy.nps.util.UnsignedInt getTimestamp()
public void setTimestamp(mil.navy.nps.util.UnsignedInt pTimestamp)
public void setTimestamp(long pTimestamp)
public int length()
public void serialize(java.io.DataOutputStream outputStream)
public void deSerialize(java.io.DataInputStream inputStream)
public static ProtocolDataUnit datagramToPdu(java.net.DatagramPacket pDatagramPacket)
ProtocolDataUnit
|
^
EntityStatePDU
The deserialize message goes first to the EntityStatePdu. The ESPDU
immediately calls the deserialize method in its superclass, ProtocolDataUnit.
PDU deserializes the first few instance variables, then returns. The ESPDU
then deserializes its ivars.
Prints out some information during exectuion if debugging flag is set.
pDatagramPacket
- The datagram packet read from the wire
Contents | Package | Class | Tree | Deprecated | Index | Help | |||
PREV | NEXT | SHOW LISTS | HIDE LISTS |