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 Connecting a Resource User section. A short example of how a response looks like is this:
<rdf:RDF> <nmib:Location mo:direction="B" mo:hasTimeStamp="17 Oct 2010 12:57:00" mo:latitude="44.8300183" mo:line="24" mo:longitude="20.4559783" mo:nextStationDistance="42.11" mo:nextStationID="B14" mo:nextStationName="Dorcol" rdf:about="http://www.resource-provider-456.com/resources#location"/> </rdf:RDF>
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.
<REP-Locator> http://195.178.44.184/rephandler/gps/358278005846910 </REP-Locator>
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:
<Resource-Description> − <Resource-ID> urn:sensei:ericsson.com:EnvironmentalSensors:busgps:358278005846910 </Resource-ID> <Name>Bus Location Sensors in Belgrade</Name> <Storage-ID>6</Storage-ID> <Expiration-Time>11-01-01T00:00:00+00:00</Expiration-Time> <Tag>Bus</Tag> <Tag>GPS</Tag> <Tag>Sensor</Tag> <Tag>Belgrade</Tag> <Tag>24</Tag> <Tag>358278005846910</Tag> − <RAI-Description> <RAI-ID>0</RAI-ID> <Description>GET returns sensor values (RDF)</Description> − <REP-Locator> http://195.178.44.184/rephandler/gps/358278005846910 </REP-Locator> </RAI-Description> </Resource-Description>
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.
/** * <p>res:hasDecimalValue="26.80"</p> * * @see lia.util.DynamicThreadPoll.SchJob#doProcess() */ @Override public Object doProcess() throws Exception { if (configGet == null) { return null; } Vector<Result> results = new Vector<Result>(); HashMap<String,URL> 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; }