Copilot commented on code in PR #2656:
URL: https://github.com/apache/plc4x/pull/2656#discussion_r3658848118


##########
plc4net/api/PlcDriverManager.cs:
##########
@@ -1,104 +1,84 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
 
 using System;
 using System.Collections.Generic;
-using System.Threading.Tasks;
 using org.apache.plc4net.api;
 using org.apache.plc4net.api.authentication;
 using org.apache.plc4net.exceptions;
 
 namespace org.apache.plc4net
 {
     /// <summary>
-    /// Manages connections to PLCs
+    /// Registry of PLC protocol drivers. A driver registers itself here;
+    /// connection requests are dispatched to the driver whose protocol code
+    /// matches the connection string scheme.
     /// </summary>
     public class PlcDriverManager
     {
-        /// <summary>
-        /// Singleton instance of the manager
-        /// </summary>
         private static PlcDriverManager _instance;

Review Comment:
   The singleton initialization is not thread-safe: concurrent calls to 
`Instance` can construct multiple `PlcDriverManager` instances and lose 
registrations. Use a thread-safe singleton pattern (e.g., `static readonly 
PlcDriverManager Instance = new PlcDriverManager();` or 
`Lazy<PlcDriverManager>`) to guarantee single instantiation.



##########
.github/workflows/dotnet-platform.yml:
##########
@@ -0,0 +1,120 @@
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#    https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+name: ".Net Platform Compatibility"
+
+on:
+  push:
+    branches: [ "develop", "plc4net" ]
+    paths:
+      - code-generation/**
+      - protocols/**
+      - plc4net**
+  pull_request:
+    branches: [ "develop", "plc4net" ]
+    paths:
+      - code-generation/**
+      - protocols/**
+      - plc4net**
+  workflow_dispatch:
+    inputs:
+      forceUpdates:
+        description: "Forces a snapshot update"
+        required: false
+        default: 'false'
+
+permissions:
+  contents: read
+
+env:
+  DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }}
+
+jobs:
+  test:
+    strategy:
+      matrix:
+        os: [ ubuntu-latest, macos-latest, windows-latest ]
+      fail-fast: false
+    runs-on: ${{ matrix.os }}
+    steps:
+      - uses: actions/checkout@v7
+
+      - name: Setup .Net
+        uses: actions/setup-dotnet@v5
+        with:
+          dotnet-version: '8.0.x'
+
+      - name: Setup Java
+        uses: actions/setup-java@v5
+        with:
+          distribution: 'adopt'
+          java-package: jdk
+          java-version: 21

Review Comment:
   The `setup-java` distribution value `adopt` has been deprecated in favor of 
maintained distributions (commonly `temurin`). To reduce CI fragility, switch 
to a currently supported distribution name that `actions/setup-java` documents.



##########
plc4net/api/PlcDriverManager.cs:
##########
@@ -1,104 +1,84 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
 
 using System;
 using System.Collections.Generic;
-using System.Threading.Tasks;
 using org.apache.plc4net.api;
 using org.apache.plc4net.api.authentication;
 using org.apache.plc4net.exceptions;
 
 namespace org.apache.plc4net
 {
     /// <summary>
-    /// Manages connections to PLCs
+    /// Registry of PLC protocol drivers. A driver registers itself here;
+    /// connection requests are dispatched to the driver whose protocol code
+    /// matches the connection string scheme.
     /// </summary>
     public class PlcDriverManager
     {
-        /// <summary>
-        /// Singleton instance of the manager
-        /// </summary>
         private static PlcDriverManager _instance;
 
-        /// <summary>
-        /// Get the singleton instance
-        /// </summary>
-        public static PlcDriverManager Instance => _instance ?? (_instance = 
new PlcDriverManager());
-
-        /// <summary>
-        /// Dictionary for the drivers
-        /// </summary>
-        private readonly Dictionary<string, IPlcDriver> _drivers;
+        // Protocol codes are matched case-insensitively, the same way
+        // DefaultTransportManager matches transport codes.
+        private readonly Dictionary<string, IPlcDriver> _drivers
+            = new Dictionary<string, 
IPlcDriver>(StringComparer.OrdinalIgnoreCase);
 
-        /// <summary>
-        /// Private constructor for the singleton driver manager.
-        /// </summary>
         private PlcDriverManager()
         {
-            _drivers = new Dictionary<string, IPlcDriver>();
-
-            /*
-             * TODO: Implement some mechanism to provide drivers -> MEF?
-             */
         }
 
-        /// <summary>
-        /// Get the connection to the a PLC identified by the URL
-        /// </summary>
-        /// <param name="url">URL including the schema to connect to the 
PLC</param>
-        /// <param name="authentication">Authentication to use</param>
-        /// <returns>Created PLC connection</returns>
-        public async Task<IPlcConnection> GetConnection(string url, 
IPlcAuthentication authentication)
+        public static PlcDriverManager Instance => _instance ?? (_instance = 
new PlcDriverManager());

Review Comment:
   The singleton initialization is not thread-safe: concurrent calls to 
`Instance` can construct multiple `PlcDriverManager` instances and lose 
registrations. Use a thread-safe singleton pattern (e.g., `static readonly 
PlcDriverManager Instance = new PlcDriverManager();` or 
`Lazy<PlcDriverManager>`) to guarantee single instantiation.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to