@Override
public PlcReadRequest.Builder readRequestBuilder() {
    if(connection == null) {
        throw new PlcRuntimeException("Error using leased connection
after returning it to the cache.");
    }
    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 {

                                 *// Sometime request have some
problem maybe the connection died. *

*                    We must close the real connection.*
                            try {
                                destroy();

                                 *// In here auto re-connect?  I mean
lease a connection*
                            } catch (Exception e) {
                            }
                            responseFuture.completeExceptionally(throwable);
                        }
                        return null;
                    });
                    return responseFuture;
                }

                @Override
                public int getNumberOfTags() {
                    return innerPlcReadRequest.getNumberOfTags();
                }

                @Override
                public LinkedHashSet<String> getTagNames() {
                    return innerPlcReadRequest.getTagNames();
                }

                @Override
                public PlcTag getTag(String name) {
                    return innerPlcReadRequest.getTag(name);
                }

                @Override
                public List<PlcTag> getTags() {
                    return innerPlcReadRequest.getTags();
                }
            };
        }

        @Override
        public PlcReadRequest.Builder addTagAddress(String name,
String tagAddress) {
            return innerBuilder.addTagAddress(name, tagAddress);
        }

        @Override
        public PlcReadRequest.Builder addTag(String name, PlcTag tag) {
            return innerBuilder.addTag(name,tag);
        }
    };
}


youlin he <[email protected]> 于2023年2月22日周三 18:58写道:

> I have restored maxUserTime.
>
> Sometimes we must hold the connection for a long time. For example, in the
> loop retrieve PLC data.
>
> If request timeout the base drive will throw a timeoutException and
> cacheManage will close this real connection and set the isConnected of the
> leased connection as false.
> So we can determine whether the connection is closed in the loop and
> automatically connect if it is closed.
>
> If you can merge my New PR. We should remove maxUserTime again.
>
> Christofer Dutz <[email protected]> 于2023年2月22日周三 18:40写道:
>
>> Could you please summarize which changes these were exactly? Removing the
>> maxUserTime? Because if this is the case, we probably need to have a look
>> at how you are using the ConnectionCache.
>>
>> Chris
>>
>>
>> From: Unai Leria <[email protected]>
>> Date: Wednesday, 22. February 2023 at 10:34
>> To: dev <[email protected]>
>> Subject: Re: Issue with CachedPlcConnectionManager in nifi integration
>> For the nifi integration to work I did only use the changes on
>> plc4x/plc4j/tools/connection-cache from spnettec/plc4x/tree/heyoulin.
>> Plus some minor changes in the nifi integration to add a timeout to all
>> processors.
>>
>> Unai
>>
>> ----- Mensaje original -----
>> De: "youlin he" <[email protected]>
>> Para: "dev" <[email protected]>, "Christofer Dutz" <
>> [email protected]>
>> Enviados: Miércoles, 22 de Febrero 2023 10:21:51
>> Asunto: Re: Issue with CachedPlcConnectionManager in nifi integration
>>
>> But it should be based on driver base revision. Otherwise network
>> connection breaks would still happen.
>> @Christofer Dutz <[email protected]>
>>
>> youlin he <[email protected]> 于2023年2月22日周三 17:16写道:
>>
>> > Ok. I will create a PR
>> >
>> > Christofer Dutz <[email protected]> 于2023年2月22日周三 16:44写道:
>> >
>> >> Unfortunately, this is not a branch, but a fork … Would you be able to
>> >> pull the changes that made it work in a separate PR? Then we can more
>> >> quickly adopt the changes, because we definitely are not going to merge
>> >> that PR (At least I’m not going to do it)
>> >>
>> >> Chris
>> >>
>> >>
>> >> From: Unai Leria <[email protected]>
>> >> Date: Wednesday, 22. February 2023 at 09:28
>> >> To: dev <[email protected]>
>> >> Subject: Re: Issue with CachedPlcConnectionManager in nifi integration
>> >> It does work in the heyoulin branch. Thanks you.
>> >>
>> >> Unai
>> >>
>> >> ----- Mensaje original -----
>> >> De: "youlin he" <[email protected]>
>> >> Para: "dev" <[email protected]>
>> >> Enviados: Martes, 21 de Febrero 2023 14:54:14
>> >> Asunto: Re: Issue with CachedPlcConnectionManager in nifi integration
>> >>
>> >> I removed the maxUseTime. I think it is unnecessary to add
>> request-timeout
>> >> feature in the next version.
>> >>
>> >> youlin he <[email protected]> 于2023年2月21日周二 21:48写道:
>> >>
>> >> > Can you test use https://github.com/spnettec/plc4x  heyoulin
>> branch. I
>> >> > fixed this problem.
>> >> >
>> >> > Unai Leria <[email protected]> 于2023年2月21日周二 21:17写道:
>> >> >
>> >> >> Hi,
>> >> >>
>> >> >> I've been working with the CachedPlcConnectionManager on the NiFi
>> >> >> integration and I have encountered a problem while looking at issue
>> [
>> >> >> https://github.com/apache/plc4x/issues/623 | #623 ] :
>> >> >> When a successful connection is already stored in the cache and the
>> >> >> network connection breaks the connections in the cache are no longer
>> >> >> usable, but I have not been able to remove them.
>> >> >> This makes the processor not work until it is manually disabled and
>> >> >> enabled.
>> >> >>
>> >> >> For the NiFi integration to work properly there should be a way of
>> >> >> removing a connection from the cache if it is invalid.
>> >> >>
>> >> >> I would appreciate some guidance.
>> >> >>
>> >> >> Unai
>> >> >>
>> >> >
>> >>
>> >
>>
>

Reply via email to