This is an automated email from the ASF dual-hosted git repository.

git-site-role pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/plc4x-website.git


The following commit(s) were added to refs/heads/asf-site by this push:
     new a3eee84  Site checkin for project PLC4X: Jenkins Tools
a3eee84 is described below

commit a3eee84ce8881e17cd983f845d0fdb05924c0bc5
Author: jenkins <[email protected]>
AuthorDate: Wed Feb 3 15:31:55 2021 +0000

    Site checkin for project PLC4X: Jenkins Tools
---
 dependency-management.html       | 28 +++++++++---
 plugin-management.html           |  2 +-
 plugins.html                     |  4 +-
 users/tools/connection-pool.html | 95 +++++++++++++++++++++++++++++++++++++---
 4 files changed, 116 insertions(+), 13 deletions(-)

diff --git a/dependency-management.html b/dependency-management.html
index 0afd409..676190b 100644
--- a/dependency-management.html
+++ b/dependency-management.html
@@ -286,7 +286,7 @@
 <tr class="b">
 <td>org.antlr</td>
 <td><a class="externalLink" 
href="http://www.antlr.org/antlr4-runtime";>antlr4-runtime</a></td>
-<td>4.9</td>
+<td>4.9.1</td>
 <td>jar</td>
 <td><a class="externalLink" href="http://www.antlr.org/license.html";>The BSD 
License</a></td></tr>
 <tr class="a">
@@ -392,6 +392,18 @@
 <td>jar</td>
 <td><a class="externalLink" 
href="http://www.apache.org/licenses/LICENSE-2.0.txt";>Apache License, Version 
2.0</a></td></tr>
 <tr class="b">
+<td>org.awaitility</td>
+<td><a class="externalLink" href="http://awaitility.org";>awaitility</a></td>
+<td>3.0.0</td>
+<td>jar</td>
+<td><a href="LICENSE.txt">Apache 2.0</a></td></tr>
+<tr class="a">
+<td>org.awaitility</td>
+<td><a class="externalLink" 
href="http://awaitility.org";>awaitility-proxy</a></td>
+<td>3.0.0</td>
+<td>jar</td>
+<td><a href="LICENSE.txt">Apache 2.0</a></td></tr>
+<tr class="b">
 <td>org.bouncycastle</td>
 <td><a class="externalLink" 
href="http://www.bouncycastle.org/java.html";>bcmail-jdk15on</a></td>
 <td>1.67</td>
@@ -530,30 +542,36 @@
 <td>jar</td>
 <td><a class="externalLink" 
href="https://github.com/mockito/mockito/blob/release/3.x/LICENSE";>The MIT 
License</a></td></tr>
 <tr class="a">
+<td>org.objenesis</td>
+<td><a class="externalLink" href="http://objenesis.org";>objenesis</a></td>
+<td>3.1</td>
+<td>jar</td>
+<td><a class="externalLink" 
href="http://www.apache.org/licenses/LICENSE-2.0.txt";>Apache License, Version 
2.0</a></td></tr>
+<tr class="b">
 <td>org.pcap4j</td>
 <td><a class="externalLink" 
href="https://github.com/kaitoy/pcap4j/pcap4j-packetfactory-static";>pcap4j-packetfactory-static</a></td>
 <td>1.8.2</td>
 <td>jar</td>
 <td><a class="externalLink" 
href="http://www.opensource.org/licenses/mit-license.php";>MIT 
License</a></td></tr>
-<tr class="b">
+<tr class="a">
 <td>org.slf4j</td>
 <td><a class="externalLink" 
href="http://www.slf4j.org";>log4j-over-slf4j</a></td>
 <td>1.7.30</td>
 <td>jar</td>
 <td><a class="externalLink" 
href="http://www.apache.org/licenses/LICENSE-2.0.txt";>Apache Software 
Licenses</a></td></tr>
-<tr class="a">
+<tr class="b">
 <td>org.slf4j</td>
 <td><a class="externalLink" href="http://www.slf4j.org";>slf4j-api</a></td>
 <td>1.7.30</td>
 <td>jar</td>
 <td><a class="externalLink" 
href="http://www.opensource.org/licenses/mit-license.php";>MIT 
License</a></td></tr>
-<tr class="b">
+<tr class="a">
 <td>org.slf4j</td>
 <td><a class="externalLink" href="http://www.slf4j.org";>slf4j-simple</a></td>
 <td>1.7.30</td>
 <td>jar</td>
 <td><a class="externalLink" 
href="http://www.opensource.org/licenses/mit-license.php";>MIT 
License</a></td></tr>
-<tr class="a">
+<tr class="b">
 <td>org.xmlunit</td>
 <td><a class="externalLink" 
href="https://www.xmlunit.org/";>xmlunit-core</a></td>
 <td>2.8.1</td>
diff --git a/plugin-management.html b/plugin-management.html
index 705f0ff..fc3d4de 100644
--- a/plugin-management.html
+++ b/plugin-management.html
@@ -138,7 +138,7 @@
 <tr class="a">
 <td>org.antlr</td>
 <td><a class="externalLink" 
href="http://www.antlr.org/antlr4-maven-plugin";>antlr4-maven-plugin</a></td>
-<td>4.9</td></tr>
+<td>4.9.1</td></tr>
 <tr class="b">
 <td>org.apache.felix</td>
 <td><a class="externalLink" 
href="http://felix.apache.org/components/bundle-plugin/";>maven-bundle-plugin</a></td>
diff --git a/plugins.html b/plugins.html
index c572092..8aaf395 100644
--- a/plugins.html
+++ b/plugins.html
@@ -133,8 +133,8 @@
 <td>2.8.2</td></tr>
 <tr class="b">
 <td>org.apache.maven.plugins</td>
-<td><a class="externalLink" 
href="http://maven.apache.org/enforcer/maven-enforcer-plugin";>maven-enforcer-plugin</a></td>
-<td>1.4.1</td></tr>
+<td><a class="externalLink" 
href="https://maven.apache.org/enforcer/maven-enforcer-plugin/";>maven-enforcer-plugin</a></td>
+<td>3.0.0-M3</td></tr>
 <tr class="a">
 <td>org.apache.maven.plugins</td>
 <td><a class="externalLink" 
href="https://maven.apache.org/surefire/maven-failsafe-plugin/";>maven-failsafe-plugin</a></td>
diff --git a/users/tools/connection-pool.html b/users/tools/connection-pool.html
index 43c3fe0..95d2f76 100644
--- a/users/tools/connection-pool.html
+++ b/users/tools/connection-pool.html
@@ -292,7 +292,7 @@
 <p>For example if you have a microservice application, you might have multiple 
services accessing PLC data.</p>
 </div>
 <div class="paragraph">
-<p>Keeping an open connection for each of these is rather problematic as in 
contrast to modern computers, PLCs usually are only able to manage a small 
number of concurrent conntections.</p>
+<p>Keeping an open connection for each of these is rather problematic as in 
contrast to modern computers, PLCs usually are only able to manage a small 
number of concurrent connections.</p>
 </div>
 <div class="paragraph">
 <p>I think a Siemens S7-1200 is limited to 7 concurrent connections and a 
Siemens LOGO can&#8217;t do more than 3.</p>
@@ -305,7 +305,7 @@ This however puts an unnecessary stress on the PLCs as for 
protocols like the S7
 <p>As usually these services only require ad-hoc access to a PLC, it would be 
ideal to share connections between services.</p>
 </div>
 <div class="paragraph">
-<p>Another problem occurs when you open a connection and keep it open for a 
prolonged timeperiod.
+<p>Another problem occurs when you open a connection and keep it open for a 
prolonged time period.
 Here it can happen quite often that a connection is terminated because the PLC 
has been turned off.</p>
 </div>
 <div class="paragraph">
@@ -332,7 +332,7 @@ Here it can happen quite often that a connection is 
terminated because the PLC h
 <p>The structure of the code is now more or less like if you would create a 
new connection for every request and close it afterwards.</p>
 </div>
 <div class="paragraph">
-<p>Another benefit of the <code>PooledPlcDriverManager</code> is that it will 
check a connection for any problems before retutning it to the client.</p>
+<p>Another benefit of the <code>PooledPlcDriverManager</code> is that it will 
check a connection for any problems before returning it to the client.</p>
 </div>
 <div class="paragraph">
 <p>So if a connection was terminated, it will detect this and create a new 
connection.</p>
@@ -345,7 +345,7 @@ Here it can happen quite often that a connection is 
terminated because the PLC h
 </div>
 <div class="listingblock">
 <div class="content">
-<pre>    PlcDriverManager driverManager = new PooledPlcDriverManager();
+<pre class="prettyprint highlight"><code data-lang="java">    PlcDriverManager 
driverManager = new PooledPlcDriverManager();
 
     // This just simulates a scenario where a lot of connections would be 
created and immediately destroyed again.
     for(int i = 0; i &lt; 100; i++) {
@@ -354,7 +354,7 @@ Here it can happen quite often that a connection is 
terminated because the PLC h
             ... do something ... (please refer to the PLC4J getting started 
for details)
 
         }
-    }</pre>
+    }</code></pre>
 </div>
 </div>
 <div class="admonitionblock note">
@@ -370,6 +370,91 @@ When sharing connections between multiple services, be 
sure to share the instanc
 </table>
 </div>
 </div>
+<div class="sect2">
+<h3 id="the_cacheddrivermanager">The CachedDriverManager</h3>
+<div class="paragraph">
+<p>There&#8217;s an another version of pool manager with similar target but 
different implementation.</p>
+</div>
+<div class="paragraph">
+<p>The idea behind this second pool driver is that a connection could be lost 
for a lot of external reason without the possibility to handle those from the 
plc4x point of view (e.g. the cable is unplugged in a reading session). In the 
Cached Pool Manager every connection could be used for only a limited period of 
time, at the end the connection is no more valid and must be returned to the 
poll.</p>
+</div>
+<div class="paragraph">
+<p>Even in the Cached Pool Manager, like before, getting a connection from the 
pool is effortless so the typical live cycle of a connection is:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code>Get a connection -&gt; use the 
connection -&gt; return the connection to the pool</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>In the Cached Pool Manager a watchdog will invalidate any open connection 
at the end of it&#8217;s live time even if no answer came back from the PLC; in 
this case the library could continue to talk to the PLC with some other 
connections fetched from the pool.</p>
+</div>
+<div class="paragraph">
+<p>Let explain this concept in more detail using the Cached Pool with a 
modified version of the previous example:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre class="prettyprint highlight"><code data-lang="java">    public static 
void main(String[] args) throws Exception {
+        String connectionString = "s7://192.168.1.192";
+            PlcDriverManager manager = new PlcDriverManager();
+            PlcDriverManager cached = new 
CachedDriverManager(connectionString,() -&gt; 
manager.getConnection(connectionString));
+            for (int i = 0; i &lt; 10000; i++) {
+                try {
+                    TimeUnit.MILLISECONDS.sleep(500);
+                    try (PlcConnection conn = 
cached.getConnection(connectionString)) {
+                        if (conn.isConnected()){
+                            PlcReadRequest.Builder builder = 
conn.readRequestBuilder();
+                            builder.addItem("PollingValue", "%DB1:4.0:BOOL");
+                            PlcReadRequest readRequest = builder.build();
+                            PlcReadResponse syncResponse = 
readRequest.execute().get(2000, TimeUnit.MILLISECONDS);
+                            printResponse(syncResponse);
+                        } else {
+                            logger.info("PLC is not connected, let's try again 
to connect");
+                            conn.connect();
+                        }
+                    }
+                } catch (PlcConnectionException e){
+                    logger.error("Connection exception in trying to connect", 
e);
+                } catch (CancellationException  e){
+                    logger.error("Polling Thread canceled", e);
+                } catch (IllegalStateException e){
+                    logger.error("Error in Netty state machine", e);
+                } catch (ExecutionException e){
+                    logger.error("Interrupted Exception fired", e);
+                } catch (TimeoutException e) {
+                    logger.error("Timeout exception fired", e);
+                }
+            }
+        System.exit(0);
+    }</code></pre>
+</div>
+</div>
+<div class="paragraph">
+<p>In this snippet of code there are some considerations that are worth to be 
underlined.</p>
+</div>
+<div class="ulist">
+<ul>
+<li>
+<p>The <code>try-with-resources</code> statement (i.e. <code>try 
(PlcConnection conn = cached.getConnection(connectionString))</code>) ensure 
that an open connection will be automatically closed and returned to the pool 
after the use. As said before if the connection get stuck for any reason, after 
a fixed amount of time will be killed by a software watchdog (i.e. the amount 
of time is now fixed to 5000 ms, will be configurable in the future);</p>
+</li>
+<li>
+<p>Check if the PLC is connected before reading some data is always advisable 
(i.e. <code>conn.isConnected()</code>) but this doesn&#8217;t mean that the PLC 
will be ready to answer to the connection, it means that the initial handshake 
went good and plc4x has the needed information to talk with the PLC;</p>
+</li>
+<li>
+<p>the use of <code>get()</code> must be done with a timeout (i.e. 
<code>readRequest.execute().get(2000, TimeUnit.MILLISECONDS)</code>). After the 
timeout amount of time a <code>TimeoutException</code> will be fired. In the 
code this is trapped and signaled with a simple line of log. This case could 
happen because the PLC for some reason could decide to not answer or the 
physical connection could have some problem;</p>
+</li>
+<li>
+<p>the <code>PlcConnectionException</code> is a connection error that could 
happen in the handshaking phase between the PLC4x library and the PLC. 
It&#8217;s a generic error;</p>
+</li>
+<li>
+<p>the <code>IllegalStateException</code> is a Netty library exception which 
could happen in some really troubled connection, mostly if a physical 
disconnection happen.</p>
+</li>
+</ul>
+</div>
+<div class="paragraph">
+<p>All the others exceptions (i.e. <code>ExecutionException</code> and 
<code>CancellationException</code>) are thread java related exceptions; in this 
example these are caught to show how plc4x could be used to handle all the 
external problems that could happen in talking to a PLC and could recover from 
them.</p>
+</div>
+</div>
 </div>
 </div>
         </main>

Reply via email to