CORAL WIKI

WindowActor

The WindowActor is a Coral Actor that enables windowing of events based on count or time. The actor receives individual events but, depending on the settings, waits until a certain time or a certain number of events have been received and then emits a list of the received items.

Creating a WindowActor

The creation JSON of the WindowActor (see Coral Actor) has type: "window". The params value is a JSON with a single field:

field type   description
method String required The method of windowing to use, either “count” or “time”
number Int required The number of milliseconds (in the case of method == “time”) or number of events (in the case of method == “count”)
sliding Int not required The number of events a window should slide. For instance, when sliding == 1, the window moves 1 event every time an event has been received. In the case of method == “time”, sliding should be specified in milliseconds.

Creation example

{
  "data": {
    "type": "actors",
    "attributes": {
      "type": "window",
      "params": {
        "method": "count",
        "number": 3,
        "sliding": 1
      }
    }
  }
}

This will create a WindowActor that waits until it receives 3 JSON objects, then emits these 3. Then, if a new event comes in, it moves the window, as in the following example:

{
   "data": [
      { "name": "object1" },
      { "name": "object2" },
      { "name": "object3" }
   ]
}

Then, object4 comes in, and the WindowActor emits the following:

{
   "data": [
      { "name": "object2" },
      { "name": "object3" },
      { "name": "object4" }
   ]
}

Trigger

The WindowActor is triggered by any incoming JSON event. It does not care about the structure of the JSON objects received, they can even be all different.

Emit

When the right number of objects is collected, a list is emitted as in the example above. If method == “time”, the WindowActor waits that amount of time and then emits what it has collected, if anything.

State

The WindowActor returns its state as follows:

field type description
method String “count” or “time” as set in the constructor
number Int The number of objects or the number of seconds of the window.
sliding Array The amount of objects or the amount of milliseconds the window slides every time.

Collect

The WindowActor does not collect state from other actors.

Timer

The WindowActor does not provide timer actions.