Class NetServerMessage
java.lang.Object
cl.obcom.desktopfx.layout.LayoutMessage
cl.obcom.desktopfx.netserver.NetServerMessage
- All Implemented Interfaces:
Serializable, Cloneable
Unit of communication between the endpoints of a
NetServerChannel. A
message is composed of a fixed set of codes, zero or more
labels, and zero or more data bytes. A NetServerMessage
is transmitted through the wire in the following serialized format:
+-+-----+-+-+----------------------------------------------------+
|V|12345|F|T|QOI<FS>KVVV...V<FS>KVVV...V<GS>SSIRMMPDDD......DDXXX|
+-+-----+-+-+----------------------------------------------------+
Message Header (8 Bytes)
V: Version Code (0x1E)
L: Length (12345)
F: Padding Count (X)
T: Type Code
Message Data (L-8 Bytes)
Q: Sequence Number
O: Operation Code
<FS>: Field Separator (0x1C)
K: Label Name
V: Label Data Bytes
<GS>: Group Separator (0x1D)
S: Server Code
I: Session ID Code
R: Request/Reply Code
M: Form Code
P: Protection Code
D: Data Bytes
X: Padding Bytes (F)- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDefines the possible labels of aNetServerMessage.static interfaceDefines the operation codes of aNetServerMessage.static interfaceDefines the protection codes of aNetServerMessage.static interfaceDefines the reply codes of aNetServerMessage.static interfaceDefines the possible types of aNetServerMessage. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newNetServerMessageinstance with zero length data.NetServerMessage(String data) Creates a newNetServerMessagewith the supplieddata. -
Method Summary
Modifier and TypeMethodDescriptionclone()Returns a "deep" copy of thisNetServerMessage.voidcopyFrom(NetServerMessage source) Copies all the properties of source into thisNetServerMessage.getData()Returns the text data of thisNetServerMessagewith trailing spaces removed (right trimmed).Returns the text data of thisNetServerMessagewith trailing spaces preserved (not removed).byte[]Returns the binary data of thisNetServerMessage.intReturns the form code of thisNetServerMessage.getLabel(int key) Returns the string value of the label identified bykey.Returns the multicast name of thisNetServerMessage.intReturns the operation code of thisNetServerMessage.intReturns the protection code of thisNetServerMessage.intReturns the reply code of thisNetServerMessage.intReturns the sequence of thisNetServerMessage.intReturns the server code of thisNetServerMessage.intReturns the session ID of thisNetServerMessage.intReturns the transaction code of thisNetServerMessage.intgetType()Returns the type of thisNetServerMessage.booleanReturnstrueif thisNetServerMessagehas data and no headers.booleanisLabelDefined(int key) Returnstrueif the label indexed by key is defined.voidremoveLabel(int key) Removes the label identified bykeyfrom thisNetServerMessage.voidRemoves all the labels defined in thisNetServerMessage.byte[]Returns a serialized version of thisNetServerMessage.byte[]serialize(boolean withType) Returns a serialized version of thisNetServerMessagewith optional type code.voidChanges the text data of thisNetServerMessage.voidsetDataBytes(byte[] bytes) Changes the binary data of thisNetServerMessage.voidsetDataOnly(boolean isDataOnly) Changes whether thisNetServerMessagehas data and no headers.voidsetFormCode(int formCode) Changes the form code of thisNetServerMessage.voidChanges the string value of the label identified bykey.voidsetOpCode(int opcode) Changes the operation code of thisNetServerMessage.voidsetProtCode(int protCode) Changes the protection code of thisNetServerMessage.voidsetReplyCode(int replyCode) Changes the reply code of thisNetServerMessage.voidsetSequence(int sequence) Changes the sequence of thisNetServerMessage.voidsetServerCode(int serverCode) Changes the server code of thisNetServerMessage.voidsetSessionID(int sessionID) Changes the session ID of thisNetServerMessage.voidsetTranCode(int tranCode) Changes the transaction code of thisNetServerMessage.voidsetType(int type) Changes the type of thisNetServerMessage.toString()Returns a string representation of thisNetServerMessage.static NetServerMessageunserialize(byte[] bytes, int offset, int length) Creates a newNetServerMessageby unserializing the supplied byte array.static NetServerMessageunserialize(byte[] bytes, int offset, int length, boolean withType) Creates a newNetServerMessageby unserializing the supplied byte array.Methods inherited from class LayoutMessage
copyFrom, exists, getChar, getChar, getDate, getDate, getDefaultSignANSI, getDouble, getDouble, getField, getInteger, getInteger, getLayout, getLong, getLong, getNumber, getNumber, getOccurs, getString, getString, getSubstring, getSubstring, getText, getText, getTextLen, getTextTrim, getValue, getValue, initFields, initFields, isNull, isNull, isNull, isSignANSI, setChar, setChar, setDate, setDate, setDefaultSignANSI, setDouble, setDouble, setInteger, setInteger, setLayout, setLong, setLong, setNull, setNull, setNumber, setNumber, setSignANSI, setString, setString, setSubstring, setText, setValue, setValue, toXml, toXml, verifyLayout
-
Constructor Details
-
NetServerMessage
public NetServerMessage()Creates a newNetServerMessageinstance with zero length data. The message codes are set to default values, and no message labels are defined. -
NetServerMessage
Creates a newNetServerMessagewith the supplieddata. The codes of the new message are set to default values, and no message labels are defined.- Parameters:
data- the initial data of theNetServerMessage.
-
-
Method Details
-
getType
public int getType()Returns the type of thisNetServerMessage.- Returns:
- the type of this
NetServerMessage.
-
setType
public void setType(int type) Changes the type of thisNetServerMessage.- Parameters:
type- the new type of thisNetServerMessage.
-
getSequence
public int getSequence()Returns the sequence of thisNetServerMessage.- Returns:
- the sequence of this
NetServerMessage.
-
setSequence
public void setSequence(int sequence) Changes the sequence of thisNetServerMessage.- Parameters:
sequence- newNetServerMessagesequence.
-
getOpCode
public int getOpCode()Returns the operation code of thisNetServerMessage.- Returns:
- the operation code of this
NetServerMessage.
-
setOpCode
public void setOpCode(int opcode) Changes the operation code of thisNetServerMessage.- Parameters:
opcode- newNetServerMessageoperation code.
-
getServerCode
public int getServerCode()Returns the server code of thisNetServerMessage.- Returns:
- the server code of this
NetServerMessage.
-
setServerCode
public void setServerCode(int serverCode) Changes the server code of thisNetServerMessage.- Parameters:
serverCode- newNetServerMessageserver code.
-
getSessionID
public int getSessionID()Returns the session ID of thisNetServerMessage.- Returns:
- the session ID of this
NetServerMessage.
-
setSessionID
public void setSessionID(int sessionID) Changes the session ID of thisNetServerMessage.- Parameters:
sessionID- newNetServerMessagesession ID.
-
getTranCode
public int getTranCode()Returns the transaction code of thisNetServerMessage.- Returns:
- the transaction code of this
NetServerMessage.
-
setTranCode
public void setTranCode(int tranCode) Changes the transaction code of thisNetServerMessage.- Parameters:
tranCode- newNetServerMessagetransaction code.
-
getReplyCode
public int getReplyCode()Returns the reply code of thisNetServerMessage.- Returns:
- the reply code of this
NetServerMessage.
-
setReplyCode
public void setReplyCode(int replyCode) Changes the reply code of thisNetServerMessage.- Parameters:
replyCode- newNetServerMessagereply code.
-
getFormCode
public int getFormCode()Returns the form code of thisNetServerMessage.- Returns:
- the form code of this
NetServerMessage.
-
setFormCode
public void setFormCode(int formCode) Changes the form code of thisNetServerMessage.- Parameters:
formCode- newNetServerMessageform code.
-
getProtCode
public int getProtCode()Returns the protection code of thisNetServerMessage.- Returns:
- the protection code of this
NetServerMessage.
-
setProtCode
public void setProtCode(int protCode) Changes the protection code of thisNetServerMessage.- Parameters:
protCode- newNetServerMessageprotection code.
-
removeLabels
public void removeLabels()Removes all the labels defined in thisNetServerMessage. -
isLabelDefined
public boolean isLabelDefined(int key) Returnstrueif the label indexed by key is defined.- Parameters:
key- the index of the label (LABEL_XXXXX).- Returns:
trueif the label indexed bykeyis defined.
-
getLabel
Returns the string value of the label identified bykey. If the required label is not defined, it returnsnull. There is not way to know if the value of a label is actuallynullor if the label was undefined.- Parameters:
key- the index of the label (LABEL_XXXXX).- Returns:
- the string value of the required label.
- Throws:
IndexOutOfBoundsException- ifkeyis out-of-range.
-
removeLabel
public void removeLabel(int key) Removes the label identified bykeyfrom thisNetServerMessage. Nothing happens if the label is not defined in thisNetServerMessage.- Parameters:
key- the index of the label (LABEL_XXXXX).- Throws:
IndexOutOfBoundsException- ifkeyis out-of-range.
-
setLabel
Changes the string value of the label identified bykey. Setting the value of the label tonullhas the effect as removing the label from thisNetServerMessage. That is, it has exactly the same effect as calling theremoveLabelmethod with the samekey.- Parameters:
key- the index of the label (LABEL_XXXXX).value- new value of the label ornull.- Throws:
IndexOutOfBoundsException- ifkeyis out-of-range.
-
getMulticatName
Returns the multicast name of thisNetServerMessage. If this is not a multicast message, it returnesnull.- Returns:
- the multicast name of this message or
null.
-
isDataOnly
public boolean isDataOnly()Returnstrueif thisNetServerMessagehas data and no headers.- Returns:
trueif thisNetServerMessagehas data and no headers.
-
setDataOnly
public void setDataOnly(boolean isDataOnly) Changes whether thisNetServerMessagehas data and no headers.- Parameters:
isDataOnly- the new value of the data only property.
-
getDataAll
Returns the text data of thisNetServerMessagewith trailing spaces preserved (not removed).- Returns:
- the text data with trailing spaces preserved (not removed).
-
getData
Returns the text data of thisNetServerMessagewith trailing spaces removed (right trimmed).- Returns:
- the text data with trailing spaces removed (right trimmed).
-
setData
Changes the text data of thisNetServerMessage.- Parameters:
data- the new text data of thisNetServerMessage.
-
getDataBytes
public byte[] getDataBytes()Returns the binary data of thisNetServerMessage.- Returns:
- the binary data of this
NetServerMessage.
-
setDataBytes
public void setDataBytes(byte[] bytes) Changes the binary data of thisNetServerMessage.- Parameters:
bytes- the new binary data of thisNetServerMessage.
-
copyFrom
Copies all the properties of source into thisNetServerMessage. The values of all properties in thisNetServerMessageare replaced by copies of the values of corresponding source properties.- Parameters:
source- the sourceNetServerMessageto be copied.- Throws:
NullPointerException- ifsourceisnull.
-
clone
Returns a "deep" copy of thisNetServerMessage.- Overrides:
clonein classLayoutMessage- Returns:
- a "deep" copy of this
NetServerMessage.
-
toString
Returns a string representation of thisNetServerMessage.- Overrides:
toStringin classLayoutMessage- Returns:
- a string representation of this
NetServerMessage.
-
serialize
public byte[] serialize()Returns a serialized version of thisNetServerMessage. This method has exactly the same effect as callingserialize(false).- Returns:
- a serialized version of this
NetServerMessage.
-
serialize
public byte[] serialize(boolean withType) Returns a serialized version of thisNetServerMessagewith optional type code. SeeNetServerMessagefor a detailed explanation of how aNetServerMessageis serialized.- Parameters:
withType- iftruethe result includes the message type.- Returns:
- a serialized version of this
NetServerMessage.
-
unserialize
Creates a newNetServerMessageby unserializing the supplied byte array. This method has exactly the same effect as callingunserialize(bytes, offset, length, false).- Parameters:
bytes- array of bytes containing a serializedNetServerMessage.offset- initial offset of thebytessubarray.length- length of thebytessubarray.- Returns:
- a new
NetServerMessage.
-
unserialize
Creates a newNetServerMessageby unserializing the supplied byte array. SeeNetServerMessagefor a detailed explanation of how aNetServerMessageis serialized.- Parameters:
bytes- array of bytes containing a serializedNetServerMessage.offset- initial offset of thebytessubarray.length- length of thebytessubarray.withType- iftruebytesinclude the message type.- Returns:
- a new
NetServerMessage.
-