Class SGrDeviceBuilder
- java.lang.Object
-
- com.smartgridready.communicator.common.api.SGrDeviceBuilder
-
public class SGrDeviceBuilder extends java.lang.ObjectImplements a generic SGr device builder. Provides a fluent interface to build device instances from EI-XML and parameters. Uses theServiceLoadermechanism to load interface driver factories from the classpath.
-
-
Constructor Summary
Constructors Constructor Description SGrDeviceBuilder()Constructs new instance with defaults.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GenDeviceApibuild()Builds the SGr device using the previously set builder parameters.SGrDeviceBuildereid(com.smartgridready.ns.v0.DeviceFrame deviceFrame)Sets the EID source to a pre-loadedDeviceFrame.SGrDeviceBuildereid(java.io.InputStream inputStream)Sets the EID source to an input stream.SGrDeviceBuildereid(java.lang.String content)Sets the EID source to XML content.SGrDeviceBuildereid(java.nio.file.Path path)Sets the EID source to a file system path.SGrDeviceBuilderproperties(java.util.Properties properties)Sets the EID configuration parameters.SGrDeviceBuilderuseContactsDriverFactory(com.smartgridready.driver.api.contacts.GenDriverAPI4ContactsFactory contactsDriverFactory)Sets the contacts driver factory explicitly.SGrDeviceBuilderuseMessagingClientFactory(com.smartgridready.driver.api.messaging.GenMessagingClientFactory messagingClientFactory, com.smartgridready.driver.api.messaging.model.MessagingPlatformType platform)Sets the messaging client factory to be used explicitly.SGrDeviceBuilderuseModbusClientFactory(com.smartgridready.driver.api.modbus.GenDriverAPI4ModbusFactory modbusClientFactory)Sets the Modbus client factory explicitly.SGrDeviceBuilderuseRestServiceClientFactory(com.smartgridready.driver.api.http.GenHttpClientFactory httpClientFactory)Sets the REST API service client factory.SGrDeviceBuilderuseSharedModbusGatewayRegistry(ModbusGatewayRegistry sharedModbusGatewayRegistry)Sets a custom shared Modbus RTU driver registry.SGrDeviceBuilderuseSharedModbusRtu(boolean useSharedModbusRtu)Enables or disables shared instances of Modbus RTU drivers.
-
-
-
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-loadedDeviceFrame. 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 usedplatform- 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 JavaServiceLoadermechanism 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. Isfalseby 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 onuseSharedModbusRtu.- 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 errorRestApiAuthenticationException- on HTTP authentication error
-
-