270 likes | 562 Views
XML-Tuples & XML-Spaces V0.7. By David “Uncle Dave” Moffat. Presented by: Shurug Al-Khalifa. Outline. Overview of Tuple Spaces and XML-Spaces. Basic XML-Spaces & XML-Tuples operations. Database operations on XML-Spaces. Extended Database Queries on XML-Spaces. Introduction.
E N D
XML-Tuples & XML-Spaces V0.7 By David “Uncle Dave” Moffat Presented by: Shurug Al-Khalifa
Outline • Overview of Tuple Spaces and XML-Spaces. • Basic XML-Spaces & XML-Tuples operations. • Database operations on XML-Spaces. • Extended Database Queries on XML-Spaces.
Introduction • Implementation of tuples and tuple-spaces using XML. • Tuple list of values (“Sam”, 7, 48.1). • Tuple Space public repository that contains tuples. • Template tuple set up for matching. • Using XML for the tuples and the commands.
Definitions • XML-tuple list of data fields in an XML format. • Data field XML-tagged data. <name> Ralph </name> • XML-tuple field values are strings. • XML-space tuple space with XML tuples. • An XML-space: • Referenced by a name. • Located on a server.
Creating and Communicating with an XML-Space • “do” method. • Commands and parameters expressed in XML. XMLSpace xs = new XMLSpace (“MySpace”,“server.mine.org”);
Writing XML-Tuples to an XML-Space String strTuple=“<write>”+ “ <name>Ralph</name>”+ “ <age>33</age>”+ “ <weight>190.7</weight>”+ “</write>”; String strResult; strResult=xs.do(strTuple); • Returns with<tuple> • If error, message with<error>
Writing Several XML-Tuples at Once • Concatenate several<write>into one string. <write> <name>Ralph</name> <age>33</age> <weight>190.7</weight> </write> <write> : </write>
Matching XML-Tuples • Create a template. • Template XML-Tuple where fields may or may not have value in them.
Reading XML-Tuples from an XML-Space • Read only. • Match a template. <read> <name/> <age>33</age> <weight/> </read> • Returns with<tuple> • If not Found, NULLis returned. • If error, message with<error>
Reading XML-Tuples from an XML-Space • Read and remove. • Match a template. <take> <name/> <age>33</age> <weight/> </take> • Returns with<tuple> • If not Found,NULLis returned. • If error, message with<error>
Reading XML-Tuples from an XML-Space • If client has to find a match. • Read <waitToRead> • Read and remove <waitToTake> • xs.doreturns: • Tuple if a match is found. • If a match is not found, waits until tuple exists then returns it.
Reading Several XML-Tuples at Once • Read only. • Match a template. <scan> <name/> <age>33</age> <weight/> </scan> • Returns list of tuples with<tuple> • If not Found,NULLis returned. • If error, message with<error>
Reading Several XML-Tuples at Once • Read and remove. • Match a template. <scanTake> <name/> <age>33</age> <weight/> </scanTake> • Returns list of tuples with<tuple> • If not Found, NULLis returned. • If error, message with<error>
Counting the Number of Matching XML-Tuples • Match a template. <count> <name/> <age>33</age> <weight/> </count> • Returns number of tuples found with<count> • If error, message with<error>
Registering for XML-Space Events • Event operation on an XML-space. • . XMLSpaceListener interface. • . Register as a Listener. • . Give a template to the space.
Registering for XML-Space Events • . XMLSpaceListener interface. Interface XMLSpaceListener { handleXMLSpaceEvent(String tuple, String space, String host, long lNum, boolean bErr); } • If error, message with<error> in “tuple”.
Template Registering for XML-Space Events • . Register as a Listener. • . Give a template to the space. xs.addXMLSpaceListner(this,tplt) • Can register for different operations and templates
XML-Space Queries • Basic query = scan <query> <name/> <age>33</age> <weight/> </query> • Returns a tuple or a list of tuples with<tuple> • If not Found, NULLis returned. • If error, message with<error>
ANDing XML-Space Queries • Match with two given query templates. <andQuery> <query> : </query> <query> : </query> </andQuery> • Returns a tuple or a list of tuples with<tuple> • If not Found, NULLis returned. • If error, message with<error>
ORing XML-Space Queries • Match with one or both given query templates. <orQuery> <query> : </query> <query> : </query> </orQuery> • Returns a tuple or a list of tuples with<tuple> • If not Found, NULLis returned. • If error, message with<error>
Range Queries • Match with values within template range. <rangeQuery> <query> : </query> <query> : </query> </rangeQuery> • Returns a tuple or a list of tuples with<tuple> • If not Found, NULLis returned. • If error, message with<error> Lower Limit Upper Limit
Nested Queries <orQuery> <andQuery> <query> : </query> <query> : </query> </andQuery> <rangeQuery> <query> : </query> <query> : </query> </rangeQuery> </orQuery>
XML-Space Transactions • Used to perform an operation only if it is successful. <transaction/> <write> : </write> <write> : </write> • Everything is OK <commit/> • Anything is unsuccessful <abort/>
Matching to Different “Depths” • A field: - have content but not subfields. <age>33</age> - be Null and have subfields. <name> <first>Karl</first> <last>Martin</last > </name> - have content and subfields. <phone>123 456 789 <ext>221</ext> </phone>
Partial XML-Tuple Templates • Partial Template does not specify all the fields or the subfields. <name/> <address> <city>Ann Arbor</city> </address> <phone> <ext/> </phone>
Partial XML-Tuple Templateswith Wildcards • Used to match upper-level fields of template. • Breadth-wise<*/> <address> <city>Ann Arbor</city> </address> • Depth-wise<*> <address> <city>Ann Arbor</city> </address> </*>
Conclusion • Tuple Spaces and XML-Spaces. • Operations on XML-Spaces & XML-Tuples. • Querying XML-Spaces.