Search in sources :

Example 1 with UaObjectNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode 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);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) MemoryMXBean(java.lang.management.MemoryMXBean) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) Optional(java.util.Optional) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) MemoryMXBean(java.lang.management.MemoryMXBean) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean)

Example 2 with UaObjectNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode 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);
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) MemoryMXBean(java.lang.management.MemoryMXBean) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) Optional(java.util.Optional) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)

Example 3 with UaObjectNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode 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);
        }
    }
}
Also used : NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) LocalizedText(org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) MemoryMXBean(java.lang.management.MemoryMXBean) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UaNodeContext(org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext) AttributeFilters(org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters) Optional(java.util.Optional) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) Identifiers(org.eclipse.milo.opcua.stack.core.Identifiers) Variant(org.eclipse.milo.opcua.stack.core.types.builtin.Variant) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) DataValue(org.eclipse.milo.opcua.stack.core.types.builtin.DataValue) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) UnixOperatingSystemMXBean(com.sun.management.UnixOperatingSystemMXBean)

Example 4 with UaObjectNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode 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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UaVariableNode(org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode) UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) ServerTypeNode(org.eclipse.milo.opcua.sdk.server.model.nodes.objects.ServerTypeNode) QualifiedName(org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName) NodeId(org.eclipse.milo.opcua.stack.core.types.builtin.NodeId) ExpandedNodeId(org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId) UaNode(org.eclipse.milo.opcua.sdk.server.nodes.UaNode) Nullable(org.jetbrains.annotations.Nullable) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 5 with UaObjectNode

use of org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode in project milo by eclipse.

the class ManagedAddressSpace method getInvocationHandler.

/**
 * Get the {@link MethodInvocationHandler} for the method identified by {@code methodId}, if it exists.
 *
 * @param objectId the {@link NodeId} identifying the object the method will be invoked on.
 * @param methodId the {@link NodeId} identifying the method.
 * @return the {@link MethodInvocationHandler} for {@code methodId}, if it exists.
 */
protected Optional<MethodInvocationHandler> getInvocationHandler(NodeId objectId, NodeId methodId) {
    return nodeManager.getNode(objectId).flatMap(node -> {
        UaMethodNode methodNode = null;
        if (node instanceof UaObjectNode) {
            UaObjectNode objectNode = (UaObjectNode) node;
            methodNode = objectNode.findMethodNode(methodId);
        } else if (node instanceof UaObjectTypeNode) {
            UaObjectTypeNode objectTypeNode = (UaObjectTypeNode) node;
            methodNode = objectTypeNode.findMethodNode(methodId);
        }
        if (methodNode != null) {
            return Optional.of(methodNode.getInvocationHandler());
        } else {
            return Optional.empty();
        }
    });
}
Also used : UaObjectTypeNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectTypeNode) UaMethodNode(org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode) UaObjectNode(org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode)

Aggregations

UaObjectNode (org.eclipse.milo.opcua.sdk.server.nodes.UaObjectNode)12 UaVariableNode (org.eclipse.milo.opcua.sdk.server.nodes.UaVariableNode)9 UaNode (org.eclipse.milo.opcua.sdk.server.nodes.UaNode)6 UaObjectTypeNode (org.eclipse.milo.opcua.sdk.server.nodes.UaObjectTypeNode)6 DataValue (org.eclipse.milo.opcua.stack.core.types.builtin.DataValue)6 NodeId (org.eclipse.milo.opcua.stack.core.types.builtin.NodeId)6 Variant (org.eclipse.milo.opcua.stack.core.types.builtin.Variant)6 Reference (org.eclipse.milo.opcua.sdk.core.Reference)4 UaMethodNode (org.eclipse.milo.opcua.sdk.server.nodes.UaMethodNode)4 UaException (org.eclipse.milo.opcua.stack.core.UaException)4 QualifiedName (org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName)4 UnixOperatingSystemMXBean (com.sun.management.UnixOperatingSystemMXBean)3 ManagementFactory (java.lang.management.ManagementFactory)3 MemoryMXBean (java.lang.management.MemoryMXBean)3 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)3 Optional (java.util.Optional)3 UaNodeContext (org.eclipse.milo.opcua.sdk.server.nodes.UaNodeContext)3 AttributeFilters (org.eclipse.milo.opcua.sdk.server.nodes.filters.AttributeFilters)3 Identifiers (org.eclipse.milo.opcua.stack.core.Identifiers)3 ExpandedNodeId (org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId)3