You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/groovy/how-to-guides/table-listeners-groovy.md
+67-63Lines changed: 67 additions & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,12 +50,15 @@ A [`MergedListener`](/core/javadoc/io/deephaven/engine/table/impl/MergedListener
50
50
-`listenerDescription`: A String description of the listener.
51
51
-`result`: a result table that uses the listener's tables as sources. Can be null.
52
52
53
-
The following example listens to two time tables, one ticking every two seconds and the other ticking every three seconds. [`getUpdate`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/impl/ListenerRecorder.html#getUpdate()) returns a [`TableUpdate`](/core/javadoc/io/deephaven/engine/table/TableUpdate.html) object for each [`ListenerRecorder`](/core/javadoc/io/deephaven/engine/table/impl/ListenerRecorder.html), and the [`MergedListener`](/core/javadoc/io/deephaven/engine/table/impl/MergedListener.html)'s `process` function is overwritten to print updates if they have been received and to do nothing otherwise.
53
+
The following example listens to two time tables, one ticking every second and the other ticking every two seconds. [`getUpdate`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/impl/ListenerRecorder.html#getUpdate()) returns a [`TableUpdate`](/core/javadoc/io/deephaven/engine/table/TableUpdate.html) object for each [`ListenerRecorder`](/core/javadoc/io/deephaven/engine/table/impl/ListenerRecorder.html), and the [`MergedListener`](/core/javadoc/io/deephaven/engine/table/impl/MergedListener.html)'s `process` function is overwritten to print updates if they have been received and to do nothing otherwise.

113
116
114
117
> [!IMPORTANT]
115
-
> `updates` contains `null` values for any table that has not changed during the update cycle. These `null` values must be handled to avoid raising errors.
118
+
> The `TableUpdate` returned by `getUpdate()` is `null` for any table that has not changed during the update cycle. These `null` values must be handled to avoid raising errors.
116
119
117
120
## Access table data
118
121
@@ -124,34 +127,35 @@ The following methods return a RowSet of the added, removed, or modified data:
124
127
-[`added`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/TableUpdate.html#added()) - rows added during the current update cycle.
125
128
-[`modified`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/TableUpdate.html#modified()) - rows modified during the current update cycle.
126
129
-[`removed`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/TableUpdate.html#removed()) - rows removed during the current update cycle.
127
-
-[`getModifiedPreShift`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/TableUpdate.html#getModifiedPreShift()) - rows modified during the previous update cycle.
130
+
-[`getModifiedPreShift`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/TableUpdate.html#getModifiedPreShift()) - modified rows in their pre-shift row key positions (before any shifts were applied during this update cycle).
128
131
129
132
The following example listens to added rows during each update cycle. It prints the data as the listener receives it.
Use a try-catch block within the `onUpdate` call to define and handle errors when using table listeners.
256
+
If a listener encounters an error, it should throw an exception rather than catching and suppressing it. When a listener throws an exception:
257
+
258
+
- In a **Persistent Query**, the exception crashes the query — which is the correct behavior, as it alerts you that something is wrong.
259
+
- In a **Code Studio**, the error appears in the logs.
252
260
253
-
Consider an example where a listener raises an error if it receives a value greater than 10. A try-catch block prints a message about the error to the console.
261
+
The following example throws a `RuntimeException`if it receives a value greater than 9. The exception propagates and causes the listener to fail, which is the expected behavior for a broken listener.
254
262
255
263
```groovy ticking-table order=null reset
256
264
import io.deephaven.engine.table.TableUpdate
@@ -267,25 +275,21 @@ listener = new InstrumentedTableUpdateListenerAdapter("listener", source, false)
267
275
268
276
@Override
269
277
void onUpdate(TableUpdate upstream) {
270
-
try {
271
-
def added = upstream.added()
272
-
273
-
if (added == null || added.isEmpty()) {
274
-
return
275
-
}
276
-
if (added.any{element -> element > 9}) {
277
-
throw new Exception("Number exceeds 9")
278
-
}
279
-
} catch (Exception e) {
280
-
println "${e}"
278
+
def added = upstream.added()
279
+
280
+
if (added == null || added.isEmpty()) {
281
+
return
282
+
}
283
+
if (added.any{element -> element > 9}) {
284
+
throw new RuntimeException("Value exceeds 9")
281
285
}
282
286
}
283
287
}
284
288
285
289
source.addUpdateListener(listener)
286
290
```
287
291
288
-

292
+

289
293
290
294
## Reduce data volumes
291
295
@@ -322,7 +326,7 @@ A table listener can listen to data that existed before the listener was registe
322
326
323
327
To make a listener listen to previously existing data, set the `replayInitialImage` parameter to `true` when calling [`addUpdateListener`](https://deephaven.io/core/javadoc/io/deephaven/engine/table/impl/TableAdapter.html#addUpdateListener(io.deephaven.engine.table.ShiftObliviousListener,boolean)).
324
328
325
-
The following example registers two listeners with a time table a few seconds after it's created. Only the one that sets `replayInitialImage` to `True` receives data when it's first registered.
329
+
The following example registers two listeners with a time table a few seconds after it's created. Only the one that sets `replayInitialImage` to `true` receives data when it's first registered.

355
+

0 commit comments