+ All Categories
Home > Technology > Practical ERSync

Practical ERSync

Date post: 07-May-2015
Category:
Upload: wo-community
View: 667 times
Download: 0 times
Share this document with a friend
Description:
ERSync is a framework that syncs data between iOS devices and REST services built with Project Wonder.
41
MONTREAL JUNE 30, JULY 1ST AND 2ND 2012 Practical ERSync 1 David Aspinall Global Village Consulting Inc.
Transcript
Page 1: Practical ERSync

MONTREAL JUNE 30, JULY 1ST AND 2ND 2012

MONTREAL JUNE 30, JULY 1ST AND 2ND 2012

Practical ERSync

1

David AspinallGlobal Village Consulting Inc.

Page 2: Practical ERSync

Outline

1

2

3

4

Sync Overview

Integrating with WebObjects

Integrating with iOS

Development Plan2

Page 3: Practical ERSync

Introduction

• Who am I

• David Aspinall

• Developer / Consultant for Global Village Consulting Inc.

3

Page 4: Practical ERSync

Why ERSync?

• Why not REST/SOAP/...

• Framework to simplify data distribution to mobile apps

• Contribute to the WOCommunity

• Leverage for my clients and projects

4

Page 5: Practical ERSync

Sync Objective

The goal is to make 2 disconnected sets of data match

.. as quickly as possible

.. in a way the user expects

5

Objective-Sync

Page 6: Practical ERSync

What is Sync

6

Page 7: Practical ERSync

What is that cloud?

Dropbox

iCloud Miracles

7

Page 8: Practical ERSync

We are Wonder-ful

Design Objectives

• Leverage our WO experience, products and services.

• Minimally impact our existing code base.

• No server database changes in existing business system.

• No sprinkling of interfaces or special logic in current system

• Simple client protocol and supporting library

8

Page 9: Practical ERSync

What is ERSync

9

?WO App

ERRest

ERSync

Page 10: Practical ERSync

Integrating with WebObjects

• Built on ERRest (routes, transport ...)

• EOObjectStoreCoordinator.ObjectsChangedInStoreNotification

• No model changes required in existing system

• ERSync database can be different schema, host or database

• All relevant data changes must notify the sync engine

• framework is linked in, turned on

• distributed change notification (ERChangeNotificationJMS)

10

Page 11: Practical ERSync

The Easy Partpublic class Application extends ERXApplication {

public static void main(String[] argv) { ERXApplication.main(argv, Application.class); }

public Application() { ERXApplication.log.info("Welcome to " + name() + " !"); /* ** put your initialization code in here ** */ ERXDatabaseContextMulticastingDelegate.addDefaultDelegate(new ERXEntityDependencyOrderingDelegate());

ERXSyncHandler syncHandler = new ERXSyncHandler(); syncHandler.setSyncAuthenticator(new SyncAuthenticationProvider());

ERXSyncHandler.register(syncHandler); }}

11

Page 12: Practical ERSync

What did that do?

• ERXSyncHandler extends ERXRouteRequestHandler

• creates REST routes

• adds change notification observer

• Sync Authenticator

• this is the gateway class between ERSync and your Application

12

Page 13: Practical ERSync

Sync Authenticator

• authenticates a user by username and password

• does NOT implement authentication, it should call your logic

• provides list of Sync’able Entity Names

• provide all EOKeyGlobalID’s for a given user

• basically CRUD processor

13

Page 14: Practical ERSync

Sync Authenticatorpublic interface ERXSyncAuthenticator

{ public ERXSyncUser userForCredentials(String nme,String pwd, EOEditingContext ec);

public NSArray<String> syncEntityNames(); public NSArray<EOKeyGlobalID> syncObjectsForEntityUser(String entityName, ERXSyncUser usr, EOEditingContext ec);

public EOEnterpriseObject syncInsertObject(EOEditingContext editingContext, EOEntity eoEntity, NSDictionary dict, ERXSyncUser user);

public void syncUpdateObject(EOEnterpriseObject eo, NSDictionary dict, ERXSyncUser user);

public void syncDeleteObject(EOEnterpriseObject eo, ERXSyncUser user); }

14

Page 15: Practical ERSync

ERSync tracking

15

ERSyncEntitytoken

status

uuid

updatedDate

Token•Must be able to reconstruct the EO•Cannot be a FK because we need to track deletes•Currently using

•EntityName:pk[-pk*]•Note:1000001

•Planning to change it to URI•ersync://EntityName/pk[/pk*]•ersync://Note/100001•ersync://Compound/10001/4432

Page 16: Practical ERSync

ERSync tracking

16

ERSyncEntitytoken

status

uuid

updatedDate

StatusV - Virgin - never by sync’dI - InsertedU - UpdatedD - Deleted

Page 17: Practical ERSync

ERSync tracking

17

ERSyncEntitytoken

status

uuid

updatedDate

UUID• The Database agnostic, universally unique id• Clients will ALWAYS provide a UUID

• usually the UUID assigned by the server• where the client inserts, it assigns the

UUID and leaves the token blank• Removes primary key distribution and

collision problems

Page 18: Practical ERSync

Change Notification Process

18

ERSyncChangeset

uuidupdatedDate

ERSyncChangeValue

attibuteNamevalueType

ERSyncChangeBooleanbooleanValue

ERSyncChangeIntegerintValue

ERSyncChangeStringbooleanValue

ERSyncEntity

tokenstatusuuid

updatedDate

ERSyncChangeToOnetoOneValue

ERSyncChangeToManyM-M

ERSyncChange .. Float ..

Double .. BLOB ..

ERSyncAuthRef

tokenuuidname

M-M

Page 19: Practical ERSync

ERSyncPrincipal

deviceUUIDprincipalUUIDlastSyncDate

ERSyncAuthRef

tokenuuidname

ERSync API Security

19

ERSyncClientDevice

disablenameuuid

ERSyncClientDeveloper

disablenameuuid

ERSyncClientApplication

disablenameuuid

Page 20: Practical ERSync

Integrating with iOS

• Very similar to the WO approach

• Built on GVC Open frameworks

20

Page 21: Practical ERSync

The Easy Part- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{! [super application:application didFinishLaunchingWithOptions:launchOptions];

! [self setEngine:[[SyncEngine alloc] ! ! initWithEditingContext:[self managedObjectContext]]];

! [[self engine] addSupportedEntity:[Note entityName]];! [[self engine] addSupportedEntity:[Category entityName]];

! [self setPrincipal:[SyncPrincipal ! ! ! pseudoSingletonInContext:[self managedObjectContext]];

return YES;}

21

Page 22: Practical ERSync

What did that do?

• SyncEngine is the client version of ERXSyncHandler

• adds change notification observer for main context

• SyncPrincipal

• Core Data record to store configuration information.

22

Page 23: Practical ERSync

iOS Model

23

SyncChangeset

uuidupdatedDate SyncChangeValue

attibuteNamevalueType

value

ERSyncEntity

tokennamestatusuuid

updatedDate

SyncPrincipal

usernamepassword

site

principaluuid lastSync toOneValue

toManyValueM-M

Page 24: Practical ERSync

Client Process

1. Registration

2. Initial / Full / Slow Sync

3. Delta / Fast Sync

24

Page 25: Practical ERSync

Client Process - Registration

• Links the client application and device to a user on the server

• must provide server assigned

• application UUID

• device Type UUID

• provide client assigned and locally stored

• device UUID

• user credentials

25

<registration> <appid> 5AC343C6-2C35-4BB0-9A00-CE2938A12260

</appid> <deviceType> 743E2D47-DDA4-4827-A164-0C61547CD4D5

</deviceType> <deviceUUID> D9781163-2A97-4E90-B978-DE2B9F86A9D5

</deviceUUID> <user>david</user> <password>tester</password></registration>

Page 26: Practical ERSync

Client Process - Registration

• server response provides

• principal UUID

• last Sync date (only if previously sync’d)

26

<sync> <principalUUID> dce87db1-0e87-44b6-9680-19dcd672eadb </principalUUID> <lastSync type = "datetime"> 2012-06-30T10:25:10Z </lastSync></sync>

Page 27: Practical ERSync

Client Process - Sync

• Client initiates communication

• sends principal UUID and last Sync

• data in the Insert / Update / Delete order

27

<sync> <principalUUID> dce87db1-0e87-44b6-9680-19dcd672eadb

</principalUUID> <lastSync>2012-06-30T09:39:11Z</lastSync>

<data> <Note id="EA3E9977-8B58-40FE-85CF-4E4027723DF8" status="update"> <subject>My new subject</subject> <category> <Category id="Category:1000000" /> </category>...

Page 28: Practical ERSync

Client Process - Sync

• Server response

• echo principal UUID

• provides new last Sync date

• data in the Insert / Update / Delete order

28

<sync> <principalUUID> dce87db1-0e87-44b6-9680-19dcd672eadb

</principalUUID> <lastSync>2012-06-30T09:55:11Z</lastSync>

<data> <Reminder id="EA3E9977-8B58-40FE-85CF-4E4027723DF8" status="update"> <name>Get Siri off my back</name> <type> <ReminderType id="ReminderType:active"/> </type>...

Page 29: Practical ERSync

We are Wonder-ful

Design Objectives

✓ Leverage our WO experience, products and services.

✓ Minimally impact our existing code base.

✓ No server database changes in existing business system.

✓ No sprinkling of interfaces or special logic in current system

✓ Simple client protocol and supporting library

29

Page 30: Practical ERSync

Development Plan - WO

• Add support for Additional Change Value Types

• float, double, char .. scalar types

• BLOB, CLOB, LOB .. SLOBs

30

Page 31: Practical ERSync

Development Plan - WO

• Track the SyncEntity status per Principal

• a principal represents a client/device combo

• entity status can be different on each device

31

• Add support for Additional Change Value Types

Page 32: Practical ERSync

Development Plan - WO

• Purge Changesets once all Principals have sync’d

• if all the registered client/devices have the change then it is not needed

• new registrations will be ‘Virgin’ and require the current record anyway. (ERSync is not a History engine)

32

• Add support for Additional Change Value Types

• Track the Entity status per Principal

Page 33: Practical ERSync

Development Plan - WO

• Make SyncEntity a composite of several EOEntity types

• Related but De-normalized data

• virtual entity for non-relational data (images/thumbnails)

33

• Add support for Additional Change Value Types

• Track the Entity status per Principal

• Purge Changesets once all Principals have sync’d

Page 34: Practical ERSync

Development Plan - WO

• Allow the client to sync a subset of data

• date range (example bank transactions in 30 day window)

• data group (example Toronto address book as a window into a larger address book)

34

• Add support for Additional Change Value Types

• Track the Entity status per Principal

• Purge Changesets once all Principals have sync’d

• Make SyncEntity a composite of several EOEntity types

Page 35: Practical ERSync

Development Plan - iOS

• Clean up the iOS ERSync framework

• ARC and Block compatible

• ERBranding

• Sync related UI components?

35

Page 36: Practical ERSync

Development Plan - iOS

• ERSyncEngine

• Does not need to process anything until registration

• Manage operations automatically

• detect errors/resets from server and perform full sync cycle

36

• Clean up the iOS ERSync framework

Page 37: Practical ERSync

Development Plan - iOS

• Multiple CoreData model migration

1. merged models cannot be migrated automatically

2. Individual Stores cannot be migrated automatically

37

• Clean up the iOS ERSync framework

• ERSyncEngine

Page 38: Practical ERSync

Q&A

MONTREAL JUNE 30, JULY 1ST AND 2ND 2012

MONTREAL JUNE 30, JULY 1ST AND 2ND 2012

38

Page 39: Practical ERSync

Web Resources

• Source is currently available at:

https://github.com/davidAtGVC/RemoteSync

• The iOS projects have submodule references for the GVC Open kits:

https://github.com/davidAtGVC/GVCFoundation https://github.com/davidAtGVC/GVCUIKit https://github.com/davidAtGVC/GVCCoreData

39

Page 40: Practical ERSync

40

Start

Session

Negotiate Mode

Should Push

Push

Should Pull

Pull

Stop

No - Login

Yes

No

YesYes

No

Source: Apple Sync Services Programming Guide

The sync process overview

1 2 3

Page 41: Practical ERSync

Why is this important

• Data != Files • Pass the TTC test

41


Recommended