Package com.sun.corba.ee.spi.protocol
Interface MessageParser
- All Known Implementing Classes:
MessageParserImpl
public interface MessageParser
An interface that knows how to parse bytes into a protocol data unit.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
checkTimeout
(long timeSinceLastInput) Checks for a stalled or rogue client.Returns the full message constructed by the last call toofferBuffer(ByteBuffer)
.Returns the byte buffer (if any) associated with the last message returned.getNewBufferAndCopyOld
(ByteBuffer byteBuffer) int
Get the starting position where the next message in theByteBuffer
given toparseBytes()
begins.Returns a buffer containing whatever is left after processing the buffer provided inofferBuffer(ByteBuffer)
, which could be the same buffer.int
Return the suggested number of bytes needed to hold the next message to be parsed.boolean
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
.boolean
boolean
Is this MessageParser expecting more data ? This method is typically called after a call toparseBytes()
to determine if theByteBuffer
which has been parsed contains a partialMessage
.void
offerBuffer
(ByteBuffer buffer) Offers an input buffer to the parser.parseBytes
(ByteBuffer byteBuffer, Connection connection) If there are sufficient bytes in theByteBuffer
to compose aMessage
, then return a newly initializedMessage
.void
setNextMessageStartPosition
(int position) Set the starting position where the next message in theByteBuffer
given toparseBytes()
begins.
-
Method Details
-
getNewBufferAndCopyOld
-
isExpectingMoreData
boolean isExpectingMoreData()Is this MessageParser expecting more data ? This method is typically called after a call toparseBytes()
to determine if theByteBuffer
which has been parsed contains a partialMessage
.- Returns:
- -
true
if more bytes are needed to construct aMessage
.false
, if no additional bytes remain to be parsed into aMessage
.
-
parseBytes
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
.- Parameters:
byteBuffer
- Buffer to parseconnection
- connection for message- Returns:
Message
if one is found in theByteBuffer
. Otherwise, returns null.
-
hasMoreBytesToParse
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
.- Returns:
true
if there are more bytes to be parsed. Otherwisefalse
.
-
setNextMessageStartPosition
void setNextMessageStartPosition(int position) Set the starting position where the next message in theByteBuffer
given toparseBytes()
begins.- Parameters:
position
- the next starting position
-
getNextMessageStartPosition
int getNextMessageStartPosition()Get the starting position where the next message in theByteBuffer
given toparseBytes()
begins.- Returns:
- start position in the buffer of the next message
-
getSizeNeeded
int getSizeNeeded()Return the suggested number of bytes needed to hold the next message to be parsed.- Returns:
- bytes needed to hold message
-
getMsgByteBuffer
ByteBuffer getMsgByteBuffer()Returns the byte buffer (if any) associated with the last message returned.- Returns:
- the associated byte buffer
-
offerBuffer
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 ingetRemainderBuffer()
- Parameters:
buffer
- a buffer containing at least the start of a GIOP message.
-
getRemainderBuffer
ByteBuffer getRemainderBuffer()Returns a buffer containing whatever is left after processing the buffer provided inofferBuffer(ByteBuffer)
, which could be the same buffer. The buffer could also be null if all data has been consumed.- Returns:
- a byte buffer representing data which still needs to be processed.
-
getMessageMediator
MessageMediator getMessageMediator()Returns the full message constructed by the last call toofferBuffer(ByteBuffer)
. Will be null if the last such call did not complete a message.- Returns:
- a complete message, wrapped in a message mediator.
-
checkTimeout
void checkTimeout(long timeSinceLastInput) 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.- Parameters:
timeSinceLastInput
- the number of milliseconds since the last input was received.
-
isExpectingFragments
boolean isExpectingFragments()
-