Package com.sun.corba.ee.impl.protocol
Class MessageParserImpl
- java.lang.Object
-
- com.sun.corba.ee.impl.protocol.MessageParserImpl
-
- All Implemented Interfaces:
MessageParser
public class MessageParserImpl extends java.lang.Object implements MessageParser
An implementation of aMessageParser
that knows how to parse bytes into a GIOP protocol data unit.
-
-
Field Summary
Fields Modifier and Type Field Description private Connection
connection
private boolean
expectingFragments
private boolean
expectingMoreData
private java.util.List<RequestId>
fragmentList
A list of request ids awaiting final fragments.private static int
MESSAGE_FLAG_INDEX
private static int
MESSAGE_LENGTH_INDEX
private MessageMediator
messageMediator
wrapped message create by the last call to offerBuffer.private boolean
moreBytesToParse
private java.nio.ByteBuffer
msgByteBuffer
private int
nextMsgStartPos
private static int
NUM_BYTES_IN_INTEGER
private ORB
orb
private java.nio.ByteBuffer
remainderBuffer
The buffer which will be returned for additional input.private int
sizeNeeded
-
Constructor Summary
Constructors Constructor Description MessageParserImpl(ORB orb)
Creates a new instance of MessageParserImplMessageParserImpl(ORB orb, Connection connection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addRequestIdToFragmentList(Message message, java.nio.ByteBuffer byteBuffer)
void
checkTimeout(long timeSinceLastInput)
Checks for a stalled or rogue client.private boolean
containsFullHeader(java.nio.ByteBuffer buffer)
private boolean
containsFullMessage(java.nio.ByteBuffer buffer)
private java.nio.ByteOrder
getByteOrder(byte messageFlag)
private int
getMessageBodyLength(java.nio.ByteBuffer buffer)
MessageMediator
getMessageMediator()
Returns the full message constructed by the last call toMessageParser.offerBuffer(ByteBuffer)
.java.nio.ByteBuffer
getMsgByteBuffer()
Returns the byte buffer (if any) associated with the last message returned.java.nio.ByteBuffer
getNewBufferAndCopyOld(java.nio.ByteBuffer byteBuffer)
int
getNextMessageStartPosition()
Get the starting position where the next message in theByteBuffer
given toparseBytes()
begins.java.nio.ByteBuffer
getRemainderBuffer()
Returns a buffer containing whatever is left after processing the buffer provided inMessageParser.offerBuffer(ByteBuffer)
, which could be the same buffer.int
getSizeNeeded()
Return the suggested number of bytes needed to hold the next message to be parsed.private int
getTotalMessageLength(java.nio.ByteBuffer buffer)
boolean
hasMoreBytesToParse()
Are there more bytes to be parsed in theByteBuffer
given to this MessageParser'sparseBytes
? This method is typically called after a call toparseBytes()
to determine if theByteBuffer
has more bytes which need to parsed into aMessage
.private boolean
isEndOfFragmentList(Message message)
boolean
isExpectingFragments()
boolean
isExpectingMoreData()
Is this MessageParser expecting more data ?private boolean
isMidMessage()
void
offerBuffer(java.nio.ByteBuffer buffer)
Offers an input buffer to the parser.Message
parseBytes(java.nio.ByteBuffer byteBuffer, Connection connection)
If there are sufficient bytes in theByteBuffer
to compose aMessage
, then return a newly initializedMessage
.private void
removeRequestIdFromFragmentList(Message message, java.nio.ByteBuffer byteBuffer)
void
setNextMessageStartPosition(int position)
Set the starting position where the next message in theByteBuffer
given toparseBytes()
begins.private java.nio.ByteBuffer
splitAndReturnRemainder(java.nio.ByteBuffer buffer, int splitPosition)
Splits the specified buffer at the specified position, returning the first part and settingremainderBuffer
to the second, or null if there is no data in the second.private boolean
stillLookingForFragments()
private boolean
timeLimitExceeded(long timeSinceLastInput)
java.lang.String
toString()
Return a string representing this MessageParser's stateprivate java.lang.String
toStringPrefix()
Return a common String prefix representing this MessageParser's state
-
-
-
Field Detail
-
NUM_BYTES_IN_INTEGER
private static final int NUM_BYTES_IN_INTEGER
- See Also:
- Constant Field Values
-
MESSAGE_LENGTH_INDEX
private static final int MESSAGE_LENGTH_INDEX
- See Also:
- Constant Field Values
-
MESSAGE_FLAG_INDEX
private static final int MESSAGE_FLAG_INDEX
- See Also:
- Constant Field Values
-
orb
private final ORB orb
-
expectingMoreData
private boolean expectingMoreData
-
moreBytesToParse
private boolean moreBytesToParse
-
nextMsgStartPos
private int nextMsgStartPos
-
sizeNeeded
private int sizeNeeded
-
fragmentList
private java.util.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 java.nio.ByteBuffer msgByteBuffer
-
remainderBuffer
private java.nio.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 Detail
-
MessageParserImpl
public MessageParserImpl(ORB orb)
Creates a new instance of MessageParserImpl- Parameters:
orb
- the ORB
-
MessageParserImpl
public MessageParserImpl(ORB orb, Connection connection)
-
-
Method Detail
-
getNewBufferAndCopyOld
public java.nio.ByteBuffer getNewBufferAndCopyOld(java.nio.ByteBuffer byteBuffer)
- Specified by:
getNewBufferAndCopyOld
in interfaceMessageParser
-
isExpectingMoreData
public boolean isExpectingMoreData()
Is this MessageParser expecting more data ?- Specified by:
isExpectingMoreData
in interfaceMessageParser
- 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 interfaceMessageParser
-
getMsgByteBuffer
public java.nio.ByteBuffer getMsgByteBuffer()
Description copied from interface:MessageParser
Returns the byte buffer (if any) associated with the last message returned.- Specified by:
getMsgByteBuffer
in interfaceMessageParser
- Returns:
- the associated byte buffer
-
offerBuffer
public void offerBuffer(java.nio.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 inMessageParser.getRemainderBuffer()
- Specified by:
offerBuffer
in interfaceMessageParser
- Parameters:
buffer
- a buffer containing at least the start of a GIOP message.
-
splitAndReturnRemainder
private java.nio.ByteBuffer splitAndReturnRemainder(java.nio.ByteBuffer buffer, int splitPosition)
Splits the specified buffer at the specified position, returning the first part and settingremainderBuffer
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(java.nio.ByteBuffer buffer)
-
containsFullMessage
private boolean containsFullMessage(java.nio.ByteBuffer buffer)
-
getTotalMessageLength
private int getTotalMessageLength(java.nio.ByteBuffer buffer)
-
getMessageBodyLength
private int getMessageBodyLength(java.nio.ByteBuffer buffer)
-
getByteOrder
private java.nio.ByteOrder getByteOrder(byte messageFlag)
-
getRemainderBuffer
public java.nio.ByteBuffer getRemainderBuffer()
Description copied from interface:MessageParser
Returns a buffer containing whatever is left after processing the buffer provided inMessageParser.offerBuffer(ByteBuffer)
, which could be the same buffer. The buffer could also be null if all data has been consumed.- Specified by:
getRemainderBuffer
in interfaceMessageParser
- 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 toMessageParser.offerBuffer(ByteBuffer)
. Will be null if the last such call did not complete a message.- Specified by:
getMessageMediator
in interfaceMessageParser
- 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 interfaceMessageParser
- 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(java.nio.ByteBuffer byteBuffer, Connection connection)
Description copied from interface:MessageParser
If there are sufficient bytes in theByteBuffer
to compose aMessage
, then return a newly initializedMessage
. Otherwise, return null. When this method is first called, it is assumed thatByteBuffer.position()
points to the location in theByteBuffer
where the beginning of the firstMessage
begins. If there is no partialMessage
remaining in theByteBuffer
when this method exits, this method will ethis.expectingMoreData
tofalse
. Otherwise, it will be set totrue
. Callees of this method may checkisExpectingMoreData()
subsequently to determine if thisMessageParser
is expecting more data to complete a protocol data unit. Callees may also subsequently checkhasMoreBytesToParse()
to determine if thisMessageParser
has more data to parse in the givenByteBuffer
.- Specified by:
parseBytes
in interfaceMessageParser
- Parameters:
byteBuffer
- Buffer to parseconnection
- connection for message- Returns:
Message
if one is found in theByteBuffer
. Otherwise, returns null.
-
stillLookingForFragments
private boolean stillLookingForFragments()
-
isEndOfFragmentList
private boolean isEndOfFragmentList(Message message)
-
removeRequestIdFromFragmentList
private void removeRequestIdFromFragmentList(Message message, java.nio.ByteBuffer byteBuffer)
-
addRequestIdToFragmentList
private void addRequestIdToFragmentList(Message message, java.nio.ByteBuffer byteBuffer)
-
hasMoreBytesToParse
public boolean hasMoreBytesToParse()
Are there more bytes to be parsed in theByteBuffer
given to this MessageParser'sparseBytes
? This method is typically called after a call toparseBytes()
to determine if theByteBuffer
has more bytes which need to parsed into aMessage
.- Specified by:
hasMoreBytesToParse
in interfaceMessageParser
- Returns:
true
if there are more bytes to be parsed. Otherwisefalse
.
-
setNextMessageStartPosition
public void setNextMessageStartPosition(int position)
Set the starting position where the next message in theByteBuffer
given toparseBytes()
begins.- Specified by:
setNextMessageStartPosition
in interfaceMessageParser
- Parameters:
position
- the next starting position
-
getNextMessageStartPosition
public int getNextMessageStartPosition()
Get the starting position where the next message in theByteBuffer
given toparseBytes()
begins.- Specified by:
getNextMessageStartPosition
in interfaceMessageParser
- Returns:
- start position in the buffer of the next message
-
toString
public java.lang.String toString()
Return a string representing this MessageParser's state- Overrides:
toString
in classjava.lang.Object
-
toStringPrefix
private java.lang.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 interfaceMessageParser
- Returns:
- bytes needed to hold message
-
-