Class MessageParserImpl

java.lang.Object
com.sun.corba.ee.impl.protocol.MessageParserImpl
All Implemented Interfaces:
MessageParser

public class MessageParserImpl extends Object implements MessageParser
An implementation of a MessageParser that knows how to parse bytes into a GIOP protocol data unit.
  • Field Details

    • NUM_BYTES_IN_INTEGER

      private static final int NUM_BYTES_IN_INTEGER
      See Also:
    • MESSAGE_LENGTH_INDEX

      private static final int MESSAGE_LENGTH_INDEX
      See Also:
    • MESSAGE_FLAG_INDEX

      private static final int MESSAGE_FLAG_INDEX
      See Also:
    • orb

      private final ORB orb
    • expectingMoreData

      private boolean expectingMoreData
    • moreBytesToParse

      private boolean moreBytesToParse
    • nextMsgStartPos

      private int nextMsgStartPos
    • sizeNeeded

      private int sizeNeeded
    • fragmentList

      private List<RequestId> fragmentList
      A list of request ids awaiting final fragments. When the size of this list is larger than 0, we have received a fragmented message and expecting to receive more message fragments for that given request id on this list. Hence, if there are entries in this list we are expecting more data to arrive. We are using a List here rather than a Set since the size of the List is expected to be rather small, (i.e. less than size 10).
    • msgByteBuffer

      private ByteBuffer msgByteBuffer
    • remainderBuffer

      private ByteBuffer remainderBuffer
      The buffer which will be returned for additional input.
    • messageMediator

      private MessageMediator messageMediator
      wrapped message create by the last call to offerBuffer.
    • connection

      private Connection connection
    • expectingFragments

      private boolean expectingFragments
  • Constructor Details

    • MessageParserImpl

      public MessageParserImpl(ORB orb)
      Creates a new instance of MessageParserImpl
      Parameters:
      orb - the ORB
    • MessageParserImpl

      public MessageParserImpl(ORB orb, Connection connection)
  • Method Details

    • getNewBufferAndCopyOld

      public ByteBuffer getNewBufferAndCopyOld(ByteBuffer byteBuffer)
      Specified by:
      getNewBufferAndCopyOld in interface MessageParser
    • isExpectingMoreData

      public boolean isExpectingMoreData()
      Is this MessageParser expecting more data ?
      Specified by:
      isExpectingMoreData in interface MessageParser
      Returns:
      - True if more bytes are needed to construct at least one GIOP protocol data unit. False, if no additional bytes are remain to be parsed into a GIOP protocol data unit.
    • isExpectingFragments

      public boolean isExpectingFragments()
      Specified by:
      isExpectingFragments in interface MessageParser
    • getMsgByteBuffer

      public ByteBuffer getMsgByteBuffer()
      Description copied from interface: MessageParser
      Returns the byte buffer (if any) associated with the last message returned.
      Specified by:
      getMsgByteBuffer in interface MessageParser
      Returns:
      the associated byte buffer
    • offerBuffer

      public void offerBuffer(ByteBuffer buffer)
      Description copied from interface: MessageParser
      Offers an input buffer to the parser. Position must be set to 0, and the buffer must contain at least the start of a GIOP message. The parser will consume what it can and make the remainder available in MessageParser.getRemainderBuffer()
      Specified by:
      offerBuffer in interface MessageParser
      Parameters:
      buffer - a buffer containing at least the start of a GIOP message.
    • splitAndReturnRemainder

      private ByteBuffer splitAndReturnRemainder(ByteBuffer buffer, int splitPosition)
      Splits the specified buffer at the specified position, returning the first part and setting remainderBuffer to the second, or null if there is no data in the second. The split position must be no greater than the limit.
    • containsFullHeader

      private boolean containsFullHeader(ByteBuffer buffer)
    • containsFullMessage

      private boolean containsFullMessage(ByteBuffer buffer)
    • getTotalMessageLength

      private int getTotalMessageLength(ByteBuffer buffer)
    • getMessageBodyLength

      private int getMessageBodyLength(ByteBuffer buffer)
    • getByteOrder

      private ByteOrder getByteOrder(byte messageFlag)
    • getRemainderBuffer

      public ByteBuffer getRemainderBuffer()
      Description copied from interface: MessageParser
      Returns a buffer containing whatever is left after processing the buffer provided in MessageParser.offerBuffer(ByteBuffer), which could be the same buffer. The buffer could also be null if all data has been consumed.
      Specified by:
      getRemainderBuffer in interface MessageParser
      Returns:
      a byte buffer representing data which still needs to be processed.
    • getMessageMediator

      public MessageMediator getMessageMediator()
      Description copied from interface: MessageParser
      Returns the full message constructed by the last call to MessageParser.offerBuffer(ByteBuffer). Will be null if the last such call did not complete a message.
      Specified by:
      getMessageMediator in interface MessageParser
      Returns:
      a complete message, wrapped in a message mediator.
    • checkTimeout

      public void checkTimeout(long timeSinceLastInput)
      Description copied from interface: MessageParser
      Checks for a stalled or rogue client. If in the middle of receiving a message and the time exceeds the limit, will throw a communications failure exception.
      Specified by:
      checkTimeout in interface MessageParser
      Parameters:
      timeSinceLastInput - the number of milliseconds since the last input was received.
    • timeLimitExceeded

      private boolean timeLimitExceeded(long timeSinceLastInput)
    • isMidMessage

      private boolean isMidMessage()
    • parseBytes

      public Message parseBytes(ByteBuffer byteBuffer, Connection connection)
      Description copied from interface: MessageParser
      If there are sufficient bytes in the ByteBuffer to compose a Message, then return a newly initialized Message. Otherwise, return null. When this method is first called, it is assumed that ByteBuffer.position() points to the location in the ByteBuffer where the beginning of the first Message begins. If there is no partial Message remaining in the ByteBuffer when this method exits, this method will e this.expectingMoreData to false. Otherwise, it will be set to true. Callees of this method may check isExpectingMoreData() subsequently to determine if this MessageParser is expecting more data to complete a protocol data unit. Callees may also subsequently check hasMoreBytesToParse() to determine if this MessageParser has more data to parse in the given ByteBuffer.
      Specified by:
      parseBytes in interface MessageParser
      Parameters:
      byteBuffer - Buffer to parse
      connection - connection for message
      Returns:
      Message if one is found in the ByteBuffer. Otherwise, returns null.
    • stillLookingForFragments

      private boolean stillLookingForFragments()
    • isEndOfFragmentList

      private boolean isEndOfFragmentList(Message message)
    • removeRequestIdFromFragmentList

      private void removeRequestIdFromFragmentList(Message message, ByteBuffer byteBuffer)
    • addRequestIdToFragmentList

      private void addRequestIdToFragmentList(Message message, ByteBuffer byteBuffer)
    • hasMoreBytesToParse

      public boolean hasMoreBytesToParse()
      Are there more bytes to be parsed in the ByteBuffer given to this MessageParser's parseBytes ? This method is typically called after a call to parseBytes() to determine if the ByteBuffer has more bytes which need to parsed into a Message.
      Specified by:
      hasMoreBytesToParse in interface MessageParser
      Returns:
      true if there are more bytes to be parsed. Otherwise false.
    • setNextMessageStartPosition

      public void setNextMessageStartPosition(int position)
      Set the starting position where the next message in the ByteBuffer given to parseBytes() begins.
      Specified by:
      setNextMessageStartPosition in interface MessageParser
      Parameters:
      position - the next starting position
    • getNextMessageStartPosition

      public int getNextMessageStartPosition()
      Get the starting position where the next message in the ByteBuffer given to parseBytes() begins.
      Specified by:
      getNextMessageStartPosition in interface MessageParser
      Returns:
      start position in the buffer of the next message
    • toString

      public String toString()
      Return a string representing this MessageParser's state
      Overrides:
      toString in class Object
    • toStringPrefix

      private String toStringPrefix()
      Return a common String prefix representing this MessageParser's state
    • getSizeNeeded

      public int getSizeNeeded()
      Return the suggested number of bytes needed to hold the next message to be parsed.
      Specified by:
      getSizeNeeded in interface MessageParser
      Returns:
      bytes needed to hold message