Class NetServerMessage

java.lang.Object
cl.obcom.desktopfx.layout.LayoutMessage
cl.obcom.desktopfx.netserver.NetServerMessage
All Implemented Interfaces:
Serializable, Cloneable

public class NetServerMessage extends LayoutMessage
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:
  • Constructor Details

    • NetServerMessage

      public NetServerMessage()
      Creates a new NetServerMessage instance with zero length data. The message codes are set to default values, and no message labels are defined.
    • NetServerMessage

      public NetServerMessage(String data)
      Creates a new NetServerMessage with the supplied data. The codes of the new message are set to default values, and no message labels are defined.
      Parameters:
      data - the initial data of the NetServerMessage.
  • Method Details

    • getType

      public final int getType()
      Returns the type of this NetServerMessage.
      Returns:
      the type of this NetServerMessage.
    • setType

      public final void setType(int type)
      Changes the type of this NetServerMessage.
      Parameters:
      type - the new type of this NetServerMessage.
    • getSequence

      public final int getSequence()
      Returns the sequence of this NetServerMessage.
      Returns:
      the sequence of this NetServerMessage.
    • setSequence

      public final void setSequence(int sequence)
      Changes the sequence of this NetServerMessage.
      Parameters:
      sequence - new NetServerMessage sequence.
    • getOpCode

      public final int getOpCode()
      Returns the operation code of this NetServerMessage.
      Returns:
      the operation code of this NetServerMessage.
    • setOpCode

      public final void setOpCode(int opcode)
      Changes the operation code of this NetServerMessage.
      Parameters:
      opcode - new NetServerMessage operation code.
    • getServerCode

      public final int getServerCode()
      Returns the server code of this NetServerMessage.
      Returns:
      the server code of this NetServerMessage.
    • setServerCode

      public final void setServerCode(int serverCode)
      Changes the server code of this NetServerMessage.
      Parameters:
      serverCode - new NetServerMessage server code.
    • getSessionID

      public final int getSessionID()
      Returns the session ID of this NetServerMessage.
      Returns:
      the session ID of this NetServerMessage.
    • setSessionID

      public final void setSessionID(int sessionID)
      Changes the session ID of this NetServerMessage.
      Parameters:
      sessionID - new NetServerMessage session ID.
    • getTranCode

      public final int getTranCode()
      Returns the transaction code of this NetServerMessage.
      Returns:
      the transaction code of this NetServerMessage.
    • setTranCode

      public final void setTranCode(int tranCode)
      Changes the transaction code of this NetServerMessage.
      Parameters:
      tranCode - new NetServerMessage transaction code.
    • getReplyCode

      public final int getReplyCode()
      Returns the reply code of this NetServerMessage.
      Returns:
      the reply code of this NetServerMessage.
    • setReplyCode

      public final void setReplyCode(int replyCode)
      Changes the reply code of this NetServerMessage.
      Parameters:
      replyCode - new NetServerMessage reply code.
    • getFormCode

      public final int getFormCode()
      Returns the form code of this NetServerMessage.
      Returns:
      the form code of this NetServerMessage.
    • setFormCode

      public final void setFormCode(int formCode)
      Changes the form code of this NetServerMessage.
      Parameters:
      formCode - new NetServerMessage form code.
    • getProtCode

      public final int getProtCode()
      Returns the protection code of this NetServerMessage.
      Returns:
      the protection code of this NetServerMessage.
    • setProtCode

      public final void setProtCode(int protCode)
      Changes the protection code of this NetServerMessage.
      Parameters:
      protCode - new NetServerMessage protection code.
    • removeLabels

      public final void removeLabels()
      Removes all the labels defined in this NetServerMessage.
    • isLabelDefined

      public final boolean isLabelDefined(int key)
      Returns true if the label indexed by key is defined.
      Parameters:
      key - the index of the label (LABEL_XXXXX).
      Returns:
      true if the label indexed by key is defined.
    • getLabel

      public final String getLabel(int key)
      Returns the string value of the label identified by key. If the required label is not defined, it returns null. There is not way to know if the value of a label is actually null 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 - if key is out-of-range.
    • removeLabel

      public final void removeLabel(int key)
      Removes the label identified by key from this NetServerMessage. Nothing happens if the label is not defined in this NetServerMessage.
      Parameters:
      key - the index of the label (LABEL_XXXXX).
      Throws:
      IndexOutOfBoundsException - if key is out-of-range.
    • setLabel

      public final void setLabel(int key, String value)
      Changes the string value of the label identified by key. Setting the value of the label to null has the effect as removing the label from this NetServerMessage. That is, it has exactly the same effect as calling the removeLabel method with the same key.
      Parameters:
      key - the index of the label (LABEL_XXXXX).
      value - new value of the label or null.
      Throws:
      IndexOutOfBoundsException - if key is out-of-range.
    • getMulticatName

      public final String getMulticatName()
      Returns the multicast name of this NetServerMessage. If this is not a multicast message, it returnes null.
      Returns:
      the multicast name of this message or null.
    • isDataOnly

      public final boolean isDataOnly()
      Returns true if this NetServerMessage has data and no headers.
      Returns:
      true if this NetServerMessage has data and no headers.
    • setDataOnly

      public final void setDataOnly(boolean isDataOnly)
      Changes whether this NetServerMessage has data and no headers.
      Parameters:
      isDataOnly - the new value of the data only property.
    • getDataAll

      public final String getDataAll()
      Returns the text data of this NetServerMessage with trailing spaces preserved (not removed).
      Returns:
      the text data with trailing spaces preserved (not removed).
    • getData

      public final String getData()
      Returns the text data of this NetServerMessage with trailing spaces removed (right trimmed).
      Returns:
      the text data with trailing spaces removed (right trimmed).
    • setData

      public final void setData(String data)
      Changes the text data of this NetServerMessage.
      Parameters:
      data - the new text data of this NetServerMessage.
    • getDataBytes

      public final byte[] getDataBytes()
      Returns the binary data of this NetServerMessage.
      Returns:
      the binary data of this NetServerMessage.
    • setDataBytes

      public final void setDataBytes(byte[] bytes)
      Changes the binary data of this NetServerMessage.
      Parameters:
      bytes - the new binary data of this NetServerMessage.
    • copyFrom

      public final void copyFrom(NetServerMessage source)
      Copies all the properties of source into this NetServerMessage. The values of all properties in this NetServerMessage are replaced by copies of the values of corresponding source properties.
      Parameters:
      source - the source NetServerMessage to be copied.
      Throws:
      NullPointerException - if source is null.
    • clone

      public NetServerMessage clone()
      Returns a "deep" copy of this NetServerMessage.
      Overrides:
      clone in class LayoutMessage
      Returns:
      a "deep" copy of this NetServerMessage.
    • toString

      public String toString()
      Returns a string representation of this NetServerMessage.
      Overrides:
      toString in class LayoutMessage
      Returns:
      a string representation of this NetServerMessage.
    • serialize

      public final byte[] serialize()
      Returns a serialized version of this NetServerMessage. This method has exactly the same effect as calling serialize(false).
      Returns:
      a serialized version of this NetServerMessage.
    • serialize

      public final byte[] serialize(boolean withType)
      Returns a serialized version of this NetServerMessage with optional type code. See NetServerMessage for a detailed explanation of how a NetServerMessage is serialized.
      Parameters:
      withType - if true the result includes the message type.
      Returns:
      a serialized version of this NetServerMessage.
    • unserialize

      public static NetServerMessage unserialize(byte[] bytes, int offset, int length)
      Creates a new NetServerMessage by unserializing the supplied byte array. This method has exactly the same effect as calling unserialize(bytes, offset, length, false).
      Parameters:
      bytes - array of bytes containing a serialized NetServerMessage.
      offset - initial offset of the bytes subarray.
      length - length of the bytes subarray.
      Returns:
      a new NetServerMessage.
    • unserialize

      public static NetServerMessage unserialize(byte[] bytes, int offset, int length, boolean withType)
      Creates a new NetServerMessage by unserializing the supplied byte array. See NetServerMessage for a detailed explanation of how a NetServerMessage is serialized.
      Parameters:
      bytes - array of bytes containing a serialized NetServerMessage.
      offset - initial offset of the bytes subarray.
      length - length of the bytes subarray.
      withType - if true bytes include the message type.
      Returns:
      a new NetServerMessage.