SlideShare a Scribd company logo
Reverse Ajax
Techniques, libraries and support in 2014
Ajax (Asynchronous JavaScript and XML)
• Group of interrelated Web development techniques used on the client-side to
create asynchronous Web applications.
• With Ajax, Web applications can send data to, and retrieve data from a server
asynchronously (in the background) without the need for a page reload.
• It is a browser feature accessible to a web page through the JavaScript.
• Though the name includes XML, nearly anything can be transfered with an Ajax
request.
• The most commonly used data is JSON, which is close to JavaScript syntax and
consumes less bandwidth.
• Ajax requests are stateless by default, and can only be opened from the client to
the server.
Reverse Ajax
• Reverse Ajax is essentially a concept for sending data from the server to the
client.
• It can be simulated with a repeated Ajax request from client – simple polling,
piggyback polling.
• Comet – umbrella term for various techniques for Reverse Ajax
• Coined by Alex Russel in 2006.
• It can be simulated with a long-held Ajax request from client .
• Server can send events to the client without the client specifically requesting it.
• Also known as Ajax Push, Two-way-web, HTTP Streaming, and HTTP server push,
• First implementations appeared in 2000 with Pushlets and LightStreamer media
server
Reverse Ajax
Basic polling techniques
Reverse Ajax – simple polling
Reverse Ajax – simple polling
• Basic Ajax with regular interval requests (every few seconds).
• To get the server events as soon as possible, the polling interval (time between
requests) must be as low as possible.
• If interval is reduced, the client will issue many more requests, many of which
won't return any useful data, and will consume bandwidth and processing
resources for nothing.
• Advantages: It's really easy to implement and does not require any special
features on the server side. It also works in all browsers.
• Disadvantages: This method is rarely employed because it does not scale at all.
Example: 100 clients each issuing polling requests for 2 seconds, where 30% of
the requests returns no data.
Reverse Ajax – piggyback polling
Reverse Ajax – piggyback polling
• Piggyback polling removes all redundant requests (which return no data)
• There is no interval
• Requests are sent when the client needs to send a request to the server
• The difference lies in the response, which is split into two parts:
 the response for the requested data
 server events, if any
• Advantages: Less resource consumption. Works in all browsers, does not
require special features on the server side.
• Disadvantages: You have no clue when the events accumulated on the server
side will be delivered to the client.
Reverse Ajax – Comet
Reverse Ajax – Comet
• Request is sent to the server and kept alive for a long time, until a time-out or
a server event occurs.
• When the request is completed, another long-lived Ajax request is sent to wait
for other server events.
• With Comet, web servers can send the data to the client without having to
explicitly request it.
• The server can push events on the clients by immediately committing
(completing) the responses, or it can accumulate them and send bursts.
• Special features are required on the server side to handle all of these long-lived
requests (Servlet 3.0 or Websockets)
• Implementations of Comet can be separated into two types: those using
streaming mode, and those using long polling.
Reverse Ajax
Comet - Streaming Mode
Comet – Streaming mode
• In streaming mode, one persistent connection is opened
• It requires a way to separate the different responses coming through the same
connection on the client side.
• Technically speaking, two common techniques for streaming include:
 Forever Iframes (hidden Iframes) or
 Multi-part feature of the XMLHttpRequest object used to create Ajax
requests in JavaScript.
Comet – Forever Iframes
• Forever Iframes technique involves a hidden Iframe tag put in the page with its
src attribute pointing to the servlet path returning server events.
• Each time an event is received, the servlet writes and flushes a new script tag
with the JavaScript code inside.
• The iframe content will be appended with this script tag that will get executed.
• Advantages: Simple to implement, and it works in all browsers supporting
iframes.
• Disadvantages: There is no way to implement reliable error handling or to
track the state of the connection, because all connection and data are handled
by the browser through HTML tags. You don't know when the connection is
broken on either side.
Comet – Multi-part XMLHttpRequest
• This technique uses the multi-part flag supported by some browsers (Chrome,
Firefox) on the XMLHttpRequest object.
• An Ajax request is sent and kept open on the server side. Each time an event
comes, a multi-part response is written through the same connection
• On the server side it is required to set up the multi-part request, suspend the
connection and return responses asynchronously (Servlet 3.0)
• Advantages: Only one persistent connection is opened. This is the Comet
technique that saves the most bandwidth usage.
• Disadvantages: The multi-part flag is not supported by all browsers. Some
widely used libraries, such as CometD in Java, reported issues in buffering. For
example, chunks of data (multi-parts) may be buffered and sent only when the
connection is completed or the buffer is full, which can create higher latency
than expected.
Reverse Ajax
Comet - HTTP long polling
Comet - HTTP long polling
• The long polling mode involves techniques that use repeated long-held client
requests.
• When client initiates a connection, it is kept open by the server, and as soon as
an event occurs, the response is committed and the connection is closed.
• New long-polling connection is reopened immediately by the client waiting for
the new events to arrive.
• You can implement HTTP long polling by using
 Script tags
 XMLHttpRequest object.
Comet – Script tags
• Similar to the iframe technique, the goal is to append a script tag in your page
to get the script executed.
• The server will: suspend the connection until an event occurs, send the script
content back to the browser, and then reopen another script tag to get the next
events.
• Advantages: Because it's based on HTML tags, this technique is easy to
implement and works across domains (by default, XMLHttpRequest does not
allow requests on other domains or sub-domains).
• Disadvantages: Similar to the iframe technique, error handling is missing, and
you can't have a state or the ability to interrupt a connection.
Comet - XMLHttpRequest long polling
• Recommended method to implement Comet
• Client opens an Ajax request to the server and waits for the response.
• The server requires specific features on the server side to allow the request to
be suspended (Servlet 3.0).
• As soon as an event occurs, the server sends back the response in the
suspended request and closes it.
• The client then consumes the response and opens a new long-lived Ajax
request to the server.
• On the back end, the code also uses the Servlet 3 API to suspend the request, as
in HTTP streaming, but without multi-part handling.
Comet - XMLHttpRequest long polling
• Advantages: It's easy to implement on the client side with a good error-
handling system and timeout management. This reliable technique also
allows reusing connections on the server side, since connections are not
persistent (a good thing, when you have a lot of clients on your application). It
also works on all browsers; you only make use of the XMLHttpRequest object
by issuing a simple Ajax request.
• Disadvantages: There is no main disadvantage compared to other techniques.
But, like all techniques we've discussed, this one still relies on a stateless HTTP
connection, which requires special features on the server side to be able to
temporarily suspend it.
• Several well-known libraries implement Comet in Java and Javascript:
 DWR
 CometD
 Atmosphere
Reverse Ajax
Libraries
DWR
• DWR – direct web remoting
• Well known library for integration between client-side JS and server-side Java code
• Reverse Ajax Modes
 Early Closing Mode (default, low performance for large number of clients)
 Full Streaming Mode (Not available to IE users)
 Long Polling (best option)
 Piggyback mode
• Advantages: Highly configurable and stable library.
• Disadvantages: Development is slow, Websocket support is uncertain.
Atmosphere
• Atmosphere is a Java technology framework that provides a common API for
using the Comet and WebSocket features of many of the web servers, including
Tomcat, Jetty, GlassFish, Weblogic, Grizzly, JBossWeb, JBoss, and Resin.
• Atmosphere has been around for more than two years, and it is still in active
development. It is used in large web applications such as JIRA
• Advantages: Atmosphere's strength remains on the server side: it provides a
standardized API that covers all of the different solutions and ways to
communicate with WebSockets or Comet.
• Disadvantages: Atmosphere does not use a protocol between the client and
server, like DWR and CometD.
CometD – our choice
• CometD framework is an event-driven communication solution based on HTTP.
It provides a Java server part and a Java client part, plus JavaScript client
libraries based upon jQuery and Dojo.
• It has been around for several years. It supports WebSockets. Reverse Ajax
Mode is implemented with XMLHttpRequest long-polling.
• All of the components communicate through a bus to send notifications and
receive events. All communication is asynchronous.
• Advantages: CometD offers a complete solution, from client and server side, and
also from a standalone Java client to a server. The framework is well-
documented and is easy to use. It supports many features - reconnection,
reliable timeout detection, error handling, low-latency communication ...
• Disadvantages: CometD currently does not support any Servlet 2.5 containers
other than Jetty for Comet (Tomcat), and it does not support Glassfish/Grizzly
WebSocket
Websockets
Overview
Websockets
• WebSockets, which comes from HTML5, is a new technique for bidirectional,
full-duplex communication.
• The connection is opened through a HTTP Upgrade request (HTTP request with
special headers), called a WebSockets handshake.
• The connection is then kept alive, and data is exchanged between both sides
directly.
• Best option for bidirectional communication, future standard
• Supported in Chrome 14+, Firefox 6+, Safari 6+, IE 10+
• Supported on Tomcat 8, JBoss 8, Glassfish 3, Jetty 7
• Supported in CometD along with long polling.
References
IBM Developerworks: Reverse Ajax series
http://www.ibm.com/developerworks/library/wa-reverseajax1/
Javabeat: An introduction to Comet and Reverse Ajax
http://www.javabeat.net/introduction-to-comet-and-reverse-ajax/
DWR: Reverse Ajax
http://directwebremoting.org/dwr/documentation/reverse-ajax/
CometD:
http://docs.cometd.org/reference/
Atmosphere Framework:
http://async-io.org/
References
Oracle: Asynchronous Notifications with Servlet 3.0
http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/async-
servlet/async-servlets.html
Javabeat: Asynchronous Servlet
http://www.javabeat.net/asynchronous-servlet-servlet-3-0/
Google groups: CometD users
https://groups.google.com/forum/#!topic/cometd-users
Wikipedia: Comet
http://en.wikipedia.org/wiki/Comet_(programming)#Implementations
Ad

More Related Content

What's hot (20)

WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
Fabio Tiriticco
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
JeongHun Byeon
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
Ming-Ying Wu
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
NAVER D2
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
Naresh Chintalcheru
 
Using Websockets with Play!
Using Websockets with Play!Using Websockets with Play!
Using Websockets with Play!
Andrew Conner
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comRuby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ilya Grigorik
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
Ilya Grigorik
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
GWTcon
 
Websockets and SockJS, Real time chatting
Websockets and SockJS, Real time chattingWebsockets and SockJS, Real time chatting
Websockets and SockJS, Real time chatting
University of Alabama at Birmingham
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
Fastly
 
Communication in Python and the C10k problem
Communication in Python and the C10k problemCommunication in Python and the C10k problem
Communication in Python and the C10k problem
Jose Galarza
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Java
jfarcand
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSockets
Sergi Almar i Graupera
 
0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services
Ilya Grigorik
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
Ilya Grigorik
 
Using Websockets in Play !
Using Websockets in Play !Using Websockets in Play !
Using Websockets in Play !
Knoldus Inc.
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
Claus Ibsen
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
Prabin Silwal
 
WebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! FrameworkWebSockets wiith Scala and Play! Framework
WebSockets wiith Scala and Play! Framework
Fabio Tiriticco
 
Realtime web application with java
Realtime web application with javaRealtime web application with java
Realtime web application with java
JeongHun Byeon
 
Spring Boot & WebSocket
Spring Boot & WebSocketSpring Boot & WebSocket
Spring Boot & WebSocket
Ming-Ying Wu
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
[1D1]신개념 N스크린 웹 앱 프레임워크 PARS
NAVER D2
 
Building Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using WebsocketsBuilding Next Generation Real-Time Web Applications using Websockets
Building Next Generation Real-Time Web Applications using Websockets
Naresh Chintalcheru
 
Using Websockets with Play!
Using Websockets with Play!Using Websockets with Play!
Using Websockets with Play!
Andrew Conner
 
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.comRuby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ruby Proxies for Scale, Performance, and Monitoring - GoGaRuCo - igvita.com
Ilya Grigorik
 
Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09Ruby C10K: High Performance Networking - RubyKaigi '09
Ruby C10K: High Performance Networking - RubyKaigi '09
Ilya Grigorik
 
GWT Web Socket and data serialization
GWT Web Socket and data serializationGWT Web Socket and data serialization
GWT Web Socket and data serialization
GWTcon
 
Solving anything in VCL
Solving anything in VCLSolving anything in VCL
Solving anything in VCL
Fastly
 
Communication in Python and the C10k problem
Communication in Python and the C10k problemCommunication in Python and the C10k problem
Communication in Python and the C10k problem
Jose Galarza
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Java
jfarcand
 
Building Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSocketsBuilding Real-Time Applications with Android and WebSockets
Building Real-Time Applications with Android and WebSockets
Sergi Almar i Graupera
 
0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services0-60 with Goliath: Building High Performance Ruby Web-Services
0-60 with Goliath: Building High Performance Ruby Web-Services
Ilya Grigorik
 
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9No callbacks, No Threads - Cooperative web servers in Ruby 1.9
No callbacks, No Threads - Cooperative web servers in Ruby 1.9
Ilya Grigorik
 
Using Websockets in Play !
Using Websockets in Play !Using Websockets in Play !
Using Websockets in Play !
Knoldus Inc.
 
Apache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the boxApache Camel Introduction & What's in the box
Apache Camel Introduction & What's in the box
Claus Ibsen
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
Prabin Silwal
 

Similar to Reverse ajax in 2014 (20)

Servlets-UNIT3and introduction to servlet
Servlets-UNIT3and introduction to servletServlets-UNIT3and introduction to servlet
Servlets-UNIT3and introduction to servlet
RadhikaP41
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
SenthilKumar571813
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
Senthil Kumar
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
Doris Chen
 
UNIT - 5.pptx Servlets And Database Connectivity
UNIT - 5.pptx  Servlets And Database ConnectivityUNIT - 5.pptx  Servlets And Database Connectivity
UNIT - 5.pptx Servlets And Database Connectivity
bmit1
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
karthiksmart21
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web Applications
Codemotion
 
Ajax & Reverse Ajax Presenation
Ajax & Reverse Ajax PresenationAjax & Reverse Ajax Presenation
Ajax & Reverse Ajax Presenation
Rishabh Garg
 
wa-cometjava-pdf
wa-cometjava-pdfwa-cometjava-pdf
wa-cometjava-pdf
Hiroshi Ono
 
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgbServlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
shubhangimalas1
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
MouDhara1
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
kstalin2
 
Servlet1.ppt
Servlet1.pptServlet1.ppt
Servlet1.ppt
KhushalChoudhary14
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
WebStackAcademy
 
Servlet (1) also contains code to create it.ppt
Servlet (1) also contains code to create it.pptServlet (1) also contains code to create it.ppt
Servlet (1) also contains code to create it.ppt
juhishrivastava25
 
Web-Socket
Web-SocketWeb-Socket
Web-Socket
Pankaj Kumar Sharma
 
Server side push in Aldan 3
Server side push in Aldan 3Server side push in Aldan 3
Server side push in Aldan 3
ALDAN3
 
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
Edward Burns
 
JAVA
JAVAJAVA
JAVA
rithika858339
 
Servlets-UNIT3and introduction to servlet
Servlets-UNIT3and introduction to servletServlets-UNIT3and introduction to servlet
Servlets-UNIT3and introduction to servlet
RadhikaP41
 
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database ConnectivityIT2255 Web Essentials - Unit V Servlets and Database Connectivity
IT2255 Web Essentials - Unit V Servlets and Database Connectivity
pkaviya
 
Developing Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax PushDeveloping Revolutionary Web Applications using Comet and Ajax Push
Developing Revolutionary Web Applications using Comet and Ajax Push
Doris Chen
 
UNIT - 5.pptx Servlets And Database Connectivity
UNIT - 5.pptx  Servlets And Database ConnectivityUNIT - 5.pptx  Servlets And Database Connectivity
UNIT - 5.pptx Servlets And Database Connectivity
bmit1
 
WEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptxWEB TECHNOLOGY Unit-3.pptx
WEB TECHNOLOGY Unit-3.pptx
karthiksmart21
 
Comet / WebSocket Web Applications
Comet / WebSocket Web ApplicationsComet / WebSocket Web Applications
Comet / WebSocket Web Applications
Codemotion
 
Ajax & Reverse Ajax Presenation
Ajax & Reverse Ajax PresenationAjax & Reverse Ajax Presenation
Ajax & Reverse Ajax Presenation
Rishabh Garg
 
wa-cometjava-pdf
wa-cometjava-pdfwa-cometjava-pdf
wa-cometjava-pdf
Hiroshi Ono
 
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgbServlet123jkhuiyhkjkljioyudfrtsdrestfhgb
Servlet123jkhuiyhkjkljioyudfrtsdrestfhgb
shubhangimalas1
 
Servlet.ppt
Servlet.pptServlet.ppt
Servlet.ppt
kstalin2
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 1...
WebStackAcademy
 
Servlet (1) also contains code to create it.ppt
Servlet (1) also contains code to create it.pptServlet (1) also contains code to create it.ppt
Servlet (1) also contains code to create it.ppt
juhishrivastava25
 
Server side push in Aldan 3
Server side push in Aldan 3Server side push in Aldan 3
Server side push in Aldan 3
ALDAN3
 
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
HTTP/2 Comes to Java: Servlet 4.0 and what it means for the Java/Jakarta EE e...
Edward Burns
 
Ad

Recently uploaded (20)

Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Ad

Reverse ajax in 2014

  • 2. Ajax (Asynchronous JavaScript and XML) • Group of interrelated Web development techniques used on the client-side to create asynchronous Web applications. • With Ajax, Web applications can send data to, and retrieve data from a server asynchronously (in the background) without the need for a page reload. • It is a browser feature accessible to a web page through the JavaScript. • Though the name includes XML, nearly anything can be transfered with an Ajax request. • The most commonly used data is JSON, which is close to JavaScript syntax and consumes less bandwidth. • Ajax requests are stateless by default, and can only be opened from the client to the server.
  • 3. Reverse Ajax • Reverse Ajax is essentially a concept for sending data from the server to the client. • It can be simulated with a repeated Ajax request from client – simple polling, piggyback polling. • Comet – umbrella term for various techniques for Reverse Ajax • Coined by Alex Russel in 2006. • It can be simulated with a long-held Ajax request from client . • Server can send events to the client without the client specifically requesting it. • Also known as Ajax Push, Two-way-web, HTTP Streaming, and HTTP server push, • First implementations appeared in 2000 with Pushlets and LightStreamer media server
  • 5. Reverse Ajax – simple polling
  • 6. Reverse Ajax – simple polling • Basic Ajax with regular interval requests (every few seconds). • To get the server events as soon as possible, the polling interval (time between requests) must be as low as possible. • If interval is reduced, the client will issue many more requests, many of which won't return any useful data, and will consume bandwidth and processing resources for nothing. • Advantages: It's really easy to implement and does not require any special features on the server side. It also works in all browsers. • Disadvantages: This method is rarely employed because it does not scale at all. Example: 100 clients each issuing polling requests for 2 seconds, where 30% of the requests returns no data.
  • 7. Reverse Ajax – piggyback polling
  • 8. Reverse Ajax – piggyback polling • Piggyback polling removes all redundant requests (which return no data) • There is no interval • Requests are sent when the client needs to send a request to the server • The difference lies in the response, which is split into two parts:  the response for the requested data  server events, if any • Advantages: Less resource consumption. Works in all browsers, does not require special features on the server side. • Disadvantages: You have no clue when the events accumulated on the server side will be delivered to the client.
  • 10. Reverse Ajax – Comet • Request is sent to the server and kept alive for a long time, until a time-out or a server event occurs. • When the request is completed, another long-lived Ajax request is sent to wait for other server events. • With Comet, web servers can send the data to the client without having to explicitly request it. • The server can push events on the clients by immediately committing (completing) the responses, or it can accumulate them and send bursts. • Special features are required on the server side to handle all of these long-lived requests (Servlet 3.0 or Websockets) • Implementations of Comet can be separated into two types: those using streaming mode, and those using long polling.
  • 11. Reverse Ajax Comet - Streaming Mode
  • 12. Comet – Streaming mode • In streaming mode, one persistent connection is opened • It requires a way to separate the different responses coming through the same connection on the client side. • Technically speaking, two common techniques for streaming include:  Forever Iframes (hidden Iframes) or  Multi-part feature of the XMLHttpRequest object used to create Ajax requests in JavaScript.
  • 13. Comet – Forever Iframes • Forever Iframes technique involves a hidden Iframe tag put in the page with its src attribute pointing to the servlet path returning server events. • Each time an event is received, the servlet writes and flushes a new script tag with the JavaScript code inside. • The iframe content will be appended with this script tag that will get executed. • Advantages: Simple to implement, and it works in all browsers supporting iframes. • Disadvantages: There is no way to implement reliable error handling or to track the state of the connection, because all connection and data are handled by the browser through HTML tags. You don't know when the connection is broken on either side.
  • 14. Comet – Multi-part XMLHttpRequest • This technique uses the multi-part flag supported by some browsers (Chrome, Firefox) on the XMLHttpRequest object. • An Ajax request is sent and kept open on the server side. Each time an event comes, a multi-part response is written through the same connection • On the server side it is required to set up the multi-part request, suspend the connection and return responses asynchronously (Servlet 3.0) • Advantages: Only one persistent connection is opened. This is the Comet technique that saves the most bandwidth usage. • Disadvantages: The multi-part flag is not supported by all browsers. Some widely used libraries, such as CometD in Java, reported issues in buffering. For example, chunks of data (multi-parts) may be buffered and sent only when the connection is completed or the buffer is full, which can create higher latency than expected.
  • 15. Reverse Ajax Comet - HTTP long polling
  • 16. Comet - HTTP long polling • The long polling mode involves techniques that use repeated long-held client requests. • When client initiates a connection, it is kept open by the server, and as soon as an event occurs, the response is committed and the connection is closed. • New long-polling connection is reopened immediately by the client waiting for the new events to arrive. • You can implement HTTP long polling by using  Script tags  XMLHttpRequest object.
  • 17. Comet – Script tags • Similar to the iframe technique, the goal is to append a script tag in your page to get the script executed. • The server will: suspend the connection until an event occurs, send the script content back to the browser, and then reopen another script tag to get the next events. • Advantages: Because it's based on HTML tags, this technique is easy to implement and works across domains (by default, XMLHttpRequest does not allow requests on other domains or sub-domains). • Disadvantages: Similar to the iframe technique, error handling is missing, and you can't have a state or the ability to interrupt a connection.
  • 18. Comet - XMLHttpRequest long polling • Recommended method to implement Comet • Client opens an Ajax request to the server and waits for the response. • The server requires specific features on the server side to allow the request to be suspended (Servlet 3.0). • As soon as an event occurs, the server sends back the response in the suspended request and closes it. • The client then consumes the response and opens a new long-lived Ajax request to the server. • On the back end, the code also uses the Servlet 3 API to suspend the request, as in HTTP streaming, but without multi-part handling.
  • 19. Comet - XMLHttpRequest long polling • Advantages: It's easy to implement on the client side with a good error- handling system and timeout management. This reliable technique also allows reusing connections on the server side, since connections are not persistent (a good thing, when you have a lot of clients on your application). It also works on all browsers; you only make use of the XMLHttpRequest object by issuing a simple Ajax request. • Disadvantages: There is no main disadvantage compared to other techniques. But, like all techniques we've discussed, this one still relies on a stateless HTTP connection, which requires special features on the server side to be able to temporarily suspend it. • Several well-known libraries implement Comet in Java and Javascript:  DWR  CometD  Atmosphere
  • 21. DWR • DWR – direct web remoting • Well known library for integration between client-side JS and server-side Java code • Reverse Ajax Modes  Early Closing Mode (default, low performance for large number of clients)  Full Streaming Mode (Not available to IE users)  Long Polling (best option)  Piggyback mode • Advantages: Highly configurable and stable library. • Disadvantages: Development is slow, Websocket support is uncertain.
  • 22. Atmosphere • Atmosphere is a Java technology framework that provides a common API for using the Comet and WebSocket features of many of the web servers, including Tomcat, Jetty, GlassFish, Weblogic, Grizzly, JBossWeb, JBoss, and Resin. • Atmosphere has been around for more than two years, and it is still in active development. It is used in large web applications such as JIRA • Advantages: Atmosphere's strength remains on the server side: it provides a standardized API that covers all of the different solutions and ways to communicate with WebSockets or Comet. • Disadvantages: Atmosphere does not use a protocol between the client and server, like DWR and CometD.
  • 23. CometD – our choice • CometD framework is an event-driven communication solution based on HTTP. It provides a Java server part and a Java client part, plus JavaScript client libraries based upon jQuery and Dojo. • It has been around for several years. It supports WebSockets. Reverse Ajax Mode is implemented with XMLHttpRequest long-polling. • All of the components communicate through a bus to send notifications and receive events. All communication is asynchronous. • Advantages: CometD offers a complete solution, from client and server side, and also from a standalone Java client to a server. The framework is well- documented and is easy to use. It supports many features - reconnection, reliable timeout detection, error handling, low-latency communication ... • Disadvantages: CometD currently does not support any Servlet 2.5 containers other than Jetty for Comet (Tomcat), and it does not support Glassfish/Grizzly WebSocket
  • 25. Websockets • WebSockets, which comes from HTML5, is a new technique for bidirectional, full-duplex communication. • The connection is opened through a HTTP Upgrade request (HTTP request with special headers), called a WebSockets handshake. • The connection is then kept alive, and data is exchanged between both sides directly. • Best option for bidirectional communication, future standard • Supported in Chrome 14+, Firefox 6+, Safari 6+, IE 10+ • Supported on Tomcat 8, JBoss 8, Glassfish 3, Jetty 7 • Supported in CometD along with long polling.
  • 26. References IBM Developerworks: Reverse Ajax series http://www.ibm.com/developerworks/library/wa-reverseajax1/ Javabeat: An introduction to Comet and Reverse Ajax http://www.javabeat.net/introduction-to-comet-and-reverse-ajax/ DWR: Reverse Ajax http://directwebremoting.org/dwr/documentation/reverse-ajax/ CometD: http://docs.cometd.org/reference/ Atmosphere Framework: http://async-io.org/
  • 27. References Oracle: Asynchronous Notifications with Servlet 3.0 http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/async- servlet/async-servlets.html Javabeat: Asynchronous Servlet http://www.javabeat.net/asynchronous-servlet-servlet-3-0/ Google groups: CometD users https://groups.google.com/forum/#!topic/cometd-users Wikipedia: Comet http://en.wikipedia.org/wiki/Comet_(programming)#Implementations