public class IotpGateway extends java.lang.Object implements IotGateway
This class is incubating and is subject to change.
See IotpDevice
for common WIoTP documentation references.
IotpGateway
establishes its own WIoTP GatewayCallback
handler in its embedded or the passed in WIoTP GatewayClient
.
An application can use
setExternalCallbackHandler
to also receive and process callbacks.
Limitations:
IotProvider
and PublishSubscribeService
do not yet support
the gateway model. An IotProvider may be initialized with an IotpGateway
but the PublishSubscribeService mechanism will only publish events and receive
commands for the gateway device, not any of its connected devices.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTR_DEVICE_ID
WIoTP Device Id identifier key.
|
static java.lang.String |
ATTR_DEVICE_TYPE
WIoTP Device Type identifier key.
|
CMD_DEVICE, CMD_FORMAT, CMD_ID, CMD_PAYLOAD, CMD_TS, RESERVED_ID_PREFIX
Constructor and Description |
---|
IotpGateway(Topology topology,
java.io.File optionsFile)
Create a connector for the IoT gateway device specified by
optionsFile . |
IotpGateway(Topology topology,
com.ibm.iotf.client.gateway.GatewayClient gatewayClient)
Create a connector using the supplied WIoTP
DeviceClient . |
IotpGateway(Topology topology,
java.util.Properties options)
Create a connector for the IoT gateway device specified by
options . |
Modifier and Type | Method and Description |
---|---|
TStream<com.google.gson.JsonObject> |
commands(java.lang.String... commands)
Create a stream of device commands as JSON objects.
|
TStream<com.google.gson.JsonObject> |
commandsForDevice(java.util.Set<java.lang.String> fqDeviceIds,
java.lang.String... commands)
Create a stream of device commands as JSON objects.
|
TStream<com.google.gson.JsonObject> |
commandsForDevice(java.lang.String fqDeviceId,
java.lang.String... commands)
Create a stream of device commands as JSON objects.
|
TStream<com.google.gson.JsonObject> |
commandsForType(java.lang.String deviceTypeId,
java.lang.String... commands)
Create a stream of device commands as JSON objects.
|
TSink<com.google.gson.JsonObject> |
events(TStream<com.google.gson.JsonObject> stream,
Function<com.google.gson.JsonObject,java.lang.String> eventId,
UnaryOperator<com.google.gson.JsonObject> payload,
Function<com.google.gson.JsonObject,java.lang.Integer> qos)
Publish a stream's tuples as device events.
|
TSink<com.google.gson.JsonObject> |
events(TStream<com.google.gson.JsonObject> stream,
java.lang.String eventId,
int qos)
Publish a stream's tuples as device events.
|
TSink<com.google.gson.JsonObject> |
eventsForDevice(Function<com.google.gson.JsonObject,java.lang.String> fqDeviceId,
TStream<com.google.gson.JsonObject> stream,
Function<com.google.gson.JsonObject,java.lang.String> eventId,
UnaryOperator<com.google.gson.JsonObject> payload,
Function<com.google.gson.JsonObject,java.lang.Integer> qos)
Publish a stream's tuples as device events.
|
TSink<com.google.gson.JsonObject> |
eventsForDevice(java.lang.String fqDeviceId,
TStream<com.google.gson.JsonObject> stream,
java.lang.String eventId,
int qos)
Publish a stream's tuples as device events.
|
java.lang.String |
getDeviceId()
Get the device's unique opaque device identifier.
|
java.lang.String |
getDeviceType()
Get the device's opaque device type identifier.
|
IotDevice |
getIotDevice(java.util.Map<java.lang.String,java.lang.String> deviceIdAttrs)
Get an
IotDevice for a connected device. |
IotDevice |
getIotDevice(java.lang.String fqDeviceId)
Get an
IotDevice for a connected device. |
java.lang.String |
getIotDeviceId(java.util.Map<java.lang.String,java.lang.String> deviceIdAttrs)
Get a
deviceId for a device. |
com.ibm.iotf.client.gateway.GatewayCallback |
setExternalCallbackHandler(com.ibm.iotf.client.gateway.GatewayCallback handler)
Set an external WIoTP
GatewayCallback handler. |
Topology |
topology()
Topology this element is contained in.
|
java.lang.String |
toString() |
public static final java.lang.String ATTR_DEVICE_TYPE
getIotDevice(Map)
,
Constant Field Valuespublic static final java.lang.String ATTR_DEVICE_ID
getIotDevice(Map)
,
Constant Field Valuespublic IotpGateway(Topology topology, java.util.Properties options)
options
.
options
.
org=
organization identifiertype=
gateway device typeid=
gateway device identifierauth-method=token
auth-token=
authorization token
Properties options = new Properties();
options.setProperty("org", "uguhsp");
options.setProperty("type", "iotsample-gateway");
options.setProperty("id", "00aabbccde03");
options.setProperty("auth-method", "token");
options.setProperty("auth-token", "AJfKQV@&bBo@VX6Dcg");
IotDevice iotDevice = new IotpDevice(options);
Connecting to the server occurs when the topology is submitted for execution.
See the IBM Watson IoT Platform documentation for additional properties.
options
- control optionstopology
- the connector's associated Topology
.public IotpGateway(Topology topology, java.io.File optionsFile)
optionsFile
.
[device]
org = organization identifier
type = gateway device type
id = gateway device identifier
auth-method = token
auth-token = authorization token
For example:
[device]
org = uguhsp
type = iotsample-gateway
id = 00aabbccde03
auth-method = token
auth-token = AJfKQV@&bBo@VX6Dcg
Connecting to the server occurs when the topology is submitted for execution.
See the IBM Watson IoT Platform documentation for additional properties.
topology
- the connector's associated Topology
.optionsFile
- File containing connection information.public IotpGateway(Topology topology, com.ibm.iotf.client.gateway.GatewayClient gatewayClient)
DeviceClient
.topology
- the connector's associated Topology
.gatewayClient
- a WIoTP device client API object.public java.lang.String getDeviceType()
IotDevice
getDeviceType
in interface IotDevice
public java.lang.String getDeviceId()
IotDevice
getDeviceId
in interface IotDevice
public TSink<com.google.gson.JsonObject> events(TStream<com.google.gson.JsonObject> stream, Function<com.google.gson.JsonObject,java.lang.String> eventId, UnaryOperator<com.google.gson.JsonObject> payload, Function<com.google.gson.JsonObject,java.lang.Integer> qos)
IotDevice
Each tuple is published as a device event with the supplied functions providing the event identifier, payload and QoS. The event identifier and QoS can be generated based upon the tuple.
events
in interface IotDevice
stream
- Stream to be published.eventId
- function to supply the event identifier.payload
- function to supply the event's payload.qos
- function to supply the event's delivery Quality of Service.public TSink<com.google.gson.JsonObject> events(TStream<com.google.gson.JsonObject> stream, java.lang.String eventId, int qos)
IotDevice
Each tuple is published as a device event with fixed event identifier and QoS.
public TStream<com.google.gson.JsonObject> commands(java.lang.String... commands)
IotDevice
commands
will result in a tuple
on the stream. The JSON object has these keys:
device
- Command's opaque target device's id String.
command
- Command identifier as a Stringtsms
- Timestamp of the command in milliseconds since the 1970/1/1 epoch.format
- Format of the command as a Stringpayload
- Payload of the command
format
is json
then payload
is JSONpayload
is Stringpublic Topology topology()
TopologyElement
topology
in interface TopologyElement
public java.lang.String getIotDeviceId(java.util.Map<java.lang.String,java.lang.String> deviceIdAttrs)
deviceId
for a device.
Logically equivalent to getIotDevice(deviceIdAttrs).getDeviceId()
.
No external validation of the attribute values is performed.
The device's WIoTP deviceType and deviceId must be supplied
using the ATTR_DEVICE_TYPE
and ATTR_DEVICE_ID
keys respectively.
getIotDeviceId
in interface IotGateway
deviceIdAttrs
- IotGateway implementation specific attributes
that identify a device.public IotDevice getIotDevice(java.util.Map<java.lang.String,java.lang.String> deviceIdAttrs)
IotDevice
for a connected device.
No external validation of the attribute values is performed.
See getIotDeviceId(Map)
for the required attribute keys.
getIotDevice
in interface IotGateway
deviceIdAttrs
- IotGateway implementation specific attributes
that identify a device.public IotDevice getIotDevice(java.lang.String fqDeviceId)
IotGateway
IotDevice
for a connected device.getIotDevice
in interface IotGateway
fqDeviceId
- a value from IotDevice.getDeviceId()
.public TSink<com.google.gson.JsonObject> eventsForDevice(Function<com.google.gson.JsonObject,java.lang.String> fqDeviceId, TStream<com.google.gson.JsonObject> stream, Function<com.google.gson.JsonObject,java.lang.String> eventId, UnaryOperator<com.google.gson.JsonObject> payload, Function<com.google.gson.JsonObject,java.lang.Integer> qos)
IotGateway
Events for a particular device can also be published via its
IotDevice.events()
.
eventsForDevice
in interface IotGateway
fqDeviceId
- function to supply the device-id that the event is associated with.stream
- Stream to be published.eventId
- function to supply the event identifier.payload
- function to supply the event's payload.qos
- function to supply the event's delivery Quality of Service.public TSink<com.google.gson.JsonObject> eventsForDevice(java.lang.String fqDeviceId, TStream<com.google.gson.JsonObject> stream, java.lang.String eventId, int qos)
IotGateway
Events for a particular device can also be published via its
IotDevice.event()
.
eventsForDevice
in interface IotGateway
fqDeviceId
- Device-id that the event is associated with.stream
- Stream to be published.eventId
- Event identifier.qos
- Event's delivery Quality of Service.public TStream<com.google.gson.JsonObject> commandsForDevice(java.util.Set<java.lang.String> fqDeviceIds, java.lang.String... commands)
IotGateway
deviceIds
matching commands
will
result in a tuple on the stream. The JSON object has these keys:
device
- Command's opaque target device's id String.
command
- Command identifier as a Stringtsms
- Timestamp of the command in milliseconds since the 1970/1/1 epoch.format
- Format of the command as a Stringpayload
- Payload of the command
format
is json
then payload
is JSONpayload
is StringcommandsForDevice
in interface IotGateway
fqDeviceIds
- Filter to include commands for the specified deviceIds
If the set is empty no filtering occurs. The commands for any device are included.commands
- Command identifiers to include. If no command identifiers are provided then the
stream will contain all device commands for the specified devices.public TStream<com.google.gson.JsonObject> commandsForDevice(java.lang.String fqDeviceId, java.lang.String... commands)
IotGateway
deviceId
matching commands
will
result in a tuple on the stream. The JSON object has these keys:
device
- Command's target device's opaque id String.
command
- Command identifier as a Stringtsms
- Timestamp of the command in milliseconds since the 1970/1/1 epoch.format
- Format of the command as a Stringpayload
- Payload of the command
format
is json
then payload
is JSONpayload
is String
Equivalent to commandsForDevice(Collections.singleton(deviceId)), ...
.
commandsForDevice
in interface IotGateway
fqDeviceId
- Filter to include commands for the specified deviceIdcommands
- Command identifiers to include. If no command identifiers are provided then the
stream will contain all device commands for the specified device.public TStream<com.google.gson.JsonObject> commandsForType(java.lang.String deviceTypeId, java.lang.String... commands)
IotGateway
deviceTypeId
matching commands
will result in a tuple on the stream. The JSON object has these keys:
device
- Command's target device's opaque id String.
command
- Command identifier as a Stringtsms
- Timestamp of the command in milliseconds since the 1970/1/1 epoch.format
- Format of the command as a Stringpayload
- Payload of the command
format
is json
then payload
is JSONpayload
is String
An IoT connector implementation may throw
UnsupportedOperationException
if it does not support this capability. See the implementation's documentation.
commandsForType
in interface IotGateway
deviceTypeId
- Only return commands for connected devices with the specified
device type id value (a value from IotDevice.getDeviceType()
).commands
- Command identifiers to include. If no command identifiers are provided then the
stream will contain all device commands for devices with the specified device type id.public com.ibm.iotf.client.gateway.GatewayCallback setExternalCallbackHandler(com.ibm.iotf.client.gateway.GatewayCallback handler)
GatewayCallback
handler.handler
- the handler to call. May be null.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2017 The Apache Software Foundation. All Rights Reserved - 4744f56-20170226-1707