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 Systerm 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 (see EPICS Sequencer Documentation for more information).

SystemEvent

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

Kotlin
val parameters = intKey("stepNumber").set(1)
val systemEvent: SystemEvent = SystemEvent("ESW.IRIS_darkNight", "stepInfo", parameters)

ObserveEvent

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

Kotlin
val parameters = intKey("stepNumber").set(1)
val observeEvent: ObserveEvent = ObserveEvent("ESW.IRIS_darkNight", "observationStarted")

SystemVar

Helper DSL to create an EventVariable corresponding to a parameter of a SystemEvent. This DSL needs the initial value of the parameter, the name of the EventKey, and the ParameterKey of the connected parameter. More details about SystemVars are provided in the FSM documentation

Kotlin
val locKey = intKey("current-location")
val systemVar: EventVariable<Int> = SystemVar(0, "IRIS.ifs.motor.position", locKey)

ObserveVar

Helper DSL to create an EventVariable corresponding to a parameter of an ObserveEvent. This DSL needs the initial value of the parameter, the name of the EventKey and the ParameterKey of the connected parameter. More details about ObserveVars are provided in the FSM documentation

Kotlin
val readNumberKey = intKey("readNumber")
val observeVar: EventVariable<Int> = ObserveVar(0, "IRIS.ifs.detector.readCompleted", readNumberKey)

publishEvent

DSL to publish the given Event.

Kotlin
val 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
publishEvent(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
val 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
onEvent(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.

Kotlin
val tempEventKey = "IRIS.env.temperature.temp"
val stateEventKey = "IRIS.env.temperature.state"
val events: Set<Event> = getEvent(tempEventKey, stateEventKey)

Source code for examples