## com.sun.grizzly
Interface ProtocolParser<T>

    public interface ProtocolParser<T>

An interface that knows how to parse bytes into a protocol data unit.

Author:
  Charlie Hunt

Field Summary
`static String` `MESSAGE` Holds the message returned from `getNextMessage` for use by downstream filters
`static String` `PARSER` Used to associate a particular parser with a connection

Method Summary
`T` `getNextMessage()` Get the next complete message from the buffer, which can then be processed by the next filter in the protocol chain.
`boolean` `hasMoreBytesToParse()` Are there more bytes to be parsed in the `ByteBuffer` given to this ProtocolParser's `setBuffer` ? 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.
`boolean` `hasNextMessage()` Indicates whether the buffer has a complete message that can be returned from `getNextMessage`.
`boolean` `isExpectingMoreData()` Is this ProtocolParser expecting more data ? This method is typically called after a call to `parseBytes()` to determine if the `ByteBuffer` which has been parsed contains a partial message
`boolean` `releaseBuffer()` No more parsing will be done on the buffer passed to `startBuffer.` Set up the buffer so that its position is the first byte that was not part of a full message, and its limit is the original limit of the buffer.
`void` `startBuffer(ByteBuffer bb)` Set the buffer to be parsed.

Field Detail

### PARSER

    static final String PARSER

  Used to associate a particular parser with a connection

  See Also:
    Constant Field Values

### MESSAGE

    static final String MESSAGE

  Holds the message returned from `getNextMessage` for use by downstream filters

  See Also:
    Constant Field Values

Method Detail

### isExpectingMoreData

    boolean isExpectingMoreData()

  Is this ProtocolParser expecting more data ? This method is typically called after a call to `parseBytes()` to determine if the `ByteBuffer` which has been parsed contains a partial message

  Returns:
    - `true` if more bytes are needed to construct a message; `false`, if no additional bytes remain to be parsed into a `T`. Note that if no partial message exists, this method should return false.

### hasMoreBytesToParse

    boolean hasMoreBytesToParse()

  Are there more bytes to be parsed in the `ByteBuffer` given to this ProtocolParser's `setBuffer` ? 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.

  Returns:
    `true` if there are more bytes to be parsed. Otherwise `false`.

### getNextMessage

    T getNextMessage()

  Get the next complete message from the buffer, which can then be processed by the next filter in the protocol chain. Because not all filters will understand protocol messages, this method should also set the position and limit of the buffer at the start and end boundaries of the message. Filters in the protocol chain can retrieve this message via context.getAttribute(MESSAGE)

  Returns:
    The next message in the buffer. If there isn't such a message, return `null.`

### hasNextMessage

    boolean hasNextMessage()

  Indicates whether the buffer has a complete message that can be returned from `getNextMessage`. Smart implementations of this will set up all the information so that an actual call to `getNextMessage` doesn't need to re-parse the data.

### startBuffer

    void startBuffer(ByteBuffer bb)

  Set the buffer to be parsed. This method should store the buffer and its state so that subsequent calls to `getNextMessage` will return distinct messages, and the buffer can be restored after parsing when the `releaseBuffer` method is called.

### releaseBuffer

    boolean releaseBuffer()

  No more parsing will be done on the buffer passed to `startBuffer.` Set up the buffer so that its position is the first byte that was not part of a full message, and its limit is the original limit of the buffer.

  Returns:
    -- true if the parser has saved some state (e.g. information data in the buffer that hasn't been returned in a full message); otherwise false. If this method returns true, the framework will make sure that the same parser is used to process the buffer after more data has been read.

Copyright © 2008 SUN Microsystems. All Rights Reserved.