450 likes | 803 Views
Data Synchronization with SyncML * and sync4j. Sean C. Sullivan <sean> at <seansullivan> <.com>. Agenda. Data synchronization SyncML sync4j Q & A. What is data synchronization?. Data synchronization “is the process of making two sets of data look identical” (syncml.org whitepaper).
E N D
Data Synchronization with SyncML* and sync4j Sean C. Sullivan <sean> at <seansullivan> <.com>
Agenda • Data synchronization • SyncML • sync4j • Q & A
What is data synchronization? Data synchronization “is the process of making two sets of data look identical” (syncml.org whitepaper)
Datastore1 A B C • Data modifications A B C A B C Data Synchronization Datastore2 • Conflict resolution
What is a “data synchronization protocol”? • Communication syntax and semantics for a data synchronization session • Protocol includes: • naming and identification of records • common protocol commands • identification and resolution of synchronization conflicts
SyncML defined… “SyncML is a new industry initiative to develop and promote a single, common data synchronization protocol that can be used industry-wide.” (syncml.org) “SyncML is a specification for a common data synchronization framework and XML-based format […] for synchronizing data on networked devices.” (syncml.org) “SyncML is a […] protocol for conveying data synchronization operations.” (syncml.org)
server modifications client modifications SyncML: clients & servers SyncML server
SyncML data identification Server Client
SyncML Synchronization Types • Two-way sync • Slow sync • One-way sync from client only • Refresh sync from client only
SyncML Synchronization Types (cont.) • One-way sync from server only • Refresh sync from server only • Server alerted sync
SyncML features • Synchronize any type of data • Multiple protocol bindings • HTTP, WSP, OBEX • Security • Interoperability
SyncML terminology • Message • Package • Command • Status code • Datastore • Device Info • Meta Info • Capabilities exchange
SyncML and XML • Abbreviated naming convention • Ex: ”protocol version” is <VerProto> • XML prolog is not required • WBXML • WAPBinary XML
SyncML documents • <SyncML> DTD • Meta info DTD • Device info DTD
<?xml version="1.0"?> <!DOCTYPE … > <SyncML> <SyncHdr> … </SyncHdr> <SyncBody> … </SyncBody> </SyncML> “A SyncML Message is a well-formed, but not necessarily valid, XML document.” (syncml.org) Contains data synchronization commands (operations) <SyncML> document
<SyncHdr> element <SyncHdr> <VerDTD>1.0</VerDTD> <VerProto>1.0</VerProto> <SessionID>session41</SessionID> <MsgID>msg80386</MsgID> … </SyncHdr>
<SyncBody> element <SyncBody> <Delete> <CmdID>cmd80486</CmdID> … <Item>…</Item> </Delete> </SyncBody>
Contains sync session parameters <MetInf> <Format>…</Format> <Type>…</Type> … <MaxMsgSize>586 </MaxMsgSize> … </MetInf> Meta Info document
Describes device capabilities For both client and server <DevInf> … <SwV>0.99</SwV> <HwV>3.14</HwV> … <DevTyp>pda</DevTyp> … </DevInf> Device Info document
SyncML commands • Put • Replace • Results • Search • Sequence • Status • Sync • Add • Alert • Atomic • Copy • Delete • Exec • Get • Map
sync4j • Java implementation of SyncML protocol • sync4j client & sync4j Server • open source • designed for J2SE platform • http://sync4j.sourceforge.net
Open source licensing • Licensing options: • GPL? • LGPL? • BSD? • Apache Public License? • JDOM public license? • Mozilla Public License (MPL)? • sync4j license is virtually identical to JDOM license
sync4j audience • developers who know Java but don’t know SyncML • developers who know SyncML but may not know Java • commercial application developers & open source application developers
API design ideas • SAX API • standard set of interfaces • multiple implementations • usage model: callbacks • JDOM API • concrete classes; single implementation • root Document object contains Element objects
API design ideas (cont.) • Servlet API • usage model: developer builds a new servlet by subclassing HTTPServlet • Auto-generate classes from DTD using an XML data-binding tool?? • Sun’s JAXB • Enhydra’s Zeus
Design goals • Hide complexity of the SyncML specification from Java programmers • XML documents, XML parsing • multiple transport protocols • A complete SyncML implementation • Interoperability • with existing SyncML clients & servers
Design goals (cont.) • API should be natural and familiar to Java programmers • direct object instantiation • exceptions • use Collection API / arrays, where appropriate • event notification via event listeners • familiar naming conventions
Design goals (cont.) • API must be familiar to developers who already know the SyncML DTD’s • API must enforce any restrictions that are defined in the SyncML specification • Target platform: J2SE
Design goals (cont.) • Modular design: • “core” protocol support • transport protocol libraries • extensible client framework • extensible server framework • client application • server application
sync4j implementation • Immutable objects • Exception class for each SyncML “status code” • Declaration of constants • public final static variables • Command object hierarchy
sync4j command hierarchy AbstractCommand RequestCommand ResponseCommand AddCommand, DeleteCommand, ReplaceCommand, … ResultsCommand, StatusCommand,
sync4j packages • sync4j.core • sync4j.client • sync4j.server • sync4j.http • sync4j.wsp • sync4j.obex • sync4j.tests
sync4j key classes • SyncMLMessage • DeviceInfo • MetaInfo • Command classes: • AddCommand • DeleteCommand • ReplaceCommand
sync4j.core.SyncMLMessage • Two ways to construct: • from a String of XML • from more basic sync4j objects
SyncMLMessage example 1 String strXML = “<SyncML> … </SyncML>”; SyncMLMessage msg; try { msg = new SyncMLMessage(strXML); } catch (InvalidSyncMLException ex) { } catch (XMLSyntaxException ex) { }
SyncMLMessage example 2 SyncHeader header = new SyncHeader(...); SyncBody body = new SyncBody(...); SyncMLMessage msg; msg = new SyncMLMessage(header, body); String strXML = msg.toXML();
Algorithms • Base64 • encode, decode • WBXML • encode, decode • MD5 • java.security.MessageDigest
sync4j future issues • Compliance testing, interoperability tests • move to JDK 1.4? • Assert facility • Java Logging API • New I/O classes: java.nio • SSL class library
Summary • SyncML is both complex and powerful • sync4j hides the complexity of SyncML from Java programmers • The sync4j API is consistent with many familiar Java programming idioms • http://sync4j.sourceforge.net/
Data Synchronization with SyncML* and sync4j Sean C. Sullivan <sean> at <seansullivan> <.com>
SyncML authentication • <Chal> • <Cred> • Authentication types: • basic • MD5