SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Pushing Oracle Coherence
 Events to Web Browsers
using HTML 5 WebSockets
       and Kaazing

     Steve Millidge
        © C2B2 Consulting Limited 2012
             All Rights Reserved
Agenda
•   What is Web Sockets
•   Review Coherence Events
•   Demo Configuration
•   Code




                © C2B2 Consulting Limited 2012
                     All Rights Reserved
Web Sockets
• Enables Full Duplex Communication
  between a browser and a Server
• Allows Web Servers to push updates to
  browsers
• Better than “long polling”
• Establishes a Dedicated Socket to the
  Backend Web Socket Server

               © C2B2 Consulting Limited 2012
                    All Rights Reserved
Server Sent Events
• Sent by the Server to the Browser
  – Uni-directional
• Sent over standard HTTP
  – Content Type is text/event-stream
• Supports only Text
• Easier to fallback to Long Polling
• Browser handles reconnect

                  © C2B2 Consulting Limited 2012
                       All Rights Reserved
Web Sockets and Standards
• This is all in flux
• Rfc 6455 defines the
  protocol
• W3C SSE
  http://dev.w3.org/html
  5/eventsource/
• W3C WebSockets
  http://dev.w3.org/html
  5/websockets/

                  © C2B2 Consulting Limited 2012
                       All Rights Reserved
WebSocket Protocol
Client                              Server
GET /chat HTTP/1.1                  HTTP/1.1 101 Switching
Host: server.example.com            Protocols Upgrade: websocket
Upgrade: websocket                  Connection: Upgrade Sec-
Connection: Upgrade                 WebSocket-Accept:
Sec-WebSocket-Key:                  s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
dGhlIHNhbXBsZSBub25jZQ==            Sec-WebSocket-Protocol: chat
Origin: http://example.com
Sec-WebSocket-Protocol:
chat, superchat
Sec-WebSocket-Version: 13




                     © C2B2 Consulting Limited 2012
                          All Rights Reserved
JS API
Web Socket                            Server Sent Events
WebSocket(location,protocol)          EventSource(location)

Function   onmessage                  Function onmessage
Function   onopen                     Function onopen
Function   onclose                    Function onerror
Function   onerror

close()
send(data)




                       © C2B2 Consulting Limited 2012
                            All Rights Reserved
Coherence Events Subsystem
Application    Application              Application       Application



      Map        Cache                     Cache            Cache
    Listener



  Cache




                         © C2B2 Consulting Limited 2012
                              All Rights Reserved
Events Code
MapListener listener = new MultiplexingMapListener() {
public void onMapEvent(MapEvent evt) {
   // do something with the trader
   }
};

NamedCache mapTrades = ...
 Filter filter =
    new AndFilter(new EqualsFilter("getTrader", traderid),
    new EqualsFilter("getStatus", Status.OPEN));

mapTrades.addMapListener(listener, new
MapEventFilter(filter), true);



                      © C2B2 Consulting Limited 2012
                           All Rights Reserved
Events
• E_ALL                            • E_UPDATED_LEFT
  – All Events                          – Updated and now not
• E_INSERTED                              matched
  – Inserts                        • E_UPDATED_WITHIN
• E_DELETED                             – Updated still matched
  – Deletes                        • E_KEYSET
• E_UPDATED                             – All updated which change
                                          the matching set
  – Updated
• E_UPDATED_ENTERED
  – Updated and now matched


                    © C2B2 Consulting Limited 2012
                         All Rights Reserved
Asynch Push to the UI
          ORCL                                            ORCL



         Applicati    Applicati   Applicati   Applicati   Applicati   Applicati   Applicati
          Cach
         on            Cach
                      on           Cach
                                  on           Cach
                                              on           Cach
                                                          on           Cach
                                                                      on           Cach
                                                                                  on
          e            e           e           e           e           e           e



         Applicati    Applicati   Applicati   Applicati   Applicati   Applicati   Applicati
          Cach
         on            Cach
                      on           Cach
                                  on           Cach
                                              on           Cach
                                                          on           Cach
                                                                      on           Cach
                                                                                  on
          e            e           e           e           e           e           e


Price
         Applicati    Applicati   Applicati   Applicati   Applicati   Applicati   Applicati
Update    Cach
         on            Cach
                      on           Cach
                                  on           Cach
                                              on           Cach
                                                          on           Cach
                                                                      on           Cach
                                                                                  on
          e            e           e           e           e           e           e
ORCL



                                        © C2B2 Consulting Limited 2012
                                             All Rights Reserved
Demo Setup


                                  Internet




            Applicati      Applicati                  KAAZING
             Cach
            on
             e
                            Cach
                           on
                        Update
                            e
                                                       HTML 5
                                                      Gateway

Coherence   Coherence Grid
  Client


                          © C2B2 Consulting Limited 2012
                               All Rights Reserved
Coherence Initialisation
String remoteURL = args[0];
NamedCache cache =
CacheFactory.getCache("conquery");

KaazingStockClient client = new
KaazingStockClient(remoteURL, "conquery");

cache.addMapListener(new StockMapListener(client));




                   © C2B2 Consulting Limited 2012
                        All Rights Reserved
Map Listener
@Override
public void entryUpdated(MapEvent event) {
   if (event.getNewValue() instanceof Stock) {
     System.out.println("Stock : " + event.getKey() + " has been
updated");
      client.pushStockUpdate();
   }
}




                       © C2B2 Consulting Limited 2012
                            All Rights Reserved
Push to Kaazing
// Convert to JSON
JSONArray stocksJson = new JSONArray();
stocksJson.addAll(stocks);

// Push via UDP to KAAZING
URI remoteURI = URI.create(remoteURL);
SocketAddress remoteAddress = new
InetSocketAddress(remoteURI.getHost(),
remoteURI.getPort());
DatagramSocket socket = new DatagramSocket();
byte[] buf = message.getBytes();
DatagramPacket packet = new DatagramPacket(buf,
buf.length, remoteAddress);
socket.send(packet);
                     © C2B2 Consulting Limited 2012
                          All Rights Reserved
Graph JavaScript
var eventSource = new EventSource("http://ec2-46-137-53-
185.eu-west-1.compute.amazonaws.com:8001/sse");

eventSource.onmessage = function(event) {
   var array = JSON.parse(event.data);
   for (var i = 0; i < array.length; i++) {
   var object = array[i];
   var x = (new Date()).getTime();
   var y = object.price;
   document.chart.series[i].addPoint([x,y],true,true);
   }
}



                     © C2B2 Consulting Limited 2012
                          All Rights Reserved
Thank you




© C2B2 Consulting Limited 2012
     All Rights Reserved

Weitere ähnliche Inhalte

Ähnlich wie Pushing Oracle Coherence Events to Web Browsers Using HTML5, Web Sockets and Kaazing

CON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To YouCON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To YouEdward Burns
 
20110507 Implementing Continuous Deployment
20110507 Implementing Continuous Deployment20110507 Implementing Continuous Deployment
20110507 Implementing Continuous DeploymentXebiaLabs
 
EMC World 2015 devops-st06 Containers and Converged Infrastructure Deployment
EMC World 2015 devops-st06 Containers and Converged Infrastructure DeploymentEMC World 2015 devops-st06 Containers and Converged Infrastructure Deployment
EMC World 2015 devops-st06 Containers and Converged Infrastructure DeploymentKendrick Coleman
 
Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422journeyer
 
ECET 340 Entire Course NEW
ECET 340 Entire Course NEWECET 340 Entire Course NEW
ECET 340 Entire Course NEWshyamuopfive
 
FlexVPNLabHandbook-SAMPLE
FlexVPNLabHandbook-SAMPLEFlexVPNLabHandbook-SAMPLE
FlexVPNLabHandbook-SAMPLETariq Sheikh
 
Cloud Foundry Marketplace
Cloud  Foundry MarketplaceCloud  Foundry Marketplace
Cloud Foundry MarketplaceLayne Peng
 
Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2360|Conferences
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...HostedbyConfluent
 
Istio Service Mesh
Istio Service MeshIstio Service Mesh
Istio Service MeshLew Tucker
 
Sadeem cloud native السحابة الطبيعية
Sadeem cloud native السحابة الطبيعيةSadeem cloud native السحابة الطبيعية
Sadeem cloud native السحابة الطبيعيةTaher Boujrida
 
Sustainable Agile Development
Sustainable Agile DevelopmentSustainable Agile Development
Sustainable Agile DevelopmentGabriele Lana
 
VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...
VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...
VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...Jonas Rosland
 
"Quantum" Performance Effects
"Quantum" Performance Effects"Quantum" Performance Effects
"Quantum" Performance EffectsSergey Kuksenko
 
Building Server-Side Eclipse based web applications
Building Server-Side Eclipse based web applicationsBuilding Server-Side Eclipse based web applications
Building Server-Side Eclipse based web applicationsGunnar Wagenknecht
 
Introduction to ActiveMQ Apollo
Introduction to ActiveMQ ApolloIntroduction to ActiveMQ Apollo
Introduction to ActiveMQ Apollodejanb
 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaJAX London
 

Ähnlich wie Pushing Oracle Coherence Events to Web Browsers Using HTML5, Web Sockets and Kaazing (20)

CON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To YouCON5898 What Servlet 4.0 Means To You
CON5898 What Servlet 4.0 Means To You
 
20110507 Implementing Continuous Deployment
20110507 Implementing Continuous Deployment20110507 Implementing Continuous Deployment
20110507 Implementing Continuous Deployment
 
EMC World 2015 devops-st06 Containers and Converged Infrastructure Deployment
EMC World 2015 devops-st06 Containers and Converged Infrastructure DeploymentEMC World 2015 devops-st06 Containers and Converged Infrastructure Deployment
EMC World 2015 devops-st06 Containers and Converged Infrastructure Deployment
 
Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422Kamaelia-ACCU-20050422
Kamaelia-ACCU-20050422
 
CloudKit
CloudKitCloudKit
CloudKit
 
ECET 340 Entire Course NEW
ECET 340 Entire Course NEWECET 340 Entire Course NEW
ECET 340 Entire Course NEW
 
FlexVPNLabHandbook-SAMPLE
FlexVPNLabHandbook-SAMPLEFlexVPNLabHandbook-SAMPLE
FlexVPNLabHandbook-SAMPLE
 
Cloud Foundry Marketplace
Cloud  Foundry MarketplaceCloud  Foundry Marketplace
Cloud Foundry Marketplace
 
Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2Samuel Asher Rivello - PureMVC Hands On Part 2
Samuel Asher Rivello - PureMVC Hands On Part 2
 
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
Apache Kafka’s Transactions in the Wild! Developing an exactly-once KafkaSink...
 
Istio Service Mesh
Istio Service MeshIstio Service Mesh
Istio Service Mesh
 
Sadeem cloud native السحابة الطبيعية
Sadeem cloud native السحابة الطبيعيةSadeem cloud native السحابة الطبيعية
Sadeem cloud native السحابة الطبيعية
 
Sustainable Agile Development
Sustainable Agile DevelopmentSustainable Agile Development
Sustainable Agile Development
 
2015 Q4 webrtc standards update
2015 Q4 webrtc standards update2015 Q4 webrtc standards update
2015 Q4 webrtc standards update
 
VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...
VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...
VMworld 2015 San Francisco - INF5432 - Infrastructure as Code - Ban Snowflake...
 
"Quantum" Performance Effects
"Quantum" Performance Effects"Quantum" Performance Effects
"Quantum" Performance Effects
 
Introducing CQ 5.1
Introducing CQ 5.1Introducing CQ 5.1
Introducing CQ 5.1
 
Building Server-Side Eclipse based web applications
Building Server-Side Eclipse based web applicationsBuilding Server-Side Eclipse based web applications
Building Server-Side Eclipse based web applications
 
Introduction to ActiveMQ Apollo
Introduction to ActiveMQ ApolloIntroduction to ActiveMQ Apollo
Introduction to ActiveMQ Apollo
 
HTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun GuptaHTML5 Websockets and Java - Arun Gupta
HTML5 Websockets and Java - Arun Gupta
 

Mehr von C2B2 Consulting

Hands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandHands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandC2B2 Consulting
 
Monitoring Oracle SOA Suite
Monitoring Oracle SOA SuiteMonitoring Oracle SOA Suite
Monitoring Oracle SOA SuiteC2B2 Consulting
 
Advanced queries on the Infinispan Data Grid
Advanced queries on the Infinispan Data Grid Advanced queries on the Infinispan Data Grid
Advanced queries on the Infinispan Data Grid C2B2 Consulting
 
Building WebLogic Domains With WLST
Building WebLogic Domains With WLSTBuilding WebLogic Domains With WLST
Building WebLogic Domains With WLSTC2B2 Consulting
 
Hands-on Performance Workshop - The science of performance
Hands-on Performance Workshop - The science of performanceHands-on Performance Workshop - The science of performance
Hands-on Performance Workshop - The science of performanceC2B2 Consulting
 
Jsr107 come, code, cache, compute!
Jsr107 come, code, cache, compute!Jsr107 come, code, cache, compute!
Jsr107 come, code, cache, compute!C2B2 Consulting
 
JBoss Clustering on OpenShift
JBoss Clustering on OpenShiftJBoss Clustering on OpenShift
JBoss Clustering on OpenShiftC2B2 Consulting
 
Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...
Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...
Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...C2B2 Consulting
 
Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at Scale
Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at ScaleOracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at Scale
Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at ScaleC2B2 Consulting
 
Java Middleware Surgery
Java Middleware Surgery Java Middleware Surgery
Java Middleware Surgery C2B2 Consulting
 
Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...
Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...
Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...C2B2 Consulting
 
'Deploying with GlassFish & Docker'
'Deploying with GlassFish & Docker' 'Deploying with GlassFish & Docker'
'Deploying with GlassFish & Docker' C2B2 Consulting
 
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit' 'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit' C2B2 Consulting
 
'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel Deakin'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel DeakinC2B2 Consulting
 
Coherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-webCoherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-webC2B2 Consulting
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleC2B2 Consulting
 
GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy C2B2 Consulting
 

Mehr von C2B2 Consulting (20)

Hands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx PolandHands-on Performance Tuning Lab - Devoxx Poland
Hands-on Performance Tuning Lab - Devoxx Poland
 
Monitoring Oracle SOA Suite
Monitoring Oracle SOA SuiteMonitoring Oracle SOA Suite
Monitoring Oracle SOA Suite
 
Advanced queries on the Infinispan Data Grid
Advanced queries on the Infinispan Data Grid Advanced queries on the Infinispan Data Grid
Advanced queries on the Infinispan Data Grid
 
Through the JMX Window
Through the JMX WindowThrough the JMX Window
Through the JMX Window
 
Building WebLogic Domains With WLST
Building WebLogic Domains With WLSTBuilding WebLogic Domains With WLST
Building WebLogic Domains With WLST
 
Hands-on Performance Workshop - The science of performance
Hands-on Performance Workshop - The science of performanceHands-on Performance Workshop - The science of performance
Hands-on Performance Workshop - The science of performance
 
Jsr107 come, code, cache, compute!
Jsr107 come, code, cache, compute!Jsr107 come, code, cache, compute!
Jsr107 come, code, cache, compute!
 
JBoss Clustering on OpenShift
JBoss Clustering on OpenShiftJBoss Clustering on OpenShift
JBoss Clustering on OpenShift
 
Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...
Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...
Dr. Low Latency or: How I Learned to Stop Worrying about Pauses and Love the ...
 
Through the JMX Window
Through the JMX WindowThrough the JMX Window
Through the JMX Window
 
Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at Scale
Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at ScaleOracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at Scale
Oracle Coherence & WebLogic 12c Web Sockets: Delivering Real Time Push at Scale
 
Java Middleware Surgery
Java Middleware Surgery Java Middleware Surgery
Java Middleware Surgery
 
Jax London 2013
Jax London 2013Jax London 2013
Jax London 2013
 
Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...
Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...
Oracle SOA Suite Performance Tuning- UKOUG Application Server & Middleware SI...
 
'Deploying with GlassFish & Docker'
'Deploying with GlassFish & Docker' 'Deploying with GlassFish & Docker'
'Deploying with GlassFish & Docker'
 
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit' 'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
'JMS @ Data Grid? Hacking the Glassfish messaging for fun & profit'
 
'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel Deakin'New JMS features in GlassFish 4.0' by Nigel Deakin
'New JMS features in GlassFish 4.0' by Nigel Deakin
 
Coherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-webCoherence sig-nfr-web-tier-scaling-using-coherence-web
Coherence sig-nfr-web-tier-scaling-using-coherence-web
 
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at ScaleJUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
JUDCon 2013- JBoss Data Grid and WebSockets: Delivering Real Time Push at Scale
 
GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy GeeCon- 'www.NoSQL.com' by Mark Addy
GeeCon- 'www.NoSQL.com' by Mark Addy
 

Pushing Oracle Coherence Events to Web Browsers Using HTML5, Web Sockets and Kaazing

  • 1. Pushing Oracle Coherence Events to Web Browsers using HTML 5 WebSockets and Kaazing Steve Millidge © C2B2 Consulting Limited 2012 All Rights Reserved
  • 2. Agenda • What is Web Sockets • Review Coherence Events • Demo Configuration • Code © C2B2 Consulting Limited 2012 All Rights Reserved
  • 3. Web Sockets • Enables Full Duplex Communication between a browser and a Server • Allows Web Servers to push updates to browsers • Better than “long polling” • Establishes a Dedicated Socket to the Backend Web Socket Server © C2B2 Consulting Limited 2012 All Rights Reserved
  • 4. Server Sent Events • Sent by the Server to the Browser – Uni-directional • Sent over standard HTTP – Content Type is text/event-stream • Supports only Text • Easier to fallback to Long Polling • Browser handles reconnect © C2B2 Consulting Limited 2012 All Rights Reserved
  • 5. Web Sockets and Standards • This is all in flux • Rfc 6455 defines the protocol • W3C SSE http://dev.w3.org/html 5/eventsource/ • W3C WebSockets http://dev.w3.org/html 5/websockets/ © C2B2 Consulting Limited 2012 All Rights Reserved
  • 6. WebSocket Protocol Client Server GET /chat HTTP/1.1 HTTP/1.1 101 Switching Host: server.example.com Protocols Upgrade: websocket Upgrade: websocket Connection: Upgrade Sec- Connection: Upgrade WebSocket-Accept: Sec-WebSocket-Key: s3pPLMBiTxaQ9kYGzzhZRbK+xOo= dGhlIHNhbXBsZSBub25jZQ== Sec-WebSocket-Protocol: chat Origin: http://example.com Sec-WebSocket-Protocol: chat, superchat Sec-WebSocket-Version: 13 © C2B2 Consulting Limited 2012 All Rights Reserved
  • 7. JS API Web Socket Server Sent Events WebSocket(location,protocol) EventSource(location) Function onmessage Function onmessage Function onopen Function onopen Function onclose Function onerror Function onerror close() send(data) © C2B2 Consulting Limited 2012 All Rights Reserved
  • 8. Coherence Events Subsystem Application Application Application Application Map Cache Cache Cache Listener Cache © C2B2 Consulting Limited 2012 All Rights Reserved
  • 9. Events Code MapListener listener = new MultiplexingMapListener() { public void onMapEvent(MapEvent evt) { // do something with the trader } }; NamedCache mapTrades = ... Filter filter = new AndFilter(new EqualsFilter("getTrader", traderid), new EqualsFilter("getStatus", Status.OPEN)); mapTrades.addMapListener(listener, new MapEventFilter(filter), true); © C2B2 Consulting Limited 2012 All Rights Reserved
  • 10. Events • E_ALL • E_UPDATED_LEFT – All Events – Updated and now not • E_INSERTED matched – Inserts • E_UPDATED_WITHIN • E_DELETED – Updated still matched – Deletes • E_KEYSET • E_UPDATED – All updated which change the matching set – Updated • E_UPDATED_ENTERED – Updated and now matched © C2B2 Consulting Limited 2012 All Rights Reserved
  • 11. Asynch Push to the UI ORCL ORCL Applicati Applicati Applicati Applicati Applicati Applicati Applicati Cach on Cach on Cach on Cach on Cach on Cach on Cach on e e e e e e e Applicati Applicati Applicati Applicati Applicati Applicati Applicati Cach on Cach on Cach on Cach on Cach on Cach on Cach on e e e e e e e Price Applicati Applicati Applicati Applicati Applicati Applicati Applicati Update Cach on Cach on Cach on Cach on Cach on Cach on Cach on e e e e e e e ORCL © C2B2 Consulting Limited 2012 All Rights Reserved
  • 12. Demo Setup Internet Applicati Applicati KAAZING Cach on e Cach on Update e HTML 5 Gateway Coherence Coherence Grid Client © C2B2 Consulting Limited 2012 All Rights Reserved
  • 13. Coherence Initialisation String remoteURL = args[0]; NamedCache cache = CacheFactory.getCache("conquery"); KaazingStockClient client = new KaazingStockClient(remoteURL, "conquery"); cache.addMapListener(new StockMapListener(client)); © C2B2 Consulting Limited 2012 All Rights Reserved
  • 14. Map Listener @Override public void entryUpdated(MapEvent event) { if (event.getNewValue() instanceof Stock) { System.out.println("Stock : " + event.getKey() + " has been updated"); client.pushStockUpdate(); } } © C2B2 Consulting Limited 2012 All Rights Reserved
  • 15. Push to Kaazing // Convert to JSON JSONArray stocksJson = new JSONArray(); stocksJson.addAll(stocks); // Push via UDP to KAAZING URI remoteURI = URI.create(remoteURL); SocketAddress remoteAddress = new InetSocketAddress(remoteURI.getHost(), remoteURI.getPort()); DatagramSocket socket = new DatagramSocket(); byte[] buf = message.getBytes(); DatagramPacket packet = new DatagramPacket(buf, buf.length, remoteAddress); socket.send(packet); © C2B2 Consulting Limited 2012 All Rights Reserved
  • 16. Graph JavaScript var eventSource = new EventSource("http://ec2-46-137-53- 185.eu-west-1.compute.amazonaws.com:8001/sse"); eventSource.onmessage = function(event) { var array = JSON.parse(event.data); for (var i = 0; i < array.length; i++) { var object = array[i]; var x = (new Date()).getTime(); var y = object.price; document.chart.series[i].addPoint([x,y],true,true); } } © C2B2 Consulting Limited 2012 All Rights Reserved
  • 17. Thank you © C2B2 Consulting Limited 2012 All Rights Reserved