28
EWD.js Architecture Rob Tweed M/Gateway Developments Ltd Twitter: @rtweed Email: [email protected] Tuesday, 18 February 14

EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Architecture

Rob TweedM/Gateway Developments Ltd

Twitter: @rtweedEmail: [email protected]

Tuesday, 18 February 14

Page 2: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Architecture

2

Tuesday, 18 February 14

Page 3: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Architecture

3

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

Tuesday, 18 February 14

Page 4: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Architecture

4

Child Process returned to available pool as soonas processing is completed

Tuesday, 18 February 14

Page 5: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Architecture

5

Each Child process handles only one request at a time

Tuesday, 18 February 14

Page 6: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Development

6

100%JavaScript

Tuesday, 18 February 14

Page 7: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

7

EventOccurs

Tuesday, 18 February 14

Page 8: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

8

JSONMessageCreated

Tuesday, 18 February 14

Page 9: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

9

MessageSent

Tuesday, 18 February 14

Page 10: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

10

MessageReceived

atback-end

Tuesday, 18 February 14

Page 11: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

11

MessageHandler

fired

Tuesday, 18 February 14

Page 12: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

12

_setDocument()

Tuesday, 18 February 14

Page 13: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

13

_getDocument()

Tuesday, 18 February 14

Page 14: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

14

Messagesentby

back-end

Tuesday, 18 February 14

Page 15: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

15

MessageReceived

bybrowser

Tuesday, 18 February 14

Page 16: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

16

JSONMessage

EventHandler

Fires

Tuesday, 18 February 14

Page 17: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

EWD.js Messaging

17

ModifyUI

Tuesday, 18 February 14

Page 18: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

Send message from browser

18

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

Tuesday, 18 February 14

Page 19: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 20: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 21: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 22: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 23: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 24: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 25: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 26: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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

Page 27: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

Secured Linked Systems

27

Tuesday, 18 February 14

Page 28: EWD and the Art of Mobile Application Developmentgradvs1.mgateway.com/download/EWDjsArchitecture.pdf · Node.js, but Synchronous Code! • Your back-end code runs in a Node.js Child

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