real-time web programming with prismtech vortex web

33
Real-Time Web Programming with Vortex-Web Angelo Corsaro, PhD Chief Technology Officer [email protected]

Upload: prismtech

Post on 10-May-2015

658 views

Category:

Software


2 download

DESCRIPTION

The Real-Time Web is rapidly growing and as a consequence an increasing number of applications require soft-real time interactions with the server-side as well as with peer web applications. In addition, real-time web technologies are experiencing swift adoption in traditional systems as a means of providing portable and ubiquitously accessible thin client applications. In spite of this trend, few high level communication frameworks exist that allow efficient and timely data exchange between web applications as well as with the server-side and the back-end system. Vortex Web is one of the first technologies to bring the powerful OMG Data Distribution Service (DDS) abstractions to the world of HTML5 / JavaScript applications. With Vortex Web, HTML5 / JavaScript applications can seamlessly and efficiently share data in a timely manner amongst themselves as well as with any other kind of device or system that supports the standard DDS Interoperability wire protocol (DDSI). This presentation will (1) introduce the key abstractions provided by Vortex Web, (2) provide an overview of its architecture and explain how Vortex Web uses Web Sockets and Web Workers to provide low latency and high throughput, and (3) get you started developing real-time web applications.

TRANSCRIPT

Page 1: Real-Time Web Programming with PrismTech Vortex Web

Real-Time Web Programming with Vortex-Web

Angelo  Corsaro,  PhD  Chief  Technology  Officer  

[email protected]

Page 2: Real-Time Web Programming with PrismTech Vortex Web

Vortex

Page 5: Real-Time Web Programming with PrismTech Vortex Web

Vortex Web

Page 13: Real-Time Web Programming with PrismTech Vortex Web

dds.js Overview

Page 21: Real-Time Web Programming with PrismTech Vortex Web

Cop

yrig

ht P

rism

Tech

, 201

4

DataCache Operations

# Writes a data sample into the cache corresponding to the key k !write: (k, data)!!# Returns a list representing the content of the cache ordered by key.!read()!!# Returns a list representing the last sample for each key!readLast()!!# Returns a list representing the content of the cache ordered by key. !# The data is actually removed from the cache.!take()!!# Returns a list representing the last sample for each key!# The data is actually removed from the cache.!takeLast()

Page 24: Real-Time Web Programming with PrismTech Vortex Web

Cop

yrig

ht P

rism

Tech

, 201

4

DataCache Operations

# Folds the content of the data cache using z as “zero” for the folding function f!# For instance, assuming that the operator “+” is defined for the elements of !# the cache, then you could compute the sum of all elements doing:!# c.fold(0)((a, v) -> a + v)!# the product by: !# c.fold(1)((a, v) -> a * v)!# a comma separated string representation of the content:!# c.fold(“”)(a, v) -> a + “, “ + v!fold(z)(f) !!# Register a listener l to be notified whenever data which matches a !# predicate p is written into the cache. If no predicate is provided !# then the listeners is always notified upon data insertion.!addListener(l, p)!!

Page 25: Real-Time Web Programming with PrismTech Vortex Web

Hacking Time!

Page 27: Real-Time Web Programming with PrismTech Vortex Web

Cop

yrig

ht P

rism

Tech

, 201

4

The Chat CoffeeScript#  Create  useful  alias  for  coffez  and  jQuery  root  =  this  z_  =  coffez  $  =  jQuery  !server  =  “ws://demo-­‐eu.prismtech.com:9999"  !#  The  post  type  used  by  the  chat  application  class  Post      constructor:  (@name,  @msg)  -­‐>  !#  Create  the  runtime  runtime  =  new  dds.runtime.Runtime()  !#  Define  the  Post  topic  used  to  send  and  receive  chat  posts  postTopic  =  new  dds.Topic(0,    "Post")  !#  Define  the  QoS  for  the  DataReader/Writer  drQos  =  new  dds.DataReaderQos(dds.Reliability.Reliable)  dwQos  =  new  dds.DataWriterQos(dds.Reliability.Reliable)  

Page 28: Real-Time Web Programming with PrismTech Vortex Web

Cop

yrig

ht P

rism

Tech

, 201

4

The Chat CoffeeScriptpostReader  =  z_.None  postWriter  =  z_.None  !avatar  =  "avatar"  +  Math.floor((Math.random()  *  10000)  +  1);  !#  Add  post  to  the  chat  and  format  it  to  show  it  is  from  me  createMyPost  =  (post)  -­‐>  ...    !#  Add  post  to  the  chat  and  format  it  to  show  it  is  from  others  createOtherPost  =  (post)  -­‐>  ...    !#  Add  post  to  the  chat  and  format  it  to  show  it  is  from  others  processPost  =  ()  -­‐>      msg  =  $("#ChatMessage").val()      post  =  new  Post(avatar,  msg)      #  Publish  the  post  (notice  that  postWriter  is  an  Option  Monad)      #  Take  a  look  at  (http://en.wikibooks.org/wiki/Haskell/Understanding_monads/Maybe)      #  or  (http://www.scala-­‐lang.org/api/2.11.0/index.html#scala.Option)      postWriter.map((dw)  -­‐>  dw.write(post))      $("#ChatMessageList").append(createMyPost(post))      $("#ChatMessage").val("")  !

Page 29: Real-Time Web Programming with PrismTech Vortex Web

Cop

yrig

ht P

rism

Tech

, 201

4

The Chat CoffeeScript#  Deal  with  click  and  keys  events…  !$("#ChatMessage").keyup(          (e)  -­‐>              if(e.keyCode  is  13)  then  processPost()  )  !!$("#SendMsgButton").click(      (evt)  -­‐>          console.log("Send  Button  has  been  clicked")          processPost()  )  !$("#SelectAvatarButton").click(      (evt)  -­‐>          s  =  $("#AvatarName").val()          if  (s  isnt  "")              avatar  =  s  )  

Page 30: Real-Time Web Programming with PrismTech Vortex Web

Cop

yrig

ht P

rism

Tech

, 201

4

The Chat CoffeeScript#  Handle  the  runtime  onconnect  event  runtime.onconnect  =  ()  -­‐>      #  Create  DataReader  and  DataWriter  for  our  posts      dr  =  new  dds.DataReader(runtime,  postTopic,  drQos)      dw  =  new  dds.DataWriter(runtime,  postTopic,  dwQos)  !    #  Register  a  listener  with  the  data  reader  to  post  messages        #  in  our  chat      dr.addListener(          (post)  -­‐>              if  (post.name  isnt  avatar)                  $("#ChatMessageList").append(createOtherPost(post)))      postReader  =  z_.Some(dr)      postWriter  =  z_.Some(dw)  !connectRuntime  =  ()  -­‐>      $("#AvatarName").val(avatar)      runtime.connect(server,  "uid:pwd")  !$(document).ready(()  -­‐>  connectRuntime())