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 773c577  Site checkin for project PLC4X: Jenkins Tools
773c577 is described below

commit 773c5773ac85b23ed7f18d332058e10719836687
Author: jenkins <[email protected]>
AuthorDate: Wed Jul 1 08:14:54 2020 +0000

    Site checkin for project PLC4X: Jenkins Tools
---
 users/tools/connection-pool.html | 84 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/users/tools/connection-pool.html b/users/tools/connection-pool.html
index 6cfcc89..cb5bbc2 100644
--- a/users/tools/connection-pool.html
+++ b/users/tools/connection-pool.html
@@ -268,7 +268,91 @@
             <div class="sect1">
 <h2 id="connection_pool">Connection Pool</h2>
 <div class="sectionbody">
+<div class="paragraph">
+<p>There are situations where you don&#8217;t want to carry around connections 
in your code.</p>
+</div>
+<div class="paragraph">
+<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>
+</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>
+</div>
+<div class="paragraph">
+<p>One alternative would be to open and close the connections all the time.
+This however puts an unnecessary stress on the PLCs as for protocols like the 
S7 or the ADS protocol a handshake of multiple requests and responses has to be 
executed before being able to communicate.</p>
+</div>
+<div class="paragraph">
+<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.
+Here it can happen quite often that a connection is terminated because the PLC 
has been turned off.</p>
+</div>
+<div class="paragraph">
+<p>Per default the PLC connection has no means of automatically 
re-connecting.</p>
+</div>
+<div class="paragraph">
+<p>The <code>PooledPlcDriverManager</code> can help you with both of these 
scenarios.</p>
+</div>
+<div class="sect2">
+<h3 id="the_pooledplcdrivermanager">The PooledPlcDriverManager</h3>
+<div class="paragraph">
+<p>The <code>PooledPlcDriverManager</code> is a wrapper around the normal 
<code>PlcDriverManager</code>.</p>
+</div>
+<div class="paragraph">
+<p>The main difference is that as soon as a connection is requested, it will 
look if one already exists and return that.</p>
+</div>
+<div class="paragraph">
+<p>If no connection exists it will create a new one and keep it in the 
pool.</p>
+</div>
+<div class="paragraph">
+<p>There are no API differences from using the normal 
<code>PlcDriverManager</code> so you call <code>createConnection</code> and 
<code>close</code> just like with the normal PLC4X API.</p>
+</div>
+<div class="paragraph">
+<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>
+</div>
+<div class="paragraph">
+<p>So if a connection was terminated, it will detect this and create a new 
connection.</p>
+</div>
+</div>
+<div class="sect2">
+<h3 id="example">Example</h3>
+<div class="paragraph">
+<p>Here comes a little example program utilizing the 
<code>PooledPlcDriverManager</code>:</p>
+</div>
+<div class="listingblock">
+<div class="content">
+<pre>    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++) {
+        try(PlcConnection connection = driverManager.getConnection("...")) {
 
+            ... do something ... (please refer to the PLC4J getting started 
for details)
+
+        }
+    }</pre>
+</div>
+</div>
+<div class="admonitionblock note">
+<table>
+<tr>
+<td class="icon">
+<i class="fa icon-note" title="Note"></i>
+</td>
+<td class="content">
+When sharing connections between multiple services, be sure to share the 
instance of the <code>PooledPldDriverManager</code> as otherwise you will 
result in having multiple pools.
+</td>
+</tr>
+</table>
+</div>
+</div>
 </div>
 </div>
         </main>

Reply via email to