Callback: onResourceReadRequest

Last modified: Jul 5, 2019 @ 06:43

This callback notifies the gateway implementation that DDM wants to read the value of a resource.

The implementation is expected to respond with a ResourceReadResponse and to send the value calling gateway.sendResourceObservationValue(senMlObject);

The following is an example implementation of the callback:

@Override
public void onResourceReadRequest(String correlationId, String endpoint, ResourceLink resourceLink) {
  // Get the device by the endpoint value and read the resource
  ResponseCode responseCode = new ResponseCode(ResponseCode.CONTENT, "Reading resource was easy.");
  try {
    getGateway().sendResourceReadResponse(correlationId, endpoint, responseCode);
  } catch (GatewayException e) {
    logger.log(Level.WARNING, "Failed to send response to DDM", e);
  }

  SenMlObject senMlObject = new SenMlObject();
  senMlObject.setBaseName(endpoint);
  senMlObject.setBaseTime(System.currentTimeMillis() / 1000); // unix timestamp UTC in 
SECONDS!

  SenMlEntry senMlEntry = new SenMlEntry();
  senMlEntry.setName(resourceLink.getUrl());
  senMlEntry.setStringValue("Hello!");
  senMlObject.addEntry(senMlEntry);

  try {
    getGateway().sendResourceObservationValue(senMlObject);
  } catch (GatewayException e) {
    logger.log(Level.WARNING, "Failed to send measurement to DDM", e);
  }
}

The following message sequence chart shows the Resource Read process.