Apama 10.7.2 | Connecting Apama Applications to External Components | Working with IAF Plug-ins | Java Codec Plug-in Development | The codec plug-in development specification for Java | Communication with other layers | Sending upstream messages received from the Semantic Mapper to a transport plug-in
 
Sending upstream messages received from the Semantic Mapper to a transport plug-in
When the Semantic Mapper produces normalized events, it sends them on to the codec layer by calling the codec plug-ins' sendNormalisedEvent methods (as defined above). The event codec must then encode the normalized event for transmission by the transport layer.
In order to send messages upstream to an event transport, a codec plug-in must have a reference to the transport plug-in object. Typically, an event codec does this by building up a map of registered transport plug-ins from the parameters passed to the addEventTransport and removeEventTransport methods. It might then use a property provided in the configuration file (for example, <property name="transportName" value="MyTransport"/>) to determine which event transport to use when the sendNormalisedEvent method is called.
Alternatively, if this transport plug-in will only ever be used in an adapter with just one codec plug-in, the EventTransport object could be stored in an instance field when it is provided to the addEventTransport method.
Once the plug-in has a reference to the event transport (or transports) it will use, it can pass on normalized events it has encoded into transport messages by calling the transport plug-in sendTransportEvent method. See the EventTransport interface in the API Reference for Java (Javadoc) for more information on this method.
For example, the implementation of the event codec's sendNormalisedEvent could look something like this:
// Select EventTransport using saved plug-in property value
EventTransport transport = eventTransports.get(currentTransportName);
// Encode message
MyCustomMessageType message = myEncodeMessage(event);
// Send to Transport layer plug-in
transport.sendTransportEvent(message, timestamps);
If an error occurs in the transport layer, a TransportException is thrown. Typically such exceptions do not need to be caught by the codec plug-in, unless the codec plug-in is able to somehow deal with the problem.
A CodecException should be thrown if there is an error encoding the normalized event.
Note that there are no guarantees about which threads might call the sendNormalisedEvent method, so plug-in authors will need to consider any thread synchronization issues arising from use of shared data structures.
Any transport plug-in called by a Java codec plug-in must also be written in Java.