use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project milo by eclipse.
the class VendorServerInfoNodes method addVendorInfoJmx.
private static void addVendorInfoJmx(UaNodeContext context, UaObjectNode vendorServerInfo) {
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
UaVariableNode usedMemory = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/UsedMemory")).setBrowseName(new QualifiedName(1, "UsedMemory")).setDisplayName(LocalizedText.english("UsedMemory")).setDataType(Identifiers.Int64).buildAndAdd();
usedMemory.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(memoryBean.getHeapMemoryUsage().getUsed()))));
UaVariableNode maxMemory = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/MaxMemory")).setBrowseName(new QualifiedName(1, "MaxMemory")).setDisplayName(LocalizedText.english("MaxMemory")).setDataType(Identifiers.Int64).buildAndAdd();
maxMemory.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(memoryBean.getHeapMemoryUsage().getMax()))));
UaVariableNode osName = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OsName")).setBrowseName(new QualifiedName(1, "OsName")).setDisplayName(LocalizedText.english("OsName")).setDataType(Identifiers.String).buildAndAdd();
osName.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(osBean.getName()))));
UaVariableNode osArch = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OsArch")).setBrowseName(new QualifiedName(1, "OsArch")).setDisplayName(LocalizedText.english("OsArch")).setDataType(Identifiers.String).buildAndAdd();
osArch.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(osBean.getArch()))));
UaVariableNode osVersion = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OsVersion")).setBrowseName(new QualifiedName(1, "OsVersion")).setDisplayName(LocalizedText.english("OsVersion")).setDataType(Identifiers.String).buildAndAdd();
osVersion.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(osBean.getVersion()))));
vendorServerInfo.addComponent(usedMemory);
vendorServerInfo.addComponent(maxMemory);
vendorServerInfo.addComponent(osName);
vendorServerInfo.addComponent(osArch);
vendorServerInfo.addComponent(osVersion);
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project milo by eclipse.
the class VendorServerInfoNodes method addVendorInfoPlainJava.
private static void addVendorInfoPlainJava(UaNodeContext context, UaObjectNode vendorServerInfo) {
UaVariableNode availableProcessors = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/AvailableProcessors")).setBrowseName(new QualifiedName(1, "AvailableProcessors")).setDisplayName(LocalizedText.english("AvailableProcessors")).setDataType(Identifiers.Int32).buildAndAdd();
availableProcessors.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(Runtime.getRuntime().availableProcessors()))));
vendorServerInfo.addComponent(availableProcessors);
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project milo by eclipse.
the class VendorServerInfoNodes method addVendorInfoSunJmx.
private static void addVendorInfoSunJmx(UaNodeContext context, UaObjectNode vendorServerInfo) {
OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();
if (osMxBean instanceof com.sun.management.OperatingSystemMXBean) {
com.sun.management.OperatingSystemMXBean sunOsMxBean = (com.sun.management.OperatingSystemMXBean) osMxBean;
UaVariableNode processCpuLoad = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/ProcessCpuLoad")).setBrowseName(new QualifiedName(1, "ProcessCpuLoad")).setDisplayName(LocalizedText.english("ProcessCpuLoad")).setDataType(Identifiers.Double).buildAndAdd();
processCpuLoad.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(sunOsMxBean.getProcessCpuLoad() * 100d))));
UaVariableNode systemCpuLoad = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/SystemCpuLoad")).setBrowseName(new QualifiedName(1, "SystemCpuLoad")).setDisplayName(LocalizedText.english("SystemCpuLoad")).setDataType(Identifiers.Double).buildAndAdd();
systemCpuLoad.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(sunOsMxBean.getSystemCpuLoad() * 100d))));
vendorServerInfo.addComponent(processCpuLoad);
vendorServerInfo.addComponent(systemCpuLoad);
if (sunOsMxBean instanceof UnixOperatingSystemMXBean) {
UnixOperatingSystemMXBean unixBean = (UnixOperatingSystemMXBean) sunOsMxBean;
UaVariableNode openFileDescriptors = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/OpenFileDescriptors")).setBrowseName(new QualifiedName(1, "OpenFileDescriptors")).setDisplayName(LocalizedText.english("OpenFileDescriptors")).setDataType(Identifiers.Int64).buildAndAdd();
openFileDescriptors.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(unixBean.getOpenFileDescriptorCount()))));
UaVariableNode maxFileDescriptors = UaVariableNode.builder(context).setNodeId(new NodeId(1, "VendorServerInfo/MaxFileDescriptors")).setBrowseName(new QualifiedName(1, "MaxFileDescriptors")).setDisplayName(LocalizedText.english("MaxFileDescriptors")).setDataType(Identifiers.Int64).buildAndAdd();
maxFileDescriptors.getFilterChain().addLast(AttributeFilters.getValue(ctx -> new DataValue(new Variant(unixBean.getMaxFileDescriptorCount()))));
vendorServerInfo.addComponent(openFileDescriptors);
vendorServerInfo.addComponent(maxFileDescriptors);
}
}
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project milo by eclipse.
the class AttributeDelegateChainTest method testCreate.
@Test
public void testCreate() throws Exception {
List<String> list = new ArrayList<>();
AttributeDelegate delegate = AttributeDelegateChain.create(new AttributeDelegate() {
@Override
public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
list.add("root");
return node.getValue();
}
}, parent -> new DelegatingAttributeDelegate(parent) {
@Override
public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
list.add("child1");
return super.getValue(context, node);
}
}, parent -> new DelegatingAttributeDelegate(parent) {
@Override
public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
list.add("child2");
return super.getValue(context, node);
}
}, parent -> new DelegatingAttributeDelegate(parent) {
@Override
public DataValue getValue(AttributeContext context, VariableNode node) throws UaException {
list.add("child3");
return super.getValue(context, node);
}
});
UaNodeManager nodeManager = new UaNodeManager();
UaNodeContext context = new UaNodeContext() {
@Override
public OpcUaServer getServer() {
return null;
}
@Override
public NodeManager<UaNode> getNodeManager() {
return nodeManager;
}
@Override
public NamespaceTable getNamespaceTable() {
return new NamespaceTable();
}
};
UaVariableNode node = new UaVariableNode.UaVariableNodeBuilder(context).setNodeId(NodeId.NULL_VALUE).setAccessLevel(AccessLevel.READ_WRITE).setBrowseName(QualifiedName.NULL_VALUE).setDisplayName(LocalizedText.NULL_VALUE).setDataType(Identifiers.String).setTypeDefinition(Identifiers.BaseDataVariableType).build();
node.setValue(new DataValue(new Variant("foo")));
DataValue value = delegate.getValue(new AttributeContext(null, null), node);
assertEquals(value.getValue().getValue(), "foo");
assertEquals(list.get(0), "child3");
assertEquals(list.get(1), "child2");
assertEquals(list.get(2), "child1");
assertEquals(list.get(3), "root");
}
use of org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode in project milo by eclipse.
the class NodeFactoryTest method testInstanceListener.
@Test
public void testInstanceListener() throws Exception {
final AtomicBoolean methodAdded = new AtomicBoolean(false);
final AtomicBoolean objectAdded = new AtomicBoolean(false);
final AtomicBoolean variableAdded = new AtomicBoolean(false);
ServerTypeNode serverNode = (ServerTypeNode) nodeFactory.createNode(new NodeId(0, "Server"), Identifiers.ServerType, new NodeFactory.InstantiationCallback() {
@Override
public boolean includeOptionalNode(NodeId typeDefinitionId, QualifiedName browseName) {
return true;
}
@Override
public void onMethodAdded(@Nullable UaObjectNode parent, UaMethodNode instance) {
String pbn = parent != null ? parent.getBrowseName().getName() : null;
System.out.println("onMethodAdded parent=" + pbn + " instance=" + instance.getBrowseName().getName());
methodAdded.set(true);
}
@Override
public void onObjectAdded(@Nullable UaNode parent, UaObjectNode instance, NodeId typeDefinitionId) {
String pbn = parent != null ? parent.getBrowseName().getName() : null;
System.out.println("onObjectAdded parent=" + pbn + " instance=" + instance.getBrowseName().getName());
objectAdded.set(true);
}
@Override
public void onVariableAdded(@Nullable UaNode parent, UaVariableNode instance, NodeId typeDefinitionId) {
String pbn = parent != null ? parent.getBrowseName().getName() : null;
System.out.println("onVariableAdded parent=" + pbn + " instance=" + instance.getBrowseName().getName());
variableAdded.set(true);
}
});
assertTrue(methodAdded.get());
assertTrue(objectAdded.get());
assertTrue(variableAdded.get());
}
Aggregations