Package cl.obcom.desktopfx.netserver
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
Modifier and TypeClassDescriptionstatic interface
Defines the possible labels of aNetServerMessage
.static interface
Defines the operation codes of aNetServerMessage
.static interface
Defines the protection codes of aNetServerMessage
.static interface
Defines the reply codes of aNetServerMessage
.static interface
Defines the possible types of aNetServerMessage
. -
Constructor Summary
ConstructorDescriptionCreates a newNetServerMessage
instance with zero length data.NetServerMessage
(String data) Creates a newNetServerMessage
with the supplieddata
. -
Method Summary
Modifier and TypeMethodDescriptionclone()
Returns a "deep" copy of thisNetServerMessage
.final void
copyFrom
(NetServerMessage source) Copies all the properties of source into thisNetServerMessage
.final String
getData()
Returns the text data of thisNetServerMessage
with trailing spaces removed (right trimmed).final String
Returns the text data of thisNetServerMessage
with trailing spaces preserved (not removed).final byte[]
Returns the binary data of thisNetServerMessage
.final int
Returns the form code of thisNetServerMessage
.final String
getLabel
(int key) Returns the string value of the label identified bykey
.final String
Returns the multicast name of thisNetServerMessage
.final int
Returns the operation code of thisNetServerMessage
.final int
Returns the protection code of thisNetServerMessage
.final int
Returns the reply code of thisNetServerMessage
.final int
Returns the sequence of thisNetServerMessage
.final int
Returns the server code of thisNetServerMessage
.final int
Returns the session ID of thisNetServerMessage
.final int
Returns the transaction code of thisNetServerMessage
.final int
getType()
Returns the type of thisNetServerMessage
.final boolean
Returnstrue
if thisNetServerMessage
has data and no headers.final boolean
isLabelDefined
(int key) Returnstrue
if the label indexed by key is defined.final void
removeLabel
(int key) Removes the label identified bykey
from thisNetServerMessage
.final void
Removes all the labels defined in thisNetServerMessage
.final byte[]
Returns a serialized version of thisNetServerMessage
.final byte[]
serialize
(boolean withType) Returns a serialized version of thisNetServerMessage
with optional type code.final void
Changes the text data of thisNetServerMessage
.final void
setDataBytes
(byte[] bytes) Changes the binary data of thisNetServerMessage
.final void
setDataOnly
(boolean isDataOnly) Changes whether thisNetServerMessage
has data and no headers.final void
setFormCode
(int formCode) Changes the form code of thisNetServerMessage
.final void
Changes the string value of the label identified bykey
.final void
setOpCode
(int opcode) Changes the operation code of thisNetServerMessage
.final void
setProtCode
(int protCode) Changes the protection code of thisNetServerMessage
.final void
setReplyCode
(int replyCode) Changes the reply code of thisNetServerMessage
.final void
setSequence
(int sequence) Changes the sequence of thisNetServerMessage
.final void
setServerCode
(int serverCode) Changes the server code of thisNetServerMessage
.final void
setSessionID
(int sessionID) Changes the session ID of thisNetServerMessage
.final void
setTranCode
(int tranCode) Changes the transaction code of thisNetServerMessage
.final void
setType
(int type) Changes the type of thisNetServerMessage
.toString()
Returns a string representation of thisNetServerMessage
.static NetServerMessage
unserialize
(byte[] bytes, int offset, int length) Creates a newNetServerMessage
by unserializing the supplied byte array.static NetServerMessage
unserialize
(byte[] bytes, int offset, int length, boolean withType) Creates a newNetServerMessage
by unserializing the supplied byte array.Methods inherited from class cl.obcom.desktopfx.layout.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 newNetServerMessage
instance with zero length data. The message codes are set to default values, and no message labels are defined. -
NetServerMessage
Creates a newNetServerMessage
with 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 final int getType()Returns the type of thisNetServerMessage
.- Returns:
- the type of this
NetServerMessage
.
-
setType
public final void setType(int type) Changes the type of thisNetServerMessage
.- Parameters:
type
- the new type of thisNetServerMessage
.
-
getSequence
public final int getSequence()Returns the sequence of thisNetServerMessage
.- Returns:
- the sequence of this
NetServerMessage
.
-
setSequence
public final void setSequence(int sequence) Changes the sequence of thisNetServerMessage
.- Parameters:
sequence
- newNetServerMessage
sequence.
-
getOpCode
public final int getOpCode()Returns the operation code of thisNetServerMessage
.- Returns:
- the operation code of this
NetServerMessage
.
-
setOpCode
public final void setOpCode(int opcode) Changes the operation code of thisNetServerMessage
.- Parameters:
opcode
- newNetServerMessage
operation code.
-
getServerCode
public final int getServerCode()Returns the server code of thisNetServerMessage
.- Returns:
- the server code of this
NetServerMessage
.
-
setServerCode
public final void setServerCode(int serverCode) Changes the server code of thisNetServerMessage
.- Parameters:
serverCode
- newNetServerMessage
server code.
-
getSessionID
public final int getSessionID()Returns the session ID of thisNetServerMessage
.- Returns:
- the session ID of this
NetServerMessage
.
-
setSessionID
public final void setSessionID(int sessionID) Changes the session ID of thisNetServerMessage
.- Parameters:
sessionID
- newNetServerMessage
session ID.
-
getTranCode
public final int getTranCode()Returns the transaction code of thisNetServerMessage
.- Returns:
- the transaction code of this
NetServerMessage
.
-
setTranCode
public final void setTranCode(int tranCode) Changes the transaction code of thisNetServerMessage
.- Parameters:
tranCode
- newNetServerMessage
transaction code.
-
getReplyCode
public final int getReplyCode()Returns the reply code of thisNetServerMessage
.- Returns:
- the reply code of this
NetServerMessage
.
-
setReplyCode
public final void setReplyCode(int replyCode) Changes the reply code of thisNetServerMessage
.- Parameters:
replyCode
- newNetServerMessage
reply code.
-
getFormCode
public final int getFormCode()Returns the form code of thisNetServerMessage
.- Returns:
- the form code of this
NetServerMessage
.
-
setFormCode
public final void setFormCode(int formCode) Changes the form code of thisNetServerMessage
.- Parameters:
formCode
- newNetServerMessage
form code.
-
getProtCode
public final int getProtCode()Returns the protection code of thisNetServerMessage
.- Returns:
- the protection code of this
NetServerMessage
.
-
setProtCode
public final void setProtCode(int protCode) Changes the protection code of thisNetServerMessage
.- Parameters:
protCode
- newNetServerMessage
protection code.
-
removeLabels
public final void removeLabels()Removes all the labels defined in thisNetServerMessage
. -
isLabelDefined
public final boolean isLabelDefined(int key) Returnstrue
if the label indexed by key is defined.- Parameters:
key
- the index of the label (LABEL_XXXXX
).- Returns:
true
if the label indexed bykey
is 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 actuallynull
or if the label was undefined.- Parameters:
key
- the index of the label (LABEL_XXXXX
).- Returns:
- the string value of the required label.
- Throws:
IndexOutOfBoundsException
- ifkey
is out-of-range.
-
removeLabel
public final void removeLabel(int key) Removes the label identified bykey
from thisNetServerMessage
. Nothing happens if the label is not defined in thisNetServerMessage
.- Parameters:
key
- the index of the label (LABEL_XXXXX
).- Throws:
IndexOutOfBoundsException
- ifkey
is out-of-range.
-
setLabel
Changes the string value of the label identified bykey
. Setting the value of the label tonull
has the effect as removing the label from thisNetServerMessage
. That is, it has exactly the same effect as calling theremoveLabel
method with the samekey
.- Parameters:
key
- the index of the label (LABEL_XXXXX
).value
- new value of the label ornull
.- Throws:
IndexOutOfBoundsException
- ifkey
is 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 final boolean isDataOnly()Returnstrue
if thisNetServerMessage
has data and no headers.- Returns:
true
if thisNetServerMessage
has data and no headers.
-
setDataOnly
public final void setDataOnly(boolean isDataOnly) Changes whether thisNetServerMessage
has data and no headers.- Parameters:
isDataOnly
- the new value of the data only property.
-
getDataAll
Returns the text data of thisNetServerMessage
with trailing spaces preserved (not removed).- Returns:
- the text data with trailing spaces preserved (not removed).
-
getData
Returns the text data of thisNetServerMessage
with 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 final byte[] getDataBytes()Returns the binary data of thisNetServerMessage
.- Returns:
- the binary data of this
NetServerMessage
.
-
setDataBytes
public final 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 thisNetServerMessage
are replaced by copies of the values of corresponding source properties.- Parameters:
source
- the sourceNetServerMessage
to be copied.- Throws:
NullPointerException
- ifsource
isnull
.
-
clone
Returns a "deep" copy of thisNetServerMessage
.- Overrides:
clone
in classLayoutMessage
- Returns:
- a "deep" copy of this
NetServerMessage
.
-
toString
Returns a string representation of thisNetServerMessage
.- Overrides:
toString
in classLayoutMessage
- Returns:
- a string representation of this
NetServerMessage
.
-
serialize
public final 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 final byte[] serialize(boolean withType) Returns a serialized version of thisNetServerMessage
with optional type code. SeeNetServerMessage
for a detailed explanation of how aNetServerMessage
is serialized.- Parameters:
withType
- iftrue
the result includes the message type.- Returns:
- a serialized version of this
NetServerMessage
.
-
unserialize
Creates a newNetServerMessage
by 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 thebytes
subarray.length
- length of thebytes
subarray.- Returns:
- a new
NetServerMessage
.
-
unserialize
Creates a newNetServerMessage
by unserializing the supplied byte array. SeeNetServerMessage
for a detailed explanation of how aNetServerMessage
is serialized.- Parameters:
bytes
- array of bytes containing a serializedNetServerMessage
.offset
- initial offset of thebytes
subarray.length
- length of thebytes
subarray.withType
- iftrue
bytes
include the message type.- Returns:
- a new
NetServerMessage
.
-