chrisdutz commented on code in PR #818:
URL: https://github.com/apache/plc4x/pull/818#discussion_r1114444171


##########
plc4j/tools/connection-cache/src/main/java/org/apache/plc4x/java/utils/cache/CachedPlcConnectionManager.java:
##########
@@ -58,21 +58,33 @@ public CachedPlcConnectionManager(PlcConnectionManager 
connectionManager, Durati
         this.connectionContainers = new HashMap<>();
     }
 
+    @Override
     public PlcConnection getConnection(String url) throws 
PlcConnectionException {
+        return getConnection(url,null);
+    }
+
+    @Override
+    public PlcConnection getConnection(String url, PlcAuthentication 
authentication) throws PlcConnectionException {
         ConnectionContainer connectionContainer;
         synchronized (connectionContainers) {
             connectionContainer = connectionContainers.get(url);
-            if (connectionContainers.get(url) == null) {
+            if (connectionContainer == null || connectionContainer.isClosed()) 
{
                 LOG.debug("Creating new connection");
 
                 // Establish the real connection to the plc
-                PlcConnection connection = 
connectionManager.getConnection(url);
-
-                // Crate a connection container to manage handling this 
connection
-                connectionContainer = new ConnectionContainer(connection, 
maxLeaseTime);
+                PlcConnection connection;
+                if(authentication!=null) {
+                    connection = 
connectionManager.getConnection(url,authentication);
+                } else{
+                    connection = connectionManager.getConnection(url);
+                }
+                connectionContainer = new 
ConnectionContainer(connection,maxLeaseTime);
                 connectionContainers.put(url, connectionContainer);
             } else {
                 LOG.debug("Reusing exising connection");
+                if(connectionContainer.getRawConnection()!=null && 
!connectionContainer.getRawConnection().isConnected()){

Review Comment:
   Also admittedly ... I'm not 100% sure if all drivers safely allow 
reconnecting if they were somehow disconnected.



-- 
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: dev-unsubscr...@plc4x.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to