Apama Documentation : Connecting Apama Applications to External Components : Developing Custom Adapters : 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 (e.g. <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:
/**
* Called by an event encoder to send an upstream message to the external
* transport.
*
* Ownership of the message is transferred to the transport when this
* function is called. It is assumed that the encoder and transport share
* the same definition of the content of the event, so that the transport
* can effectively interpret the event.
*
* @param event An object representing the event to be sent by the
* transport, in a format shared by the encoder and transport.
* @param timestamps A TimestampSet representing the timestamps attached to
* the event.
*
* @throws TransportException Thrown by the transport if any error occurs
* sending the message.
*/
public void sendTransportEvent(Object event, TimestampSet timestamps)
    throws TransportException;
For example, the implementation of the event codec's sendNormalisedEvent could look something like this:
// Select EventTransport using saved plugin property value
EventTransport transport = eventTransports.get(currentTransportName);
// Encode message
MyCustomMessageType message = myEncodeMessage(event);
// Send to Transport layer plugin
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.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback