Skip to content

Commit 111e875

Browse files
authored
Add a new OpcUaClient.create overload (#1487)
Adds a new `OpcUaClient.create` overload that accepts an `OpcUaClientConfig` and a callback that can be used to configure an `OpcTcpClientTransportConfigBuilder`. fixes #1486
1 parent b48046e commit 111e875

File tree

1 file changed

+23
-2
lines changed
  • opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client

1 file changed

+23
-2
lines changed

opc-ua-sdk/sdk-client/src/main/java/org/eclipse/milo/opcua/sdk/client/OpcUaClient.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ public class OpcUaClient {
178178
* Create an {@link OpcUaClient} configured with {@code config}.
179179
*
180180
* @param config the {@link OpcUaClientConfig}.
181-
* @return an {@link OpcUaClient} configured with {@code config}.
182-
* @throws UaException if the client could not be created (e.g. transport/encoding not supported).
181+
* @return a new {@link OpcUaClient} configured with {@code config}.
182+
* @throws UaException if the client could not be created.
183183
*/
184184
public static OpcUaClient create(OpcUaClientConfig config) throws UaException {
185185
OpcTcpClientTransportConfig transportConfig = OpcTcpClientTransportConfig.newBuilder().build();
@@ -188,6 +188,27 @@ public static OpcUaClient create(OpcUaClientConfig config) throws UaException {
188188
return new OpcUaClient(config, transport);
189189
}
190190

191+
/**
192+
* Create an {@link OpcUaClient} configured with {@code config}.
193+
*
194+
* @param config the {@link OpcUaClientConfig}.
195+
* @param configureTransport a Consumer that receives an {@link
196+
* OpcTcpClientTransportConfigBuilder} that can be used to configure the transport.
197+
* @return a new {@link OpcUaClient} configured with {@code config}.
198+
* @throws UaException if the client could not be created.
199+
*/
200+
public static OpcUaClient create(
201+
OpcUaClientConfig config, Consumer<OpcTcpClientTransportConfigBuilder> configureTransport)
202+
throws UaException {
203+
204+
var transportConfigBuilder = OpcTcpClientTransportConfig.newBuilder();
205+
configureTransport.accept(transportConfigBuilder);
206+
207+
OpcTcpClientTransportConfig transportConfig = transportConfigBuilder.build();
208+
209+
return new OpcUaClient(config, new OpcTcpClientTransport(transportConfig));
210+
}
211+
191212
/**
192213
* Select the first endpoint with no security that allows anonymous connections and create an
193214
* {@link OpcUaClient} with the default configuration.

0 commit comments

Comments
 (0)