Class AbstractSimpleCodec

All Implemented Interfaces:
HostSide, TransportSide

public abstract class AbstractSimpleCodec extends AbstractCodec
Base class that allows simplified implementation of codec plug-ins. Handles batches of messages and ignoring null payload messages (by default). Plug-in authors will typically extend this class, providing a valid constructor, and an implementation of the transformMessageTowardsHost(Message) and transformMessageTowardsTransport(Message) methods.

Subclasses should provide a constructor with the same signature as AbstractSimpleCodec(org.slf4j.Logger, PluginConstructorParameters.CodecConstructorParameters).

  • Constructor Details

    • AbstractSimpleCodec

      public AbstractSimpleCodec(org.slf4j.Logger logger, PluginConstructorParameters.CodecConstructorParameters params) throws IllegalArgumentException, Exception
      Constructor. A subclass should provide its own constructor with the same signature as this one. This base class makes the parameters passed into its constructor available as member fields or methods for use by the subclass.
      Parameters:
      logger - a slf4j Logger object which can be used to log to the host log file.
      params - an extensible interface providing access to the configuration for this plug-in and other capabilities.
      Throws:
      IllegalArgumentException - should be thrown from a plug-in's constructor if the configuration is invalid.
      Exception - can be thrown to indicate an internal error.
      Since:
      9.12.0.1
  • Method Details

    • sendBatchTowardsTransport

      public void sendBatchTowardsTransport(List<Message> messages)
      Transform a batch of messages and pass them on to the next plug-in synchronously. For each message passed in, calls transformMessageTowardsTransport(Message) or transformNullPayloadTowardsTransport(Message) (if the payload was null). On an exception, calls handleException(Exception, Message, boolean). Any non-null results are then sent in a batch by calling the next plug-in in this thread.
    • sendBatchTowardsHost

      public void sendBatchTowardsHost(List<Message> messages)
      Transform a batch of messages and pass them on to the next plug-in synchronously. For each message passed in, calls transformMessageTowardsHost(Message) or transformNullPayloadTowardsHost(Message) (if the payload was null).On an exception, calls handleException(Exception, Message, boolean). Any non-null results are then sent in a batch by calling the next plug-in in this thread.
    • transformMessageTowardsHost

      public abstract Message transformMessageTowardsHost(Message message) throws Exception
      Transform an individual message with a non-null payload. Decode an individual message, optionally producing a result. If this method throws then the exception will be logged and the message dropped.
      Parameters:
      message - - the message, guaranteed to be non-null and have a non-null payload.
      Returns:
      the decoded message, or null if it is to be discarded.
      Throws:
      Exception
      See Also:
    • transformMessageTowardsTransport

      public abstract Message transformMessageTowardsTransport(Message message) throws Exception
      Transform an individual message with a non-null payload. Encode an individual message, optionally producing a result. If this method throws then the exception will be logged and the message dropped.
      Parameters:
      message - - the message, guaranteed to be non-null and have a non-null payload.
      Returns:
      the encoded message, or null if it is to be discarded.
      Throws:
      Exception
      See Also:
    • transformNullPayloadTowardsHost

      public Message transformNullPayloadTowardsHost(Message message) throws Exception
      Transform an individual message that has a null payload.

      By convention, most plug-ins silently pass through messages with null payloads without transforming them. Thus, the default implementation of this method is to just return the value passed in. If this method throws then the exception will be logged and the message dropped.

      Throws:
      Exception
    • transformNullPayloadTowardsTransport

      public Message transformNullPayloadTowardsTransport(Message message) throws Exception
      Transform an individual message that has a null payload.

      By convention, most plug-ins silently pass through messages with null payloads without transforming them. Thus, the default implementation of this method is to just return the value passed in. If this method throws then the exception will be logged and the message dropped.

      Throws:
      Exception
    • handleException

      public Message handleException(Exception ex, Message message, boolean towardsTransport)
      Handle an exception thrown from transforming messages.

      The default implementation is to log an error and return null (thus discarding this message, but not others in the same batch)

      Parameters:
      e - T