Apama Documentation : Connecting Apama Applications to External Components : Working with IAF Plug-ins : Monitoring Adapter Status : Asynchronously notifying IAFStatusManager of connection changes
Asynchronously notifying IAFStatusManager of connection changes
 
Mapping AdapterConnectionClosed and AdapterConnectionOpened events
In addition to returning status information in response to a poll from the IAFStatusManager, an adapter may also send out events asynchronously when a connection is opened or closed.
This is done by creating and sending a NormalisedEvent object from the transport or codec to the semantic mapper. The NormalisedEvent object has special fields that allow for automatic mapping to an Apama event type — either AdapterConnectionOpened or AdapterConnectionClosed. The AdapterConnectionOpened and AdapterConnectionClosed events are then sent through the correlator to the IAFStatusManager.
The NormalisedEvent must have the following fields:
Field name
Field value
AdapterConnectionOpenEvent or AdapterConnectionClosedEvent
No value (empty string). This will either represent a connection opened or connection closed and be translated into AdapterConnectionOpened or AdapterConnectionClosed events respectively for the IAFStatusManager to consume.
codecName
Name of codec.
transportName
Name of transport.
connectionName
No value (empty string) if there is only one connection. If there is more than one connection, this should contain CONNECTION_<id> and one event should be sent for every connection the adapter is concerned with.
connectionGeneration
Connection generation identifier. This identifies a successful connection attempt with a connectionName. If the connection fails, then is successfully connected again, this should change. This is usually a number that is incremented.
This connection information should have a direct correlation to the connection information sent in the getStatus implementation. Note that if the transport deals with only a single connection at a time, the connectionName will be "" (the empty string) instead of CONNECTION, as it is in the getStatus implementation.
The following is an example in Java of sending a NormalisedEvent that provides status information.
protected void sendAdapterConnectionStatusChangeNotification(boolean open,
String reason, TimestampSet tss)
{
  if(decoder==null) return;
  NormalisedEvent ne=new NormalisedEvent();
  ne.add("codecName", codecName);
  ne.add("transportName", transportName);
  if(reason==null)
  {
    reason="";
  }
  if(open)
  {
    ne.add("AdapterConnectionOpenEvent", reason);
  }
  else
  {
    ne.add("AdapterConnectionClosedEvent", reason);
  }
  ne.add("connectionGeneration", String.valueOf(connGeneration));
  ne.add("connectionName", "");
  try
  {
    decoder.sendTransportEvent(ne, tss);
  }
  catch (CodecException e)
  {
    logger.error("Could not send message due to Codec error: ", e);
  }
  catch (SemanticMapperException e)
  {
    logger.error("Could not send message due to Semantic Mapper
        error: ", e);
  }
}
Note: When using these events, the (J)NullCodec must be used, unless you write a codec that handles these and passes them on to the correlator. For example, the XMLCodec by default will not forward these events to the semantic mapper. If you want to use the XMLCodec, you need to use the (J)NullCodec as the codec to send these particular events.
For more information on the implicit rules that the semantic mapper uses to automatically map the objects to AdapterConnectionOpened and AdapterConnectionClosed events, see Mapping AdapterConnectionClosed and AdapterConnectionOpened events.
Copyright © 2013-2017 Software AG, Darmstadt, Germany. (Innovation Release)

Product LogoContact Support   |   Community   |   Feedback