Class PDU
- java.lang.Object
-
- com.opencloud.slee.resources.smpp.pdu.ByteData
-
- com.opencloud.slee.resources.smpp.pdu.PDU
-
- All Implemented Interfaces:
com.opencloud.util.FastSerializable
,Externalizable
,Serializable
public abstract class PDU extends ByteData implements Externalizable, com.opencloud.util.FastSerializable
Common base class for all SMPP PDU types- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected int
commandID
protected int
commandStatus
static int
MIN_SIZE
protected int
sequenceNumber
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTLV(TLV tlv)
Adds a TLV (optional field) to the end of this PDU.protected boolean
bodyEquals(PDU pdu)
Compares the body of given PDU with the body (not including header or TLVs) of this PDU for equality.protected void
bodyFromBuffer(ByteBuffer buf)
Read PDU body (not including header or TLVs) from a ByteBuffer.protected int
bodyHashCode()
Get the hash code value of PDU body (not including header or TLVs).protected int
bodySize()
Return size (in bytes) of PDU body (not including header or TLVs).protected void
bodyToBuffer(ByteBuffer buf)
Write PDU body (not including header or TLVs) to a ByteBuffer.protected String
bodyToString()
boolean
equals(Object o)
Compares given object with this PDU for equality, including header, body and optional TLVs.void
fromBuffer(ByteBuffer buf)
NOTE fromBuffer() assumes buffer contains ONLY one PDUvoid
fromStream(DataInput in)
List<TLV>
getAllTLVs()
Get the list of TLVs that this PDU contains.int
getCommandID()
int
getCommandLength()
int
getCommandStatus()
int
getSequenceNumber()
TLV
getTLV(short tag)
Get the TLV object that has this tag.int
hashCode()
Get the hash code value of this PDU, including header, body and optional TLVs.boolean
hasTLV(short tag)
protected boolean
headerEquals(PDU pdu)
protected void
headerFromBuffer(ByteBuffer buf)
protected int
headerHashCode()
protected int
headerSize()
protected void
headerToBuffer(ByteBuffer buf)
protected String
headerToString()
void
readExternal(ObjectInput in)
void
setCommandID(int commandID)
void
setCommandStatus(int commandStatus)
void
setSequenceNumber(int sequenceNumber)
int
size()
Get the number of bytes that this object containsprotected boolean
tlvEquals(PDU pdu)
Compares the optional TLVs of given PDU with the optional TLVs of this PDU for equality.protected void
tlvFromBuffer(ByteBuffer buf)
protected int
tlvHashCode()
Get the hash code value of all optional TLVs that have been added to this PDU.protected int
tlvSize()
Get size (in bytes) of all optional TLVs that have been added to this PDU.protected void
tlvToBuffer(ByteBuffer buf)
protected String
tlvToString()
void
toBuffer(ByteBuffer buf)
Write PDU, including header, body and TLV, to a buffer.void
toStream(DataOutput out)
String
toString()
void
writeExternal(ObjectOutput out)
-
Methods inherited from class com.opencloud.slee.resources.smpp.pdu.ByteData
checkCString, checkCString, checkDate, decodeUnsigned, encodeUnsigned, equalCStrings, getCString, getCString, getCStringByteArray, getCStringHashCode, isNullOrEmptyCString, printAsHex, putCString
-
-
-
-
Field Detail
-
commandID
protected int commandID
-
commandStatus
protected int commandStatus
-
sequenceNumber
protected int sequenceNumber
-
MIN_SIZE
public static final int MIN_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PDU
public PDU(int commandID)
-
PDU
protected PDU(DataInput in) throws IOException
- Throws:
IOException
-
-
Method Detail
-
getCommandLength
public int getCommandLength()
-
getCommandID
public int getCommandID()
-
getCommandStatus
public int getCommandStatus()
-
getSequenceNumber
public int getSequenceNumber()
-
setCommandID
public void setCommandID(int commandID)
-
setCommandStatus
public void setCommandStatus(int commandStatus)
-
setSequenceNumber
public void setSequenceNumber(int sequenceNumber)
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
toStream
public void toStream(DataOutput out) throws IOException
- Specified by:
toStream
in interfacecom.opencloud.util.FastSerializable
- Throws:
IOException
-
fromStream
public void fromStream(DataInput in) throws IOException
- Throws:
IOException
-
toBuffer
public final void toBuffer(ByteBuffer buf) throws BufferOverflowException
Write PDU, including header, body and TLV, to a buffer.- Specified by:
toBuffer
in classByteData
- Throws:
BufferOverflowException
-
headerToBuffer
protected final void headerToBuffer(ByteBuffer buf) throws BufferOverflowException
- Throws:
BufferOverflowException
-
bodyToBuffer
protected void bodyToBuffer(ByteBuffer buf) throws BufferOverflowException
Write PDU body (not including header or TLVs) to a ByteBuffer. Subclasses MUST override this if they have any additional fields in their body. Fields must be written in big-endian byte order (the default with ByteBuffer anyway).- Throws:
BufferOverflowException
-
tlvToBuffer
protected final void tlvToBuffer(ByteBuffer buf) throws BufferOverflowException
- Throws:
BufferOverflowException
-
fromBuffer
public final void fromBuffer(ByteBuffer buf) throws BufferUnderflowException, InvalidPDUFieldException
NOTE fromBuffer() assumes buffer contains ONLY one PDU- Specified by:
fromBuffer
in classByteData
- Throws:
BufferUnderflowException
InvalidPDUFieldException
-
headerFromBuffer
protected final void headerFromBuffer(ByteBuffer buf) throws BufferUnderflowException
- Throws:
BufferUnderflowException
-
bodyFromBuffer
protected void bodyFromBuffer(ByteBuffer buf) throws BufferUnderflowException, InvalidPDUFieldException
Read PDU body (not including header or TLVs) from a ByteBuffer. Subclasses MUST override this if they have any additional fields in their body. Fields are read in big-endian byte order (the default with ByteBuffer anyway).
-
tlvFromBuffer
protected final void tlvFromBuffer(ByteBuffer buf) throws BufferUnderflowException, InvalidPDUFieldException
-
size
public final int size()
Description copied from class:ByteData
Get the number of bytes that this object contains
-
headerSize
protected final int headerSize()
-
bodySize
protected int bodySize()
Return size (in bytes) of PDU body (not including header or TLVs). Subclasses MUST override this if they have any additional fields in their body, so that PDU lengths will be calculated correctly.
-
tlvSize
protected final int tlvSize()
Get size (in bytes) of all optional TLVs that have been added to this PDU.
-
headerToString
protected String headerToString()
-
bodyToString
protected String bodyToString()
-
tlvToString
protected String tlvToString()
-
addTLV
public void addTLV(TLV tlv) throws TLVAlreadyExistsException
Adds a TLV (optional field) to the end of this PDU. Note that for some types of TLV, the insertion order is significant, namely CALLBACK_NUM, CALLBACK_NUM_ATAG, CALLBACK_NUM_PRES_IND, and BROADCAST_AREA_IDENTIFIER, BROADCAST_ERROR_STATUS. For instance, there may be any number of callback TLVs and the order determines which CALLBACK_NUM_ATAG is associated with which CALLBACK_NUM etc. For all other TLV types, repetition is not permitted and attempting to add the same TLV twice will cause aTLVAlreadyExistsException
.- Parameters:
tlv
- the TLV to be added to this PDU.- Throws:
TLVAlreadyExistsException
- if a TLV of the same type has already been added to the PDU.
-
getTLV
public TLV getTLV(short tag)
Get the TLV object that has this tag.- Parameters:
tag
- the TLV tag to search for.- Returns:
- the TLV object containing
tag
, ornull
if it is not present in this PDU.
-
hasTLV
public boolean hasTLV(short tag)
-
getAllTLVs
public List<TLV> getAllTLVs()
Get the list of TLVs that this PDU contains. This should only be used by applications that need to support multiple occurrences of the same TLV (e.g. CALLBACK_NUM_xxx etc). For singular TLVs, usegetTLV(short)
.
-
equals
public boolean equals(Object o)
Compares given object with this PDU for equality, including header, body and optional TLVs.NOTE that the order/duplicates of TLVs are ONLY significant in terms of TLV pairs for TLV types, for which multiple occurrences are supported (e.g. CALLBACK_NUM_xxx etc). For all other TLV types the order/duplicates are insignificant in terms of the comparison result.
-
headerEquals
protected final boolean headerEquals(PDU pdu)
-
bodyEquals
protected boolean bodyEquals(PDU pdu)
Compares the body of given PDU with the body (not including header or TLVs) of this PDU for equality. Subclasses MUST override this if they have any additional fields in their body, so that PDUs comparison will be performed correctly.
-
tlvEquals
protected final boolean tlvEquals(PDU pdu)
Compares the optional TLVs of given PDU with the optional TLVs of this PDU for equality.NOTE that the order/duplicates are ONLY significant in terms of TLV pairs for TLV types, for which multiple occurrences are supported (e.g. CALLBACK_NUM_xxx). For all other TLV types the order/duplicates are insignificant in terms of the comparison result.
-
hashCode
public int hashCode()
Get the hash code value of this PDU, including header, body and optional TLVs.NOTE that the hash code will be computed using the mutable PDU fields. Meaning that the resulting hash code value following a PDU field value change, may differ from the hash code computed before the change.
-
headerHashCode
protected final int headerHashCode()
-
bodyHashCode
protected int bodyHashCode()
Get the hash code value of PDU body (not including header or TLVs). Subclasses MUST override this if they have any additional fields in their body, so that PDU hash code will be calculated correctly.
-
tlvHashCode
protected final int tlvHashCode()
Get the hash code value of all optional TLVs that have been added to this PDU.
-
-