-
Notifications
You must be signed in to change notification settings - Fork 420
/
AddressSpace.java
649 lines (529 loc) · 23.1 KB
/
AddressSpace.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
/*
* Copyright (c) 2024 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.milo.opcua.sdk.server;
import java.util.Collections;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import org.eclipse.milo.opcua.sdk.core.Reference;
import org.eclipse.milo.opcua.sdk.server.items.DataItem;
import org.eclipse.milo.opcua.sdk.server.items.EventItem;
import org.eclipse.milo.opcua.sdk.server.items.MonitoredItem;
import org.eclipse.milo.opcua.stack.core.StatusCodes;
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue;
import org.eclipse.milo.opcua.stack.core.types.builtin.DiagnosticInfo;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
import org.eclipse.milo.opcua.stack.core.types.enumerated.MonitoringMode;
import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesItem;
import org.eclipse.milo.opcua.stack.core.types.structured.AddNodesResult;
import org.eclipse.milo.opcua.stack.core.types.structured.AddReferencesItem;
import org.eclipse.milo.opcua.stack.core.types.structured.CallMethodRequest;
import org.eclipse.milo.opcua.stack.core.types.structured.CallMethodResult;
import org.eclipse.milo.opcua.stack.core.types.structured.DeleteNodesItem;
import org.eclipse.milo.opcua.stack.core.types.structured.DeleteReferencesItem;
import org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadDetails;
import org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadResult;
import org.eclipse.milo.opcua.stack.core.types.structured.HistoryReadValueId;
import org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateDetails;
import org.eclipse.milo.opcua.stack.core.types.structured.HistoryUpdateResult;
import org.eclipse.milo.opcua.stack.core.types.structured.ReadValueId;
import org.eclipse.milo.opcua.stack.core.types.structured.ViewDescription;
import org.eclipse.milo.opcua.stack.core.types.structured.WriteValue;
import org.jetbrains.annotations.Nullable;
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
public interface AddressSpace {
//region Attribute Services
/**
* Read one or more values from nodes belonging to this {@link AddressSpace}.
*
* @param context the {@link ReadContext}.
* @param maxAge requested max age.
* @param timestamps requested timestamp values.
* @param readValueIds the values to read.
* @return the {@link DataValue}s read.
*/
List<DataValue> read(ReadContext context, Double maxAge, TimestampsToReturn timestamps, List<ReadValueId> readValueIds);
/**
* Write one or more values to nodes belonging to this {@link AddressSpace}.
*
* @param context the {@link WriteContext}.
* @param writeValues the values to write.
* @return the {@link StatusCode}s for each write.
*/
List<StatusCode> write(WriteContext context, List<WriteValue> writeValues);
/**
* Read history values from nodes belonging to this {@link AddressSpace}.
*
* @param context the {@link HistoryReadContext}.
* @param timestamps requested timestamp values.
* @param readValueIds the values to read.
* @return the {@link HistoryReadResult}s read.
*/
default List<HistoryReadResult> historyRead(
HistoryReadContext context,
HistoryReadDetails readDetails,
TimestampsToReturn timestamps,
List<HistoryReadValueId> readValueIds
) {
HistoryReadResult result = new HistoryReadResult(
new StatusCode(StatusCodes.Bad_HistoryOperationUnsupported),
null,
null
);
return Collections.nCopies(readValueIds.size(), result);
}
/**
* Update history values in nodes belonging to this {@link AddressSpace}.
*
* @param context the {@link HistoryUpdateContext}.
* @param updateDetails the values to read.
* @return the {@link HistoryUpdateResult}s for each update.
*/
default List<HistoryUpdateResult> historyUpdate(
HistoryUpdateContext context,
List<HistoryUpdateDetails> updateDetails
) {
HistoryUpdateResult result = new HistoryUpdateResult(
new StatusCode(StatusCodes.Bad_HistoryOperationUnsupported),
null,
null
);
return Collections.nCopies(updateDetails.size(), result);
}
//endregion
//region Method Services
/**
* Invoke one or more methods belonging to this {@link AddressSpace}.
*
* @param context the {@link CallContext}.
* @param requests The {@link CallMethodRequest}s for the methods to invoke.
* @return the {@link CallMethodResult}s for each method invocation.
*/
default List<CallMethodResult> call(CallContext context, List<CallMethodRequest> requests) {
CallMethodResult result = new CallMethodResult(
new StatusCode(StatusCodes.Bad_NotImplemented),
new StatusCode[0],
new DiagnosticInfo[0],
new Variant[0]
);
return Collections.nCopies(requests.size(), result);
}
//endregion
//region MonitoredItem Services
/**
* A {@link DataItem} is being created for a Node managed by this {@link AddressSpace}.
* <p>
* This is a chance to revise the requested queue size and/or sampling interval.
* <p>
* The sampling interval has already been revised to fit within the configured server limits and to be at least the
* value of the Minimum Sampling Interval attribute for the Node if it was present.
*
* @param itemToMonitor the item that will be monitored.
* @param requestedQueueSize the requested queue size.
* @param requestedSamplingInterval the requested sampling interval.
* @param revisionCallback the callback to invoke to revise the sampling interval and queue size.
*/
default void onCreateDataItem(
@SuppressWarnings("unused") ReadValueId itemToMonitor,
Double requestedSamplingInterval,
UInteger requestedQueueSize,
BiConsumer<Double, UInteger> revisionCallback) {
revisionCallback.accept(requestedSamplingInterval, requestedQueueSize);
}
/**
* A {@link DataItem} is being modified for a Node managed by this {@link AddressSpace}.
* <p>
* This is a chance to revise the requested queue size and/or sampling interval.
* <p>
* The sampling interval has already been revised to fit within the configured server limits and to be at least the
* value of the Minimum Sampling Interval attribute for the Node if it was present.
*
* @param itemToModify the item that will be modified.
* @param requestedQueueSize the requested queue size.
* @param requestedSamplingInterval the requested sampling interval.
* @param revisionCallback the callback to invoke to revise the sampling interval and queue size.
*/
default void onModifyDataItem(
@SuppressWarnings("unused") ReadValueId itemToModify,
Double requestedSamplingInterval,
UInteger requestedQueueSize,
BiConsumer<Double, UInteger> revisionCallback) {
revisionCallback.accept(requestedSamplingInterval, requestedQueueSize);
}
/**
* An {@link EventItem} is being created for a Node managed by this {@link AddressSpace}.
* <p>
* This is a chance to revise the requested queue size.
*
* @param itemToMonitor the item that will be monitored.
* @param requestedQueueSize the requested queue size.
* @param revisionCallback the callback to invoke to revise the queue size.
*/
default void onCreateEventItem(
@SuppressWarnings("unused") ReadValueId itemToMonitor,
UInteger requestedQueueSize,
Consumer<UInteger> revisionCallback) {
revisionCallback.accept(requestedQueueSize);
}
/**
* An {@link EventItem} is being modified for a Node managed by this {@link AddressSpace}.
* <p>
* This is a chance to revise the requested queue size.
*
* @param itemToModify the item that will be modified.
* @param requestedQueueSize the requested queue size.
* @param revisionCallback the callback to invoke to revise the queue size.
*/
default void onModifyEventItem(
@SuppressWarnings("unused") ReadValueId itemToModify,
UInteger requestedQueueSize,
Consumer<UInteger> revisionCallback) {
revisionCallback.accept(requestedQueueSize);
}
/**
* {@link DataItem}s have been created for nodes belonging to this {@link AddressSpace}.
* <p>
* If sampling is enabled for this item, it is expected that a best-effort will be made to update the item's value
* at the sampling rate.
*
* @param dataItems the {@link DataItem}s that were created.
*/
void onDataItemsCreated(List<DataItem> dataItems);
/**
* {@link DataItem}s have been modified for nodes belonging to this {@link AddressSpace}.
* <p>
* Check to see if the sampling rate has changed or if sampling has been enabled or disabled.
*
* @param dataItems the {@link DataItem}s that were modified.
*/
void onDataItemsModified(List<DataItem> dataItems);
/**
* {@link DataItem}s have been deleted for nodes belonging to this {@link AddressSpace}.
* <p>
* Updates to this item should cease and any references to it should be removed.
*
* @param dataItems the {@link DataItem}s that were deleted.
*/
void onDataItemsDeleted(List<DataItem> dataItems);
/**
* {@link EventItem}s have been created for nodes belonging to this {@link AddressSpace}.
*
* @param eventItems the {@link EventItem}s that were created.
*/
default void onEventItemsCreated(List<EventItem> eventItems) {}
/**
* {@link EventItem}s have been modified for nodes belonging to this {@link AddressSpace}.
*
* @param eventItems the {@link EventItem}s that were modified.
*/
default void onEventItemsModified(List<EventItem> eventItems) {}
/**
* {@link EventItem}s have been deleted for nodes belonging to this {@link AddressSpace}.
*
* @param eventItems the {@link EventItem}s that were deleted.
*/
default void onEventItemsDeleted(List<EventItem> eventItems) {}
/**
* {@link MonitoredItem}s have had their {@link MonitoringMode} modified by a client.
* <p>
* Check if sampling is still enabled and react accordingly.
*
* @param monitoredItems The {@link MonitoredItem}s whose {@link MonitoringMode} was modified.
*/
void onMonitoringModeChanged(List<MonitoredItem> monitoredItems);
//endregion
//region NodeManagement Services
default List<AddNodesResult> addNodes(AddNodesContext context, List<AddNodesItem> nodesToAdd) {
AddNodesResult result = new AddNodesResult(
new StatusCode(StatusCodes.Bad_NotSupported),
NodeId.NULL_VALUE
);
return Collections.nCopies(nodesToAdd.size(), result);
}
default List<StatusCode> deleteNodes(DeleteNodesContext context, List<DeleteNodesItem> nodesToDelete) {
StatusCode statusCode = new StatusCode(StatusCodes.Bad_NotSupported);
return Collections.nCopies(nodesToDelete.size(), statusCode);
}
default List<StatusCode> addReferences(AddReferencesContext context, List<AddReferencesItem> referencesToAdd) {
StatusCode statusCode = new StatusCode(StatusCodes.Bad_NotSupported);
return Collections.nCopies(referencesToAdd.size(), statusCode);
}
default List<StatusCode> deleteReferences(DeleteReferencesContext context, List<DeleteReferencesItem> referencesToDelete) {
StatusCode statusCode = new StatusCode(StatusCodes.Bad_NotSupported);
return Collections.nCopies(referencesToDelete.size(), statusCode);
}
//endregion
//region View Services
/**
* The result of an {@link AddressSpace} browse or gather operation.
*
* @see AddressSpace#browse(BrowseContext, ViewDescription, List)
* @see AddressSpace#gather(BrowseContext, ViewDescription, NodeId)
*/
sealed interface ReferenceResult {
/**
* The NodeId being browsed is unknown to the {@link AddressSpace}.
*/
record BadNodeIdUnknown() implements ReferenceResult {}
/**
* The {@link AddressSpace} being browsed or gathered has references to contribute.
*
* @param references the {@link Reference}s being contributed.
*/
record ReferenceList(List<Reference> references) implements ReferenceResult {}
static ReferenceList of(List<Reference> references) {
return new ReferenceList(references);
}
static BadNodeIdUnknown unknown() {
return new BadNodeIdUnknown();
}
}
/**
* For each {@link NodeId} in {@code nodeIds} return the References for which that
* {@link NodeId} is the source.
*
* <p> If the NodeId is unknown to this AddressSpace then return
* {@link ReferenceResult.BadNodeIdUnknown}.
*
* <p> If this AddressSpace has References to contribute then return
* {@link ReferenceResult.ReferenceList} containing the References.
*
* @param context the {@link BrowseContext}.
* @param view the {@link ViewDescription}.
* @param nodeIds the {@link NodeId}s to browse.
* @return a List of {@link ReferenceResult}s for each {@link NodeId}.
*/
List<ReferenceResult> browse(BrowseContext context, ViewDescription view, List<NodeId> nodeIds);
/**
* References for which {@code nodeId} is the source are being gathered from all AddressSpace
* instances. Return any References where {@code nodeId} is the source this AddressSpace may
* have to contribute.
*
* <p> The Node identified by {@code nodeId} may be managed by another AddressSpace, i.e. the
* NodeId References are being gathered for did not pass any {@link AddressSpaceFilter}.
*
* @param context the {@link BrowseContext}.
* @param view the {@link ViewDescription}.
* @param nodeId the {@link NodeId} to get references fo.
* @return a {@link ReferenceResult.ReferenceList} containing the gathered {@link Reference}s.
*/
ReferenceResult.ReferenceList gather(BrowseContext context, ViewDescription view, NodeId nodeId);
/**
* Register one or more {@link NodeId}s.
*
* @param context the {@link RegisterNodesContext}.
* @param nodeIds the {@link NodeId}s to register.
* @return the registered {@link NodeId}s.
*/
default List<NodeId> registerNodes(RegisterNodesContext context, List<NodeId> nodeIds) {
return nodeIds;
}
/**
* Unregister one or more previously registered {@link NodeId}s.
*
* @param context the {@link UnregisterNodesContext}.
* @param nodeIds the {@link NodeId}s to unregister.
*/
default void unregisterNodes(UnregisterNodesContext context, List<NodeId> nodeIds) {}
/**
* Get the number of views, if any, managed by this {@link AddressSpace} implementation.
*
* @return the number of views, if any, managed by this {@link AddressSpace} implementation.
*/
default UInteger getViewCount() {
return uint(0);
}
//endregion
final class ReadContext extends ServiceOperationContext<ReadValueId> {
public ReadContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public ReadContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<ReadValueId> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class WriteContext extends ServiceOperationContext<WriteValue> {
public WriteContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public WriteContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<WriteValue> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class HistoryReadContext extends ServiceOperationContext<HistoryReadValueId> {
public HistoryReadContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public HistoryReadContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<HistoryReadValueId> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class HistoryUpdateContext extends ServiceOperationContext<HistoryUpdateDetails> {
public HistoryUpdateContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public HistoryUpdateContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<HistoryUpdateDetails> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class CallContext extends ServiceOperationContext<CallMethodRequest> {
public CallContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public CallContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<CallMethodRequest> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class AddNodesContext extends ServiceOperationContext<AddNodesItem> {
public AddNodesContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public AddNodesContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<AddNodesItem> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class DeleteNodesContext extends ServiceOperationContext<DeleteNodesItem> {
public DeleteNodesContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public DeleteNodesContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<DeleteNodesItem> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class AddReferencesContext extends ServiceOperationContext<AddReferencesItem> {
public AddReferencesContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public AddReferencesContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<AddReferencesItem> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class DeleteReferencesContext extends ServiceOperationContext<DeleteReferencesItem> {
public DeleteReferencesContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public DeleteReferencesContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<DeleteReferencesItem> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class BrowseContext extends ServiceOperationContext<NodeId> {
public BrowseContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public BrowseContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<NodeId> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class RegisterNodesContext extends ServiceOperationContext<NodeId> {
public RegisterNodesContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public RegisterNodesContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<NodeId> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
final class UnregisterNodesContext extends ServiceOperationContext<NodeId> {
public UnregisterNodesContext(OpcUaServer server, @Nullable Session session) {
super(server, session);
}
public UnregisterNodesContext(
OpcUaServer server,
@Nullable Session session,
DiagnosticsContext<NodeId> diagnosticsContext,
@Nullable String auditEntryId,
UInteger timeoutHint,
ExtensionObject additionalHeader
) {
super(server, session, diagnosticsContext, auditEntryId, timeoutHint, additionalHeader);
}
}
}