[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

[S8] Object Sharing

Framework to share objects between S8 and other Smalltalk systems (e.g. VSE systems).

The transfer of an object (source object) is realized converting the object to a literal string that will be sent to target system for interpretation.
The target system will parse the literal string and build a copy of the source object on target system.
The process of building the object on target system is an adaption to the rules of the target system, so the object can suffer transformations (e.g. OrderedCollection instances are transformed to instance of S8 Array; TimeStamp instances are converted to DateTime instances etc, etc).
During the conversion/adaption we can loose of presition, time (e.g. Sets are rehashed) and/or information in the process (Dictionaries are transformed to PoolDictionaries).

The process can be mediated by a file system and/or any communication link.
The same communication medium can be used to transfer multiple objects (in an array) or sequence (a series of objects sent in multiple transfer operations).

The low level formating of data is in JSON format (by default, using the native support if it is detected, or implemented internally by the framework in pure Smalltalk).

Using the framework

It is required to load the Object sharing framework in both systems.
If your system will emmit objects to other systems you need to load the Stringifier.
If your system will receive/load data from other Smalltalk system; you need to load the Objectifier.
Both are required to receive and send objects to other systems.

The first step in sending an object to another system is to stringify the object and then send the string result to the other system.
The first step in loading a stringified object sent by another system is to instantiate an Objectifier and use the result of parsing the string.

Expression to serialize anObject to string literal

Stringifier @ anObjectReturns the string literal to be sent to target to obtain a copy of anObject

Sample expressions to obtain anObject from string literal

Objectifier @ aStringReturns the object read from aString (string literal)
(Objectifier from: #VSE) objectFrom: aStringReturns an object read from aString literal that has been stringified in a VSE system.
An error is triggered if the object has not been stringified in a VSE system

Tests

We built the Stringifier and Objectifier as usual, using our s8-media swiki, and multiple smalltalk systems (VSE runtimes, and S8 running in internet browsers and mobile devices running native).
As usual, the tests embedded in s8-media swiki pages can be run instantly from any S8 system (evaluating testing expression and/or scanning QR code with your iOS or Android U8 tools app).

The tests are good to learn how to use and customize the framework.

See Test pages

Customizing the Stringifier/Objectifier

In most cases nothing is required to be customized to transfer objects.
But in case you want to modify how the objects are encoded and/or decoded, subclassing can be used; it is good to use events and direct parametrization just after instantiating the stringifier/objectifier.

When planning the extensions/changes you need for your objects consider:
  1. the events triggered while processing (see implementation of #constructEventsTriggered on class side)
  2. the internals of Stringifier/Objectifier used for mappings

Structure of Stringifier
origina Symbol specifying the type of the system from where the object has been served
objectHandlers A dictionary used to set the strategy used to map instances of a class. See implementation of #initializeXXXObjectHandlers to learn how to add custom mappings

Structure of Objectifier
originA symbol, the type of the system that produced the literal
namesIt is a map used to instantiate objects from a class name (the name has been specified by source system and can happen that the real class do not exist here). The value liked to a class name can be a Symbol/String of an existing class or a block to produce a new instance.
See implementation of #setDefaultXXXNames
transformsA map to transform objects while reading structural data.
See implementation of #setDefaultXXXTransforms
nativesInternal - A pool with platform dependent strategies used during parsing. Not ethat we have the same code for all smalltalk implementations, we use this pool to run platform dependent actions.

ToDo list:




Drafts