Hi Stefano,

First of all, welcome on our list... We'll do our best to help you.

Have you tried using our connection pool? Cause this should handle the 
connection state if the connection is disturbed. Also the scraper is a tool for 
collecting data periodically. This in combination with the connection pool 
should be what you are looking for.

Please find the documentation to using both on our website.

Hope that helps,
Chris
________________________________
Von: Stefano Bossi <[email protected]>
Gesendet: Dienstag, 21. Juli 2020 15:56
An: Apache PLC4X <[email protected]>
Betreff: Connection died after disconnection


Dear forum,

I am trying to develop a simple poller for my S7 PLC ST_1200.
I need just a simple thread in java which read a value and report it, anyway 
this must be robust to any problem on the network.
I mean I would like to cope with these situation:

  *   PLC not responding;
  *   network issues;

The software should normally read a value from the plc in 200 ms and if 
something bad happen, wait for 5 second and retry to read in a normal way.

I wrote some code but when I found a problem.
This is my code:

    public void run() {
        ConfigurationDataProvider configurationDataProvider = 
ConfigurationDataProvider.getInstance();
        try {
            PlcConnection plcConnection = new 
Client().getClient(configurationDataProvider.getPlcConnectionString()).getPlcConnection();
            PlcReadRequest.Builder requestBuilder = 
plcConnection.readRequestBuilder();
            requestBuilder.addItem("pollingVariable", 
configurationDataProvider.getPlcPollingVariable());
            PlcReadRequest readRequest = requestBuilder.build();
            while (true){
                if (plcConnection.isConnected()){
                    try {
                        PlcReadResponse response = 
readRequest.execute().get(CONNECTION_TIME_OUT, TimeUnit.MILLISECONDS);
                        if (response != null ){
                            logger.debug("Polling variable: {}", 
response.getPlcValue("pollingVariable"));
                        } else {
                            logger.error("No response from PLC in reading 
polling variable");
                            break;
                        }
                    } catch (TimeoutException timeoutException){
                        logger.error("Time out Exception in polling PLC", 
timeoutException);
                        Thread.sleep(5000);
                    }
                    
Thread.sleep(configurationDataProvider.getPollingInterval());
                }
            }

        } catch (Exception e) {
            logger.error("Interrupted Exception", e);
        }
    }


When I try to disconnect the cable, netty comply with an internal error and my 
application dies without a way to recover.
Here are the logs:

[ERROR] 15:33:38.830 it.fox.plcreader.Poller.run() - Time out Exception in 
polling PLC
java.util.concurrent.TimeoutException: null
    at java.util.concurrent.CompletableFuture.timedGet(Unknown Source) ~[?:?]
    at java.util.concurrent.CompletableFuture.get(Unknown Source) ~[?:?]
    at it.fox.plcreader.Poller.run(Poller.java:34) [main/:?]
Poller.java:34
    at java.lang.Thread.run(Unknown Source) [?:?]
[ERROR] 15:33:49.333 it.fox.plcreader.Poller.run() - Time out Exception in 
polling PLC
java.util.concurrent.TimeoutException: null
    at java.util.concurrent.CompletableFuture.timedGet(Unknown Source) ~[?:?]
    at java.util.concurrent.CompletableFuture.get(Unknown Source) ~[?:?]
    at it.fox.plcreader.Poller.run(Poller.java:34) [main/:?]
Poller.java:34
    at java.lang.Thread.run(Unknown Source) [?:?]
[WARN ] 15:33:54.308 
io.netty.channel.DefaultChannelPipeline.onUnhandledInboundException() - An 
exceptionCaught() event was fired, and it reached at the tail of the pipeline. 
It usually means the last handler in the pipeline did not handle the exception.
java.io.IOException: Operation timed out
    at sun.nio.ch.SocketDispatcher.read0(Native Method) ~[?:?]
    at sun.nio.ch.SocketDispatcher.read(Unknown Source) ~[?:?]
    at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) ~[?:?]
    at sun.nio.ch.IOUtil.read(Unknown Source) ~[?:?]
    at sun.nio.ch.IOUtil.read(Unknown Source) ~[?:?]
    at sun.nio.ch.SocketChannelImpl.read(Unknown Source) ~[?:?]
    at io.netty.buffer.PooledByteBuf.setBytes(PooledByteBuf.java:253) 
~[netty-buffer-4.1.47.Final.jar:4.1.47.Final]
PooledByteBuf.java:253
    at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1133) 
~[netty-buffer-4.1.47.Final.jar:4.1.47.Final]
AbstractByteBuf.java:1133
    at 
io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:350)
 ~[netty-transport-4.1.47.Final.jar:4.1.47.Final]
NioSocketChannel.java:350
    at 
io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148)
 [netty-transport-4.1.47.Final.jar:4.1.47.Final]
AbstractNioByteChannel.java:148
    at 
io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:714) 
[netty-transport-4.1.47.Final.jar:4.1.47.Final]
NioEventLoop.java:714
    at 
io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:650)
 [netty-transport-4.1.47.Final.jar:4.1.47.Final]
NioEventLoop.java:650
    at 
io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:576) 
[netty-transport-4.1.47.Final.jar:4.1.47.Final]
NioEventLoop.java:576
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) 
[netty-transport-4.1.47.Final.jar:4.1.47.Final]
NioEventLoop.java:493
    at 
io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
 [netty-common-4.1.47.Final.jar:4.1.47.Final]
SingleThreadEventExecutor.java:989
    at 
io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) 
[netty-common-4.1.47.Final.jar:4.1.47.Final]
ThreadExecutorMap.java:74
    at 
io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
 [netty-common-4.1.47.Final.jar:4.1.47.Final]
FastThreadLocalRunnable.java:30
    at java.lang.Thread.run(Unknown Source) [?:?]


Googling I found this Stack 
Overflow<https://stackoverflow.com/questions/40370114/netty-an-exceptioncaught-event-was-fired-and-it-reached-at-the-tail-of-the>
 thread which seems to talk about this kind of error but is too far for my java 
knowledge.

How could I let my code to never stop retrying ?

Thanks for your wonderful work.

Regards,
Stefano

​

Reply via email to