V1
OPCUAConnectionManager
¶
Thread-safe connection manager for OPC UA clients with connection pooling and circuit breaker pattern.
Maintains a pool of connections keyed by (url, user_name) to avoid creating new connections for every write operation. Uses circuit breaker to fail fast when servers are unreachable.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
__new__()
¶
Singleton pattern to ensure one connection manager across the application.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
35 36 37 38 39 40 41 42 | |
close_all()
¶
Close all connections in the pool and stop the shared ThreadLoop.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
332 333 334 335 336 337 338 339 340 | |
get_connection(url, user_name, password, timeout, max_retries=1, base_backoff=0.0)
¶
Get a connection from the pool or create a new one.
This method is thread-safe and will reuse existing healthy connections. Uses circuit breaker pattern to fail fast for recently failed servers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
user_name
|
Optional[str]
|
Optional username for authentication |
required |
password
|
Optional[str]
|
Optional password for authentication |
required |
timeout
|
int
|
Connection timeout in seconds |
required |
max_retries
|
int
|
Maximum number of connection attempts (default 1) |
1
|
base_backoff
|
float
|
Base delay between retries (default 0) |
0.0
|
Returns:
| Type | Description |
|---|---|
Client
|
A connected OPC UA client |
Raises:
| Type | Description |
|---|---|
Exception
|
If connection fails or circuit breaker is open |
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
get_pool_stats()
¶
Get statistics about the connection pool.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
invalidate_connection(url, user_name)
¶
Invalidate a connection, forcing it to be recreated on next use.
Call this when a connection error occurs during an operation to ensure the next operation gets a fresh connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
user_name
|
Optional[str]
|
Optional username used for the connection |
required |
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
release_connection(url, user_name, force_close=False)
¶
Release a connection back to the pool.
By default, connections are kept alive for reuse. Set force_close=True to immediately close the connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
user_name
|
Optional[str]
|
Optional username used for the connection |
required |
force_close
|
bool
|
If True, close the connection instead of keeping it |
False
|
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
UnsupportedTypeError
¶
Bases: Exception
Raised when an unsupported value type is specified
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
370 371 372 373 | |
get_available_namespaces(client)
¶
Get list of available namespaces from OPC UA server. Returns empty list if unable to fetch namespaces.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
778 779 780 781 782 783 784 785 786 787 788 789 790 | |
get_connection_manager()
¶
Get the global OPC UA connection manager instance.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
362 363 364 365 366 367 | |
get_node_data_type(var)
¶
Get the data type of an OPC UA node. Returns a string representation of the type, or "Unknown" if unable to read.
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
802 803 804 805 806 807 808 809 810 811 | |
opc_connect_and_write_value(url, namespace, user_name, password, object_name, variable_name, value, timeout, node_lookup_mode='hierarchical', value_type='String', max_retries=1, retry_backoff_seconds=0.0)
¶
Connect to OPC UA server and write a value using connection pooling.
Uses the connection manager to reuse existing connections. If no connection exists, attempts to create one. Fails fast on connection errors to avoid blocking the pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
OPC UA server URL |
required |
namespace
|
str
|
Namespace URI or index |
required |
user_name
|
Optional[str]
|
Optional username for authentication |
required |
password
|
Optional[str]
|
Optional password for authentication |
required |
object_name
|
str
|
Target object path |
required |
variable_name
|
str
|
Variable to write |
required |
value
|
Union[bool, float, int, str]
|
Value to write |
required |
timeout
|
int
|
Connection timeout in seconds |
required |
node_lookup_mode
|
Literal['hierarchical', 'direct']
|
Path lookup strategy ('hierarchical' or 'direct') |
'hierarchical'
|
value_type
|
str
|
OPC UA data type for the value |
'String'
|
max_retries
|
int
|
Maximum number of connection attempts (default 1 = no retries) |
1
|
retry_backoff_seconds
|
float
|
Base delay between retries (default 0 = no delay) |
0.0
|
Returns:
| Type | Description |
|---|---|
Tuple[bool, str]
|
Tuple of (error_status, message) |
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 | |
safe_disconnect(client)
¶
Safely disconnect from OPC UA server, swallowing any errors
Source code in inference/enterprise/workflows/enterprise_blocks/sinks/opc_writer/v1.py
793 794 795 796 797 798 799 | |