Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Getting Started with Sun Java System RFID  : Page 3

Using Sun Java System RFID, you can build a highly customized Radio Frequency Identification (RFID) application or service that meets your specific needs.


advertisement
Handling Application-level Events with ALE
Sun Java System RFID offers an abstraction of Application-level Events (ALE) defined by the EPCglobal specification in the com.sun.autoid.ale.AleAPI interface. Classes implementing this interface (you'll find it in sun-alesvc-common.jar) embody support for handling Application-level Events.

The EPCglobal Application-level Events (ALE) specification (also known as collection and filtering), is a Web service specification with a WSDL file that defines operations to define, configure, and request reports. It also defines an XML schema for reports and report requests.

Sun provides a default implementation of the AleAPI interface in the com.sun.autoid.ale.client.ALEClient class, installed when you select the ALE custom option during installation of the RFID Event Manager. You will find this class in the /rfidem/lib/sun-rfid-common.jar file, where SUN_RFID_HOME is the directory where you installed Sun Java System RFID.

The ALEClient class constantly searches for all readers on the system and maintains an up-to-date list of physical and logical names. The code you'll see below illustrates how to use the ALEClient class to support the ALE specification.

The Sun Java RFID Software implements an ALE Web service using Java API for XML-based RPC (JAX-RPC). This service acts as an intermediary to a Jini RMI service contained within the RFID Event Manager. Requests and messages sent to this Web service are referred to as "report requests" and "report messages" respectively, and are implemented as Plain old Java objects (POJOs).

The ALE Web service supports three basic modes of interaction with clients: subscription, polling predefined ECSpecs, and polling a new ECSpec.

The following line of code connects to the ALE service specified by the ENDPOINT_ADDRESS parameter:

ALEClient aleClient = new ALEClient(ENDPOINT_ADDRESS);

The ALE API defines two configuration objects: an Event Cycle Specification (ECSpec) and a Report Specification (ECReportSpec). When interacting with the ALE Web service, you must provide it with an ECSpec (a "define") that describes an event cycle (the smallest unit of interaction between the ALE Web service and a client) by specifying the boundary (when to start and stop collecting data), the logical readers from which to receive data, and one or more ECReportSpecs. The system collects data during an event cycle. After an event cycle boundary has completed, the system groups and filters the data, and then generates reports.

private static ECSpec defineECSpec(String specStr, ALEClient aleClient, String ecSpecName) { ECSpec ecSpec = null; try { ecSpec = xmlUtil.getSPEC(specStr); aleClient.define(ecSpecName, ecSpec); System.out.println("Define of ECSpec: " + ecSpecName + " succeeded"); } catch (Exception e) { System.out.println("Define of ECSpec: " + ecSpecName + " failed"); System.err.println(e.getMessage()); } return ecSpec; } private static void undefineECSpec(ALEClient aleClient, String ecSpecName) { try { aleClient.undefine(ecSpecName); System.out.println("Undefine succeeded"); } catch (Exception e) { System.err.println("ECSpec undefine failed"); System.err.println(e.getMessage()); } }

The Subscribe mode of interaction requires the ECSpec to be defined ahead of time. Then a client adds a subscription to the ECSpec with which the ALE Web services communicates.



private static void subscribeECSpec(ALEClient aleClient, String ecSpecName, String outputFilePath) { try { aleClient.subscribe(ecSpecName, outputFilePath); System.out.println("ECSpec: " + ecSpecName + " subscribe Succeeded"); } catch (Exception e) { System.err.println("ECSpec: " + ecSpecName + " subscribe failed"); System.err.println(e.getMessage()); } } private static void unsubscribeECSpec(ALEClient aleClient, String ecSpecName, String outputFilePath) { try { aleClient.unsubscribe(ecSpecName, outputFilePath); System.out.println("ECSpec: " + ecSpecName + " unsubscribe succeeded"); } catch (Exception e) { System.err.println("ECSpec: " + ecSpecName + " unsubscribe failed"); System.err.println(e.getMessage()); } }

The Immediate mode of interaction demands that the ECSpec must be processed and fulfilled immediately, for example, when the ECSpecs first event cycle boundary completes.

private static ECReports executeSpecImmediately( String specStr, ALEClient aleClient) { ECReports reports = null; try { ECSpec ecSpec = xmlUtil.getSPEC(specStr); reports = aleClient.immediate(ecSpec); } catch (Exception e) { System.err.println("Execute failed"); System.err.println(e.getMessage()); } return reports; }

The Poll mode of interaction is similar to Immediate, except that the ECSpec is defined on the server beforehand and given a name, letting clients request data from it using the name rather than continually resending the ECSpec.

private static ECReports pollForReports( ALEClient aleClient, String ecSpecName) { try { return aleClient.poll(ecSpecName); } catch (Exception e) { System.err.println("Poll reports failed"); System.err.println(e.getMessage()); } return null; }

You can retrieve ancillary data and reports from the ALE Web service, as the following methods illustrate.

private static List retrieveSubscribers(ALEClient aleClient, String ecSpecName) { List subscribers = null; try { subscribers = aleClient.getSubscribers(ecSpecName); } catch (Exception e) { System.err.println("ECSpec: " + ecSpecName + " subscribers retrieval failed"); System.err.println(e.getMessage()); } return subscribers; } private static ECSpec retrieveSpec(ALEClient aleClient, String ecSpecName) { ECSpec ecSpec = null; try { ecSpec = aleClient.getECSpec(ecSpecName); } catch (Exception e) { System.err.println("ECSpec retrieval for " + ecSpecName + " failed"); System.err.println(e.getMessage()); } return ecSpec; } private static List getSpecNames(ALEClient aleClient) { try { List specNames = aleClient.getECSpecNames(); return specNames; } catch (Exception e) { System.err.println("SpecNames fetch failed"); System.err.println(e.getMessage()); } return new ArrayList(); } private static String getVendorVersion(ALEClient aleClient) { try { return aleClient.getVendorVersion(); } catch (Exception e) { System.err.println("VendorVersion failed"); System.err.println(e.getMessage()); } return ""; } private static String getStandardVersion(ALEClient aleClient) { try { return aleClient.getStandardVersion(); } catch (Exception e) { System.err.println("StandardVersion failed"); System.err.println(e.getMessage()); } return ""; }



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap