Add GET endpoint for one-shot pv value reads#9
Add GET endpoint for one-shot pv value reads#9georgweiss merged 4 commits intoControlSystemStudio:masterfrom
Conversation
3956571 to
1c24f6a
Compare
georgweiss
left a comment
There was a problem hiding this comment.
Thanks for the PR.
Some remarks...
Retrying a read read operation is not the preferred pattern. Instead you could consider something like
CountDownLatch countDownLatch = new CountDownLatch(1);
AtomicReference<VType> value = new AtomicReference<>(null);
try {
PV pv = PVPool.getPV(name);
pv.onValueEvent().subscribe(vtype -> {
if (!VTypeHelper.isDisconnected(vtype)) {
value.set(pv.read());
}
countDownLatch.countDown();
});
countDownLatch.await(5000, TimeUnit.MILLISECONDS);
PVPool.releasePV(pv);
if(value.get() == null){
return null;
}
return Vtype2Json.toJson(name, value.get(), null, true, true);
} catch (Exception e) {
// Do something sensible here to avoid HTTP 500 status
}
The above connects to the PV and reads the value when connected. If the PV is offline - or does not exist - the code waits at most 5000 ms and then proceeds.
Also, returning a non-JSON formatted string forces the client to inspect the response. So returning null (=empty body) may be the preferred option.
Thanks - will implement. I wasn't sure if retrying was the best approach, seemed messy! |
|
ok - all done I think @georgweiss - let me know what you think |
Closes #8