Apama EPL Plug-ins

Contains classes used to define EPL plug-ins written in Python that run inside the Apama correlator.

EPL plug-ins must inherit from EPLPluginBase and have methods on them decorated with the EPLAction decorator to declare the EPL type of the methods.

There are also several classes defined to pass custom EPL types from EPL to Python.

Event

class apama.eplplugin.Event

Bases: tuple

Event is a class containing type and fields.

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable)

Make a new Event object from a sequence or iterable

_replace(**kwds)

Return a new Event object replacing specified fields with new values

property fields

A dictionary containing key-value pairs of field name and value.

property type

A string containing the fully-qualified name of this Event instance. For example: apama.tests.myEvent

Location

class apama.eplplugin.Location

Bases: tuple

Location class defines a position in Apama using 2 coordinates.

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable)

Make a new Location object from a sequence or iterable

_replace(**kwds)

Return a new Location object replacing specified fields with new values

property x1

Float defining the x position of the first coordinate pair.

property x2

Float defining the x position of the second coordinate pair.

property y1

Float defining the y position of the first coordinate pair.

property y2

Float defining the y position of the second coordinate pair.

Context

class apama.eplplugin.Context(name, contextId)[source]

Bases: object

Context class represents an Apama EPL context.

Parameters
  • name – The string name of the context.

  • contextId – The integer id of the context.

_getContextId()[source]

Get the id of this context.

Returns

The integer ID of this context.

getName()[source]

Retrieve the name of this context.

Returns

The string name of the context.

repr()[source]

Stringify this context.

Returns

A string representation of the contexts, containing the context name and ID.

str()[source]

Stringify the context.

Returns

A string representation of the context, containing the context name.

Channel

class apama.eplplugin.Channel

Bases: tuple

Channel class represents an Apama channel.

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable)

Make a new Channel object from a sequence or iterable

_replace(**kwds)

Return a new Channel object replacing specified fields with new values

property channel

A string representing the name for the channel.

property context

A context object for the channel.

Any

class apama.eplplugin.Any

Bases: tuple

Any class representing the any variant type in EPL.

_asdict()

Return a new OrderedDict which maps field names to their values.

classmethod _make(iterable)

Make a new Any object from a sequence or iterable

_replace(**kwds)

Return a new Any object replacing specified fields with new values

property type

String name of the EPL type contained in the any, may be None if empty. Uses EPL-format type names, for example: dictionary<string, sequence<integer> >

property value

Contents of the any. Will be of the equivalent Python type to the EPL type named in type, or None if empty.

Correlator

class apama.eplplugin.Correlator[source]

Bases: object

Contains static methods to interact with the correlator directly from an EPL plug-in, such as by sending events.

static getCurrentContext()[source]

Get the current context we are running in.

Returns

A Context object representing the current execution context, or None if called on a background thread.

static sendTo(destination, event, type=None)[source]

Send an event from Python to a destination within the correlator.

sendTo takes two or three arguments, but can only be invoked with positional arguments, not named arguments. For example:

Correlator.sendTo("channelname", "MyEvent(123, 456)")
Correlator.sendTo(Channel("channelname"), {"i":123, "j":456}, type="MyEvent")
Correlator.sentTo(Correlator.getCurrentContext(), Event("MyEvent", {"i":123, "j":456}))

This method may block if sending to a context with a full queue.

You may not call this method from the plugin module (static) code or from the plugin constructor.

Parameters
  • destination – Either a string representing a channel name, a Context object or a Channel object containing either a string channel name or a Context object. The event will be sent to the specified context, or any context subscribed to the specified channel. (required)

  • event – Either a string in Apama event string format; a dictionary of string field names to values (in which case type must be specified); an Event object. (required)

  • type (str) – The fully-qualified name of an EPL event type. (optional)

EPLPluginBase

class apama.eplplugin.EPLPluginBase(init)[source]

Bases: object

This is the base class which all Python EPL plug-in instances should inherit from, and therefore defines all the ways in which the plug-in can interact with the correlator.

Methods on a Python EPL plug-in class must be decorated with the EPLAction decorator in order to be exposed to EPL.

getConfig()[source]

Get the plug-in instance configuration.

Returns

A dictionary with string keys as specified in the configuration file for this plug-in instance.

getLogger()[source]

Get a reference to the system logger.

Returns

A logging.Logger object which can be used to log to the correlator log file.

EPLAction

apama.eplplugin.EPLAction(actionsig, actionname=None)[source]

EPLAction is the available decorator that can be set on a method to allow access to the method from EPL. For example:

@EPLAction("action<> returns string", actionname="eplaction")
Parameters
  • actionsig (str) – The EPL action signature used to access the decorated method. Uses the same syntax as declaring action variables, for example: action<integer> returns string.

  • actionname (str) – The action name to use in EPL to access the decorated method. Optional, defaults to the name of the method in Python.