Class AbstractSimpleCodec
- java.lang.Object
-
- com.softwareag.connectivity.ConnectivityPlugin
-
- com.softwareag.connectivity.AbstractCodec
-
- com.softwareag.connectivity.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 thetransformMessageTowardsHost(Message)
andtransformMessageTowardsTransport(Message)
methods.Subclasses should provide a constructor with the same signature as
AbstractSimpleCodec(org.slf4j.Logger, PluginConstructorParameters.CodecConstructorParameters)
.
-
-
Field Summary
-
Fields inherited from class com.softwareag.connectivity.AbstractCodec
hostSide, transportSide
-
Fields inherited from class com.softwareag.connectivity.ConnectivityPlugin
chainId, config, CONNECTIVITY_API_VERSION, host, logger, pluginName
-
-
Constructor Summary
Constructors Constructor Description AbstractSimpleCodec(org.slf4j.Logger logger, PluginConstructorParameters.CodecConstructorParameters params)
Constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Message
handleException(java.lang.Exception ex, Message message, boolean towardsTransport)
Handle an exception thrown from transforming messages.void
sendBatchTowardsHost(java.util.List<Message> messages)
Transform a batch of messages and pass them on to the next plug-in synchronously.void
sendBatchTowardsTransport(java.util.List<Message> messages)
Transform a batch of messages and pass them on to the next plug-in synchronously.abstract Message
transformMessageTowardsHost(Message message)
Transform an individual message with a non-null payload.abstract Message
transformMessageTowardsTransport(Message message)
Transform an individual message with a non-null payload.Message
transformNullPayloadTowardsHost(Message message)
Transform an individual message that has a null payload.Message
transformNullPayloadTowardsTransport(Message message)
Transform an individual message that has a null payload.-
Methods inherited from class com.softwareag.connectivity.AbstractCodec
hostReady, setNextTowardsHost, setNextTowardsTransport, shutdown, start, toString
-
Methods inherited from class com.softwareag.connectivity.ConnectivityPlugin
getStatusReporter
-
-
-
-
Constructor Detail
-
AbstractSimpleCodec
public AbstractSimpleCodec(org.slf4j.Logger logger, PluginConstructorParameters.CodecConstructorParameters params) throws java.lang.IllegalArgumentException, java.lang.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:
java.lang.IllegalArgumentException
- should be thrown from a plug-in's constructor if the configuration is invalid.java.lang.Exception
- can be thrown to indicate an internal error.- Since:
- 9.12.0.1
-
-
Method Detail
-
sendBatchTowardsTransport
public void sendBatchTowardsTransport(java.util.List<Message> messages)
Transform a batch of messages and pass them on to the next plug-in synchronously. For each message passed in, callstransformMessageTowardsTransport(Message)
ortransformNullPayloadTowardsTransport(Message)
(if the payload was null). On an exception, callshandleException(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(java.util.List<Message> messages)
Transform a batch of messages and pass them on to the next plug-in synchronously. For each message passed in, callstransformMessageTowardsHost(Message)
ortransformNullPayloadTowardsHost(Message)
(if the payload was null).On an exception, callshandleException(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 java.lang.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:
java.lang.Exception
- See Also:
transformNullPayloadTowardsHost(Message)
-
transformMessageTowardsTransport
public abstract Message transformMessageTowardsTransport(Message message) throws java.lang.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:
java.lang.Exception
- See Also:
transformNullPayloadTowardsTransport(Message)
-
transformNullPayloadTowardsHost
public Message transformNullPayloadTowardsHost(Message message) throws java.lang.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:
java.lang.Exception
-
transformNullPayloadTowardsTransport
public Message transformNullPayloadTowardsTransport(Message message) throws java.lang.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:
java.lang.Exception
-
handleException
public Message handleException(java.lang.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
-
-