Class SGrDeviceBuilder


  • public class SGrDeviceBuilder
    extends java.lang.Object
    Implements a generic SGr device builder. Provides a fluent interface to build device instances from EI-XML and parameters. Uses the ServiceLoader mechanism to load interface driver factories from the classpath.
    • Constructor Detail

      • SGrDeviceBuilder

        public SGrDeviceBuilder()
        Constructs new instance with defaults. Interface driver factories are loaded using the ServiceLoader mechanism, if present in the classpath.
    • Method Detail

      • eid

        public SGrDeviceBuilder eid​(java.nio.file.Path path)
        Sets the EID source to a file system path.
        Parameters:
        path - the file system path
        Returns:
        the same instance of SGrDeviceBuilder
      • eid

        public SGrDeviceBuilder eid​(java.io.InputStream inputStream)
        Sets the EID source to an input stream.
        Parameters:
        inputStream - the input stream
        Returns:
        the same instance of SGrDeviceBuilder
      • eid

        public SGrDeviceBuilder eid​(java.lang.String content)
        Sets the EID source to XML content.
        Parameters:
        content - the XML content
        Returns:
        the same instance of SGrDeviceBuilder
      • eid

        public SGrDeviceBuilder eid​(com.smartgridready.ns.v0.DeviceFrame deviceFrame)
        Sets the EID source to a pre-loaded DeviceFrame. This ignores any given EID configuration properties.
        Parameters:
        deviceFrame - the XML content
        Returns:
        the same instance of SGrDeviceBuilder
      • useRestServiceClientFactory

        public SGrDeviceBuilder useRestServiceClientFactory​(com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory)
        Sets the REST API service client factory.
        Parameters:
        httpClientFactory - an instance of a REST API service client factory
        Returns:
        the same instance of SGrDeviceBuilder
      • useModbusClientFactory

        public SGrDeviceBuilder useModbusClientFactory​(com.smartgridready.driver.api.modbus.GenDriverAPI4ModbusFactory modbusClientFactory)
        Sets the Modbus client factory explicitly. If not set explicitly, the Java ServiceLoader mechanism tries to find an implementation on the classpath.
        Parameters:
        modbusClientFactory - an instance of a Modbus client factory
        Returns:
        the same instance of SGrDeviceBuilder
      • useMessagingClientFactory

        public SGrDeviceBuilder useMessagingClientFactory​(com.smartgridready.driver.api.messaging.GenMessagingClientFactory messagingClientFactory,
                                                          com.smartgridready.driver.api.messaging.model.MessagingPlatformType platform)
        Sets the messaging client factory to be used explicitly. If not set explicitly, the Java ServiceLoader mechanism tries to find an implementation on the classpath.
        Parameters:
        messagingClientFactory - the messaging client factory to be used
        platform - the messaging platform type
        Returns:
        the same instance of SGrDeviceBuilder
      • useContactsDriverFactory

        public SGrDeviceBuilder useContactsDriverFactory​(com.smartgridready.driver.api.contacts.GenDriverAPI4ContactsFactory contactsDriverFactory)
        Sets the contacts driver factory explicitly. If not set explicitly, the Java ServiceLoader mechanism tries to find an implementation on the classpath.
        Parameters:
        contactsDriverFactory - an instance of a contacts driver factory
        Returns:
        the same instance of SGrDeviceBuilder
      • useSharedModbusRtu

        public SGrDeviceBuilder useSharedModbusRtu​(boolean useSharedModbusRtu)
        Enables or disables shared instances of Modbus RTU drivers. When enabled, multiple device instances can use the same RS-485 serial port. Otherwise a serial port can only be used by a single device. Is false by default, if not set.
        Parameters:
        useSharedModbusRtu - the updated setting
        Returns:
        the same instance of SGrDeviceBuilder
      • useSharedModbusGatewayRegistry

        public SGrDeviceBuilder useSharedModbusGatewayRegistry​(ModbusGatewayRegistry sharedModbusGatewayRegistry)
        Sets a custom shared Modbus RTU driver registry. Uses a global singleton instance by default, if not set. Also depends on useSharedModbusRtu.
        Parameters:
        sharedModbusGatewayRegistry - the custom registry
        Returns:
        the same instance of SGrDeviceBuilder
      • properties

        public SGrDeviceBuilder properties​(java.util.Properties properties)
        Sets the EID configuration parameters.
        Parameters:
        properties - the properties
        Returns:
        the same instance of SGrDeviceBuilder
      • build

        public GenDeviceApi build()
                           throws com.smartgridready.driver.api.common.GenDriverException,
                                  RestApiAuthenticationException
        Builds the SGr device using the previously set builder parameters.
        Returns:
        an SGr device object implementing GenDeviceApi
        Throws:
        com.smartgridready.driver.api.common.GenDriverException - on generic error
        RestApiAuthenticationException - on HTTP authentication error