Event Service

The Event Service DSL is a Kotlin wrapper for the CSW Event Service. This DSL has the ability of publishing, getting, and subscribing to events, and also contains some helper methods for model creation. You can refer to the detailed documentation of Event Service provided by CSW here.

Helper Methods

These methods can be used to create System and Observe Events. Additionally, a System or Observe “Event Variable” can be created that can be tied to the first value of a parameter of an Event, similar to the way local variables are tied to “process variables” in the EPICS State Notation Language.

SystemEvent

Helper DSL to create a SystemEvent from the provided prefix, event name and parameters (optional).

Kotlin
sourceval parameters = intKey("stepNumber").set(1)

val systemEvent: SystemEvent = SystemEvent("ESW.IRIS_darkNight", "stepInfo", parameters)

ObserveEvent

Helper DSL to create an ObserveEvent using factory provided to create various sequencer observe events. sequencerObserveEvent object is available in the script scope.

Refer here to get the list of other Sequencer Events.

Kotlin
sourceval observeEvent: ObserveEvent = observationStart(ObsId("2020A-001-123"))

publishEvent

DSL to publish the given Event.

Kotlin
sourceval systemEvent: SystemEvent = SystemEvent("ESW.IRIS_darkNight", "stepInfo", parameters)
publishEvent(systemEvent)

This DSL can also publish events periodically when provided with the optional duration and an event generator function. In the below example, an Event with temperature Key will get published every 10 seconds, with current temperature value given by getTemperature method.

Kotlin
sourcepublishEvent(10.seconds) {
    val temperatureKey = intKey("temperature").set(getTemperature())
    SystemEvent("ESW.IRIS_darkNight", "temperature", temperatureKey)
}

onEvent

DSL to subscribe to events getting published on the given EventKey names. This DSL takes a callback as a lambda which operates on an event. The callback block will be invoked whenever an Event is published on any of the provided event keys.

Kotlin
sourceval tempEventKey = "IRIS.env.temperature.temp"
val stateEventKey = "IRIS.env.temperature.state"
onEvent(tempEventKey, stateEventKey) { event ->
    // logic to execute on every event
    println(event.eventKey())
}

This DSL has the ability to control the subscription rate by providing a duration with the callback. This operates like the Rate Adapter Mode for regular Event Service subscriptions.

Kotlin
sourceonEvent(tempEventKey, stateEventKey, duration = 2.seconds) { event ->
    // logic to execute on every event
    println(event.eventKey())
}

getEvent

DSL to get the latest Event published on each of the given EventKey names. There are two variations. One is for getting the latest event for single key, the other variation is to get the latest events against multiple keys.

Kotlin
sourceval tempEventKey = "IRIS.env.temperature.temp"
val stateEventKey = "IRIS.env.temperature.state"
val event = getEvent(tempEventKey) // for single event key

val events: Set<Event> = getEvent(tempEventKey, stateEventKey) // for single event key

Source code for examples