swim
swim copied to clipboard
Multiple executions of callbacks on client downlinks
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.
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");
});