swim icon indicating copy to clipboard operation
swim copied to clipboard

Multiple executions of callbacks on client downlinks

Open DobromirM opened this issue 3 years ago • 1 comments

The callbacks of downlinks opened using the swim client are being executed multiple times.

Tested with a map downlink with didUpdate callback and a value downlink with a didSet callback.

DobromirM avatar Oct 01 '21 15:10 DobromirM

This is expected behavior. These multiple executions are due to the client reconnecting (this is due to an idle connection). So it resyncs and gets the data back. If the connection is not idle, i.e if there are messages in transit then this won't happen. You can confirm by logging the didConnect callbacks. Also the way to work around it is to do the following:

    final MapDownlink<Uri, Uri> downlink = downlinkMap()
        .keyForm(Uri.form())
        .valueForm(Uri.form())
        .hostUri(hostUri)
        .nodeUri(nodeUri())
        .laneUri(laneUri)
        .keepSynced(true);
    downlink.open()
        .didConnect(() -> {
          info(nodeUri() + ": Did connect to host:" + hostUri + ", node: " + nodeUri() + ", lane: " + laneUri);
        })
        .didSync(() -> {
          downlink.keepSynced(false);
        })
        .didUpdate((key, newValue, oldValue) -> {
          info(nodeUri() + ": Did update");
        });

ajay-gov avatar Oct 01 '21 15:10 ajay-gov