== Resource Access Interface ==
There is no single resource access interface in the SENSEI architecture, instead each resource description published by a REP includes information about the interface(s) available to access it, for example the URL and interface description. In order for Resource Users to easily access resources, a set of well-known resource interfaces have been defined for sensor, parameter, actuator and code-update resource types.
How to connect to these URLs using REST is described in the [[RuConnecting| Connecting a Resource User ]] section.
A short example of how a response looks like is this:
{{{
#!xml
}}}
All responses are in the XML-RDF format so that the Semantic Query Analyser can work with them.
How a Resource User gets this reference is by either querying an SQR or an RD. (see [[RuRli| the
RLI Interface). Of course another way would be to browse an RD directly (/rd url) and to read all
resources available, but this works well only for small systems.
The URL is provided by the Rep-Locator entry of the Resource Directory Description.
A resource may have one or more such urls, and even publish URL behind company proxies.
{{{
#!xml
http://195.178.44.184/rephandler/gps/358278005846910
}}}
It is up to the client to detect if it will use IPv6 or IPv4 addresses and to select
the best connected resource.
The whole RD entry looks like this:
{{{
#!xml
−
urn:sensei:ericsson.com:EnvironmentalSensors:busgps:358278005846910
Bus Location Sensors in Belgrade
6
11-01-01T00:00:00+00:00
Bus
GPS
Sensor
Belgrade
24
358278005846910
−
0
GET returns sensor values (RDF)
−
http://195.178.44.184/rephandler/gps/358278005846910
}}}
By using URLs to get sensor data, you can enforce AAA and Billing easily and you can use any language to query the resource. Ofcouse, you have to parse XML. A small example of a RAI Client is the monitoring plugin of the WP4 Check Service.
{{{
#!java
/**
*
res:hasDecimalValue="26.80"
*
* @see lia.util.DynamicThreadPoll.SchJob#doProcess()
*/
@Override
public Object doProcess() throws Exception {
if (configGet == null) {
return null;
}
Vector results = new Vector();
HashMap sensors = configGet.getSensorUrls();
for (String name : sensors.keySet()) {
URL url = sensors.get(name);
String sResult = configGet.post(url, null);
String sPattern = "res:hasDecimalValue=\"((.)*)\"";
Pattern pattern = Pattern.compile(sPattern,
Pattern.UNIX_LINES | Pattern.DOTALL);
Matcher matcher = pattern.matcher(sResult);
try {
if (matcher.find()) {
String data = matcher.group(1);
if (data != null) {
Double value = new Double(data);
//Store Result
Result result = new Result(Node.getFarmName(),
Node.getClusterName(),
name, ModuleName, ResTypes);
result.time = System.currentTimeMillis();
result.param[0] = value;
results.add(result);
if (logger.isLoggable(Level.INFO)) {
logger.info("" + result.toString());
}
}
}
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
}
}
return results;
}
}}}