MessageParser.java 1.2 KB

12345678910111213141516171819202122232425262728
  1. package com.serotonin.cdc.messaging;
  2. import com.serotonin.cdc.util.queue.ByteQueue;
  3. /**
  4. * Interface defining methods that are called when data arrives in the connection.
  5. *
  6. * @author Matthew Lohbihler
  7. */
  8. public interface MessageParser {
  9. /**
  10. * Attempt to parse a message out of the queue. Data in the queue may be discarded if it is unusable (i.e. a start
  11. * indicator is not found), but otherwise if a message is not found due to the data being incomplete, the method
  12. * should return null. As additional data arrives, it will be appended to the queue and this method will be called
  13. * again.
  14. *
  15. * Implementations should not modify the queue unless it is safe to do so. No copy of the data is made before
  16. * calling this method.
  17. *
  18. * @param queue
  19. * the queue from which to access data for the creation of the message
  20. * @return the message if one was able to be created, or null otherwise.
  21. * @throws Exception
  22. * if the data in the queue is sufficient to construct a message, but the message data is invalid, this
  23. * method must throw an exception, or it will keep getting the same data.
  24. */
  25. IncomingMessage parseMessage(ByteQueue queue) throws Exception;
  26. }