Class GreedyMessageBuffer

java.lang.Object
com.jme3.network.base.protocol.GreedyMessageBuffer
All Implemented Interfaces:
MessageBuffer

public class GreedyMessageBuffer extends Object implements MessageBuffer
A MessageBuffer implementation that will aggressively create all messages as byte data comes in. In other words, if there are four messages in the ByteBuffer passed to addBuffer() then all of the messages will be deserialized during that call and queued up for later return. The downside is that, if any of those messages was going to alter the MessageProtocol serialization behavior in a way that affects later messages, then problems occur when those messages are all in one block.
Author:
Paul Speed
  • Constructor Details

    • GreedyMessageBuffer

      public GreedyMessageBuffer(MessageProtocol protocol)
      Creates a greedy message buffer for the specified protocol.
      Parameters:
      protocol - the protocol used to deserialize complete messages
  • Method Details

    • pollMessage

      public Message pollMessage()
      Returns the next message in the buffer or null if there are no more messages in the buffer.
      Specified by:
      pollMessage in interface MessageBuffer
      Returns:
      the next buffered message, or null if none are ready
    • hasMessages

      public boolean hasMessages()
      Returns true if there is a message waiting in the buffer.
      Specified by:
      hasMessages in interface MessageBuffer
      Returns:
      true if a message can be polled immediately
    • addBytes

      public boolean addBytes(ByteBuffer buffer)
      Adds byte data to the message buffer. Returns true if there is a message waiting after this call.
      Specified by:
      addBytes in interface MessageBuffer
      Parameters:
      buffer - the bytes to add
      Returns:
      true if a complete message is now available