J-Sim v1.2.1-p7 API

drcl.net
Class Packet

java.lang.Object
  extended bydrcl.DrclObj
      extended bydrcl.net.Packet
All Implemented Interfaces:
java.lang.Cloneable, Countable, ObjectDuplicable, PacketWrapper, java.io.Serializable
Direct Known Subclasses:
FooPacket, InetPacket, OSPF_Packet, TCPPacket, UDPPacket

public abstract class Packet
extends DrclObj
implements PacketWrapper, Countable

This class defines the base class for implementing packets. A packet consists of a header and a body. The header structure should be further defined in subclasses. This class defines the interface a subclass should/would implement, and implements the setter/getter methods for the encapsulated body object, the packet size and the header size.

See Also:
Serialized Form

Field Summary
 java.lang.Object body
           
 int headerSize
           
 long id
          The packet ID that is used and maintained by instrument components, should be globally and uniquely recognized.
 int size
           
 
Constructor Summary
Packet()
           
Packet(int packetSize_)
           
Packet(int headerSize_, int bodySize_, java.lang.Object body_)
           
 
Method Summary
 java.lang.String _toString(java.lang.String separator_)
          Prints the packet header.
 void duplicate(java.lang.Object source_)
          opies the content of the source_ object to this object.
 boolean equals(java.lang.Object that_)
          Returns true if that_ is a packet, and its packet size, header size and the encapsulated object are all equal to those of this packet.
 java.lang.Object getBody()
          Returns the encapsulated object of this packet.
 long getByteCount()
          Returns the byte count of this packet in the connection to which this packet belongs.
 int getHeaderSize()
          Returns the header size of this packet.
abstract  java.lang.String getName()
          Returns the name of this packet.
 int getNumberCount()
           
 int getPacketCount()
          Returns the count of this packet in the connection to which this packet belongs.
 int getPacketSize()
          Returns the packet size of this packet.
 java.lang.String getPacketType()
          Returns the type of packet.
 int getSize()
          Returns the packet size of this packet.
 long getSizeCount()
           
 double getTimestamp()
           
 boolean isByteCountSupported()
           
 boolean isPacketCountSupported()
           
 boolean isTimestampSupported()
           
 void setBody(java.lang.Object b_, int bodySize_)
          Sets the encapsulated object of this packet.
 void setBody(Packet b_)
          Sets the encapsulated object of this packet with another packet.
 void setHeaderSize(int hsize_)
          Sets the header size of this packet.
 void setPacketSize(int packetSize_)
          Sets the packet size of this packet.
 void setSize(int packetSize_, int headerSize_)
          Sets the packet and header sizes of this packet.
 void setTimestamp(double time_)
           
 java.lang.String toString()
          Prints the content of this packet; subclasses should override _toString(String).
 java.lang.String toString(java.lang.String separator_)
          Prints the content of this packet; subclasses should override _toString(String).
 void wraps(Packet p_)
          Wraps the argument packet as the body of this packet.
 
Methods inherited from class drcl.DrclObj
clone
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface drcl.net.PacketWrapper
clone
 

Field Detail

body

public java.lang.Object body

size

public int size

headerSize

public int headerSize

id

public long id
The packet ID that is used and maintained by instrument components, should be globally and uniquely recognized.

Constructor Detail

Packet

public Packet()

Packet

public Packet(int packetSize_)

Packet

public Packet(int headerSize_,
              int bodySize_,
              java.lang.Object body_)
Method Detail

duplicate

public void duplicate(java.lang.Object source_)
Description copied from class: DrclObj
opies the content of the source_ object to this object. he subclass must implement this method to realize DrclObj.clone().

Specified by:
duplicate in interface ObjectDuplicable
Overrides:
duplicate in class DrclObj

getName

public abstract java.lang.String getName()
Returns the name of this packet.


getBody

public java.lang.Object getBody()
Returns the encapsulated object of this packet.


setBody

public void setBody(Packet b_)
Sets the encapsulated object of this packet with another packet.


wraps

public void wraps(Packet p_)
Wraps the argument packet as the body of this packet.

Specified by:
wraps in interface PacketWrapper

setBody

public void setBody(java.lang.Object b_,
                    int bodySize_)
Sets the encapsulated object of this packet.


getPacketSize

public int getPacketSize()
Returns the packet size of this packet.


getSize

public int getSize()
Returns the packet size of this packet.

Specified by:
getSize in interface Countable

setPacketSize

public void setPacketSize(int packetSize_)
Sets the packet size of this packet.


setHeaderSize

public void setHeaderSize(int hsize_)
Sets the header size of this packet.


getHeaderSize

public int getHeaderSize()
Returns the header size of this packet.


getPacketType

public java.lang.String getPacketType()
Returns the type of packet. By default, it delegates the call to the encapsulated packet, and returns getName() otherwise.


getPacketCount

public int getPacketCount()
Returns the count of this packet in the connection to which this packet belongs. By default, it delegates the call to the encapsulated packet, and throws a PacketException if the encapsulated object is not a packet.


getNumberCount

public int getNumberCount()
Specified by:
getNumberCount in interface Countable
See Also:
getPacketCount()

isPacketCountSupported

public boolean isPacketCountSupported()

getByteCount

public long getByteCount()
Returns the byte count of this packet in the connection to which this packet belongs. By default, it delegates the call to the encapsulated packet, and throws a PacketException if the encapsulated object is not a packet. This method approximates the byte count with the byte count obtained from the encapsulated packet plus the header size times the packet count.


getSizeCount

public long getSizeCount()
Specified by:
getSizeCount in interface Countable
See Also:
getByteCount()

isByteCountSupported

public boolean isByteCountSupported()

getTimestamp

public double getTimestamp()

setTimestamp

public void setTimestamp(double time_)

isTimestampSupported

public boolean isTimestampSupported()

setSize

public void setSize(int packetSize_,
                    int headerSize_)
Sets the packet and header sizes of this packet.


toString

public java.lang.String toString()
Prints the content of this packet; subclasses should override _toString(String).

Overrides:
toString in class DrclObj

toString

public java.lang.String toString(java.lang.String separator_)
Prints the content of this packet; subclasses should override _toString(String).


_toString

public java.lang.String _toString(java.lang.String separator_)
Prints the packet header.


equals

public boolean equals(java.lang.Object that_)
Returns true if that_ is a packet, and its packet size, header size and the encapsulated object are all equal to those of this packet.


J-Sim v1.2.1-p7 API

Copyright © 1998-2003 Distributed Real-time Computing Lab (DRCL). All Rights Reserved.     ~ To J-Sim Home ~