Class NetServerMessage

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

public final 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 int getType()
      Returns the type of this NetServerMessage.
      Returns:
      the type of this NetServerMessage.
    • setType

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      public 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 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 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 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 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 boolean isDataOnly()
      Returns true if this NetServerMessage has data and no headers.
      Returns:
      true if this NetServerMessage has data and no headers.
    • setDataOnly

      public 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 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 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 void setData(String data)
      Changes the text data of this NetServerMessage.
      Parameters:
      data - the new text data of this NetServerMessage.
    • getDataBytes

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

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

      public 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 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 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.