chrisdutz commented on code in PR #818:
URL: https://github.com/apache/plc4x/pull/818#discussion_r1115308098
##########
plc4j/tools/connection-cache/src/main/java/org/apache/plc4x/java/utils/cache/LeasedPlcConnection.java:
##########
@@ -92,15 +102,139 @@ public PlcReadRequest.Builder readRequestBuilder() {
if(connection == null) {
throw new PlcRuntimeException("Error using leased connection after
returning it to the cache.");
}
- return connection.readRequestBuilder();
+ final PlcReadRequest.Builder innerBuilder =
connection.readRequestBuilder();
+ return new PlcReadRequest.Builder(){
+
+ @Override
+ public PlcReadRequest build() {
+ final PlcReadRequest innerPlcReadRequest =
innerBuilder.build();
+ return new PlcReadRequest(){
+
+ @Override
+ public CompletableFuture<? extends PlcReadResponse>
execute() {
+ CompletableFuture<? extends PlcReadResponse> future =
innerPlcReadRequest.execute();
+ final CompletableFuture<PlcReadResponse>
responseFuture = new CompletableFuture<>();
+ future.handle((plcReadResponse, throwable) -> {
+ if (plcReadResponse != null) {
+ responseFuture.complete(plcReadResponse);
+ } else {
+ try {
+ destroy();
+ } catch (Exception e) {
+ }
+
responseFuture.completeExceptionally(throwable);
Review Comment:
So do I understand this block correctly? If anything goes wrong with the
request, it terminates the connection, right? Should we really be doing this? I
mean ... it's easy to ask for an invalid tag ... that doesn't really make it
necessary to reconnect? For example with my KNX gateway it only allows 3
connections in paralell and within a window of 2-3 minutes (when it closes
inactive connections) ... not 100% sure we should be doing this.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]