EWD and the Art of Mobile Application...

Post on 03-Aug-2020

1 views 0 download

transcript

EWD.js Architecture

Rob TweedM/Gateway Developments Ltd

Twitter: @rtweedEmail: rtweed@mgateway.com

Tuesday, 18 February 14

EWD.js Architecture

2

Tuesday, 18 February 14

EWD.js Architecture

3

Child Process removed from available poolas soon as a request is sent to it

Tuesday, 18 February 14

EWD.js Architecture

4

Child Process returned to available pool as soonas processing is completed

Tuesday, 18 February 14

EWD.js Architecture

5

Each Child process handles only one request at a time

Tuesday, 18 February 14

EWD.js Development

6

100%JavaScript

Tuesday, 18 February 14

EWD.js Messaging

7

EventOccurs

Tuesday, 18 February 14

EWD.js Messaging

8

JSONMessageCreated

Tuesday, 18 February 14

EWD.js Messaging

9

MessageSent

Tuesday, 18 February 14

EWD.js Messaging

10

MessageReceived

atback-end

Tuesday, 18 February 14

EWD.js Messaging

11

MessageHandler

fired

Tuesday, 18 February 14

EWD.js Messaging

12

_setDocument()

Tuesday, 18 February 14

EWD.js Messaging

13

_getDocument()

Tuesday, 18 February 14

EWD.js Messaging

14

Messagesentby

back-end

Tuesday, 18 February 14

EWD.js Messaging

15

MessageReceived

bybrowser

Tuesday, 18 February 14

EWD.js Messaging

16

JSONMessage

EventHandler

Fires

Tuesday, 18 February 14

EWD.js Messaging

17

ModifyUI

Tuesday, 18 February 14

Send message from browser

18

EWD.sockets.sendMessage({ type: "sendHelloWorld", params: { text: 'Hello World!', sender: 'Rob', date: new Date().toUTCString() } });

Tuesday, 18 February 14

Back-end Module

19

module.exports = { onMessage: { sendHelloWorld: function(payload, ewd) { // do whatever is required with payload return {received: true}; // or any JSON } }};

Tuesday, 18 February 14

Back-end Module

20

module.exports = { onMessage: { sendHelloWorld: function(payload, ewd) { // eg save payload to JSON store var store = new ewd.mumps.GlobalNode('myStore', [1]); store._setDocument(payload); return {savedInto: ‘myStore’}; } }};

Tuesday, 18 February 14

Browser-side Handler

21

onMessage { sendHelloWorld: function(msgObject) { // do whatever you need to do with the incoming message, eg: var text = 'Your message was successfully saved into ' + messageObj.message.savedInto; toastr.clear(); toastr.info(text); } };

Tuesday, 18 February 14

No Polling!

• With WebSockets, the back-end can send a message at any time to:– a specific browser– all browsers running a specific EWD.js

application– all currently-connected browsers

22

Tuesday, 18 February 14

Back-end can send a message

23

var savedMsg = new ewd.mumps.GlobalNode('myMessage', []); ewd.sendWebSocketMsg({ type: 'savedMessage', message: savedMsg._getDocument() });

Tuesday, 18 February 14

Node.js, but Synchronous Code!

• Your back-end code runs in a Node.js Child Process

• An EWD.js Child Process only handles a single request at a time so it can afford to use blocking, synchronous I/O

• If all Child Processes are busy, incoming requests are queued in the fully asynchronous master Node.js process

• Child Process pool size is configurable to match demand

24

Tuesday, 18 February 14

Node.js, but Synchronous Code!

• Database connector interfaces used by EWD.js are synchronous

• Your back-end JavaScript logic can be written in easy-to-maintain, intuitive synchronous style

• No “callback hell” or pseudo-synchronous syntax

• Result: faster development, maintainable JavaScript logic

25

Tuesday, 18 February 14

Built-in secured Web Services

• Any back-end EWD.js JavaScript method can also be exposed as a JSON Web Service

• Access is automatically secured– HMAC-SHA256 digital signatures required for

every HTTP request– The same security used by Amazon Web

Services• Lightweight peer-to-peer access between

EWD.js systems 26

Tuesday, 18 February 14

Secured Linked Systems

27

Tuesday, 18 February 14

EWD.js requirements

• Ideally browsers that support HTML5 WebSockets– however, EWD.js uses Node.js socket.io

library• emulates websockets using other techniques if not

available• even works with old versions of Internet Explorer!

28

Tuesday, 18 February 14