-
Notifications
You must be signed in to change notification settings - Fork 1
Add GET endpoint for one-shot pv value reads #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3956571 to
1c24f6a
Compare
georgweiss
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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