SlideShare a Scribd company logo
1 of 19
Download to read offline
Asynchronous I/O
for Servlet 3.0

 Jeanfrancois Arcand
 Senior Staff Engineer
 Sun Microsystems
Goal                                          JGD




• Bring Asynchronous I/O to Servlet without
  exposing low level I/O details
• New classes:
  >   ServletFuture
  >   ServletAsyncHandler
  >   ServletRequestChannel
  >   ServletResponseChannel
  >   ReadFuture
  >   WriteFuture



                                    2
ServletFuture                                 JGD




• A Future representing the result of an
  asynchronous I/O operation.
• In addition to the methods defined by the
  Future interface, a ServletFuture allows
  for the attachment of a single arbitrary
  object.
• The object can be used to associate
  application-specific data or context
  required when consuming the result of the
  I/O operation.
• This is important for cases where the
  same ServletAsyncHandler is used to
  consume the result of several I/O
  operations.
                                    3
ServletIoFuture                                  JGD




 boolean cancel(boolean mayInterruptIfRunning)

 A attachment()

 A attach(A attachment)




                                  4
ServletAsyncHandler                          JGD




• A handler for consuming the result of an
  asynchronous I/O operation.
• The asynchronous
  ServletRequestChannel.read or
  ServletResponseChannel.write defined in
  this package allow a ServletAsyncHandler
  to be specified yo consume the result of
  an asynchronous operation.
• When an operation completes the
  handler's completed method is invoked
  with the result.

                                   5
ServletAsyncHandler                            JGD




 void completed(ServletIoFuture<T,A> result)




                                   6
ServletRequestChannel                          JGD




• An asynchronous channel for read
  stream-oriented operations.
• Allow synchronous and asynchronous
  read operations
• From a Class definition, the read
  operation will convert the request body
  into an instance of that Class definition.




                                       7
ServletRequestChannel                        JGD




 <T,A> ReadFuture<T,A> read
         (java.lang.Class<T> clazz,
          A attachment,
          ServletAsyncHandler<? super T,A>
          handler)

 <T,A> ReadFuture<T,A> read
         (java.lang.Class<T> clazz,
          long timeout,
          TimeUnit unit,
          A attachment,
          ServletAsyncHandler<? super T,A>
           handler)
                                         8
Example 1: Asynchronous Read                                                    JGD




// Asynchronous Read
// The request is automatically suspended when the getChannel() is invoked.
// See Example 3 for a scenario when the request is not explicitly suspended.


ServletRequestChannel channel = servletRequest.getChannel();
ReadFuture ioFuture = channel.read(Map.class,30,TimeUnits.SECONDS, null,
         new ServletAsyncHandler<ReadFuture<Map,Void>){
               public void completed(ReadFuture<Map,Void> result){
                   Map map = result.getContent();
               }
         });




                                                               9
Example 2: Synchronous Read                                           JGD




// Synchronous Read
ServletRequestChannel channel = servletRequest.getChannel();
ReadFuture ioFuture = channel.read(Map.class);
// Or ReadFuture ioFuture = channel.read(Map.class,null,null);
ioFuture.get(30,TimeUnits.SECONDS);
Map map = ioFuture.getContent() ;




                                                                 10
Example 3: Suspendable Request                                                 JGD




// Asynchronous Read
servletRequest.suspend();
ServletRequestChannel channel = servletRequest.getChannel();
ReadFuture ioFuture = channel.read(
          Map.class,30,TimeUnits.SECONDS, servletRequest,
          new ServletAsyncHandler<ReadFuture<Map,ServletRequest>){
               public void completed(ReadFuture<Map,ServletRequest> result){
                    Map map = result.getContent();
                    result.attachment().resume();
               }
         });




                                                               11
ServletResponseChannel                 JGD




• An asynchronous channel for write
  stream-oriented operations.
• Allow synchronous and asynchronous
  write operations




                                 12
ServletResponseChannel                                  JGD




 <A> WriteFuture<Integer> write
            (Object object,
             A attachment,
             ServletAsyncHandler<Integer,A> handler)

 <A> WriteFuture<Integer> write
             (Object object,
              long timeout,
              TimeUnit unit,
              A attachment,
              ServletAsyncHandler<Integer,A> handler)



                                          13
Example 4: Asynchronous Write                                                   JGD




// Asynchronous Write
// The request is automatically suspended when the getChannel() is invoked.
// See Example 6 for a scenario when the request is not explicitly suspended.
ServletResponseChannel channel = servletResponse.getChannel();
WriteFuture ioFuture = channel.write(“Hello”,30,TimeUnits.SECONDS, null,
          new ServletAsyncHandler<WriteFuture<Integer,Void>){
               public void completed(WriteFuture<Integer,Void> result){
                   System.out.println(“Bytes Written: “ + result.get());
               }
         });




                                                                  14
Example 5: Asynchronous Write                                              JGD




// Asynchronous Write
ServletResponseChannel channel = servletResponse.getChannel();
WriteFuture ioFuture = channel.write(“Hello”,30,TimeUnits.SECONDS, null,
          new ServletAsyncHandler<WriteFuture<Integer,Void>){
               public void completed(WriteFuture<Integer,Void> result){
                   System.out.println(“Bytes Written: “ + result.get());
               }
         });




                                                                  15
Example 6: Synchronous Write                                     JGD




// Asynchronous Write
ServletResponseChannel channel = servletResponse.getChannel();
WriteIoFuture ioFuture = channel.write(“Hello”);
ioFuture.get(30,TimeUnits.SECONDS);




                                                           16
Example 2: Suspendable Request                                                         JGD




// Asynchronous Read
servletRequest.suspend();
ServletResponseChannel channel = servletResponse.getChannel();
WriteIoFuture ioFuture = channel.write(
 “Hello”,30,TimeUnits.SECONDS, servletRequest, new
           ServletAsynchronousIoHandler<WriteIoFuture<Integer,ServletRequest>){
                public void completed(WriteIoFuture<Integer,ServletRequest> result){
                    result.attachment().resume();
                }
         });




                                                                17
Summary                               JGD




• Simple API.
• No buffering of data
• API can be used synchronously and
  asynchronously.
• Easy to implement.




                                 18
jeanfrancois.arcand@sun.com

More Related Content

What's hot

Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 
Other Approaches (Concurrency)
Other Approaches (Concurrency)Other Approaches (Concurrency)
Other Approaches (Concurrency)Sri Prasanna
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in GolangBo-Yi Wu
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構Bo-Yi Wu
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Alexey Fyodorov
 
FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!Vincent Claes
 
[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++Dimitrios Platis
 
Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Yoshifumi Kawai
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageablecorehard_by
 
Building serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platformBuilding serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platformLucio Grenzi
 
OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2Pradeep Kumar TS
 
Memory Management of C# with Unity Native Collections
Memory Management of C# with Unity Native CollectionsMemory Management of C# with Unity Native Collections
Memory Management of C# with Unity Native CollectionsYoshifumi Kawai
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Mr. Vengineer
 

What's hot (20)

Rcpp11
Rcpp11Rcpp11
Rcpp11
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 
Other Approaches (Concurrency)
Other Approaches (Concurrency)Other Approaches (Concurrency)
Other Approaches (Concurrency)
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構用 Go 語言打造多台機器 Scale 架構
用 Go 語言打造多台機器 Scale 架構
 
Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)Counter Wars (JEEConf 2016)
Counter Wars (JEEConf 2016)
 
Node js lecture
Node js lectureNode js lecture
Node js lecture
 
FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!FreeRTOS Xilinx Vivado: Hello World!
FreeRTOS Xilinx Vivado: Hello World!
 
[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++[grcpp] Refactoring for testability c++
[grcpp] Refactoring for testability c++
 
Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)Deep Dive async/await in Unity with UniTask(EN)
Deep Dive async/await in Unity with UniTask(EN)
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageable
 
Building serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platformBuilding serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platform
 
bluespec talk
bluespec talkbluespec talk
bluespec talk
 
OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2OTcl and C++ linkages in NS2
OTcl and C++ linkages in NS2
 
Kubernetes
KubernetesKubernetes
Kubernetes
 
Fm wtm12-v2
Fm wtm12-v2Fm wtm12-v2
Fm wtm12-v2
 
Memory Management of C# with Unity Native Collections
Memory Management of C# with Unity Native CollectionsMemory Management of C# with Unity Native Collections
Memory Management of C# with Unity Native Collections
 
Cuda 2
Cuda 2Cuda 2
Cuda 2
 
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
 
C++17 now
C++17 nowC++17 now
C++17 now
 

Viewers also liked

Asynchronous Processing in Java/JEE/Spring
Asynchronous Processing in Java/JEE/SpringAsynchronous Processing in Java/JEE/Spring
Asynchronous Processing in Java/JEE/SpringNaresh Chintalcheru
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaJames Falkner
 
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 WebsocketsNaresh Chintalcheru
 
Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programmingFilip Ekberg
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Jukka Zitting
 

Viewers also liked (6)

Think async
Think asyncThink async
Think async
 
Asynchronous Processing in Java/JEE/Spring
Asynchronous Processing in Java/JEE/SpringAsynchronous Processing in Java/JEE/Spring
Asynchronous Processing in Java/JEE/Spring
 
Asynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and JavaAsynchronous Web Programming with HTML5 WebSockets and Java
Asynchronous Web Programming with HTML5 WebSockets and Java
 
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
 
Asynchronous programming
Asynchronous programmingAsynchronous programming
Asynchronous programming
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3
 

Similar to Asynchronous I/O for Servlet 3.0

Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestPavan Chitumalla
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsCarol McDonald
 
Concurrent Programming in Java
Concurrent Programming in JavaConcurrent Programming in Java
Concurrent Programming in JavaRuben Inoto Soto
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyDavid Gómez García
 
Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022David Gómez García
 
Kubernetes Probes (Liveness, Readyness, Startup) Introduction
Kubernetes Probes (Liveness, Readyness, Startup) IntroductionKubernetes Probes (Liveness, Readyness, Startup) Introduction
Kubernetes Probes (Liveness, Readyness, Startup) IntroductionAkhmadZakiAlsafi
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontrackingvamsi krishna
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsAzul Systems, Inc.
 
Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the networkMu Chun Wang
 
Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Maurice De Beijer [MVP]
 
swift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientswift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientShinya Mochida
 
Jetty Continuation - 이상민
Jetty Continuation - 이상민Jetty Continuation - 이상민
Jetty Continuation - 이상민JavaCommunity.Org
 
The event-driven nature of javascript – IPC2012
The event-driven nature of javascript – IPC2012The event-driven nature of javascript – IPC2012
The event-driven nature of javascript – IPC2012Martin Schuhfuß
 

Similar to Asynchronous I/O for Servlet 3.0 (20)

gRPC in Go
gRPC in GogRPC in Go
gRPC in Go
 
Java Concurrency
Java ConcurrencyJava Concurrency
Java Concurrency
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
 
Concurrent Programming in Java
Concurrent Programming in JavaConcurrent Programming in Java
Concurrent Programming in Java
 
devday2012
devday2012devday2012
devday2012
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022Leverage CompletableFutures to handle async queries. DevNexus 2022
Leverage CompletableFutures to handle async queries. DevNexus 2022
 
Kubernetes Probes (Liveness, Readyness, Startup) Introduction
Kubernetes Probes (Liveness, Readyness, Startup) IntroductionKubernetes Probes (Liveness, Readyness, Startup) Introduction
Kubernetes Probes (Liveness, Readyness, Startup) Introduction
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontracking
 
Silicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM MechanicsSilicon Valley JUG: JVM Mechanics
Silicon Valley JUG: JVM Mechanics
 
Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the network
 
Concurrency in Swift
Concurrency in SwiftConcurrency in Swift
Concurrency in Swift
 
RxJava@Android
RxJava@AndroidRxJava@Android
RxJava@Android
 
Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18Concurrent Rendering Adventures in React 18
Concurrent Rendering Adventures in React 18
 
swift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClientswift-nio のアーキテクチャーと RxHttpClient
swift-nio のアーキテクチャーと RxHttpClient
 
Jetty Continuation - 이상민
Jetty Continuation - 이상민Jetty Continuation - 이상민
Jetty Continuation - 이상민
 
Qt Network Explained (Portuguese)
Qt Network Explained (Portuguese)Qt Network Explained (Portuguese)
Qt Network Explained (Portuguese)
 
The event-driven nature of javascript – IPC2012
The event-driven nature of javascript – IPC2012The event-driven nature of javascript – IPC2012
The event-driven nature of javascript – IPC2012
 
Npc08
Npc08Npc08
Npc08
 

More from jfarcand

Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!jfarcand
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmospherejfarcand
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Javajfarcand
 
Introduction au WebSockets via le projet Atmosphere
Introduction au WebSockets via le projet AtmosphereIntroduction au WebSockets via le projet Atmosphere
Introduction au WebSockets via le projet Atmospherejfarcand
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scalajfarcand
 
Async Http Client for Java and Scripting Language
Async Http Client for Java and Scripting LanguageAsync Http Client for Java and Scripting Language
Async Http Client for Java and Scripting Languagejfarcand
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Frameworkjfarcand
 

More from jfarcand (7)

Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!Websockets on the JVM: Atmosphere to the rescue!
Websockets on the JVM: Atmosphere to the rescue!
 
Building WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using AtmosphereBuilding WebSocket and Server Side Events Applications using Atmosphere
Building WebSocket and Server Side Events Applications using Atmosphere
 
Writing Portable WebSockets in Java
Writing Portable WebSockets in JavaWriting Portable WebSockets in Java
Writing Portable WebSockets in Java
 
Introduction au WebSockets via le projet Atmosphere
Introduction au WebSockets via le projet AtmosphereIntroduction au WebSockets via le projet Atmosphere
Introduction au WebSockets via le projet Atmosphere
 
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and ScalaWriting highly scalable WebSocket using the Atmosphere Framework and Scala
Writing highly scalable WebSocket using the Atmosphere Framework and Scala
 
Async Http Client for Java and Scripting Language
Async Http Client for Java and Scripting LanguageAsync Http Client for Java and Scripting Language
Async Http Client for Java and Scripting Language
 
The Atmosphere Framework
The Atmosphere FrameworkThe Atmosphere Framework
The Atmosphere Framework
 

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

Asynchronous I/O for Servlet 3.0

  • 1. Asynchronous I/O for Servlet 3.0 Jeanfrancois Arcand Senior Staff Engineer Sun Microsystems
  • 2. Goal JGD • Bring Asynchronous I/O to Servlet without exposing low level I/O details • New classes: > ServletFuture > ServletAsyncHandler > ServletRequestChannel > ServletResponseChannel > ReadFuture > WriteFuture 2
  • 3. ServletFuture JGD • A Future representing the result of an asynchronous I/O operation. • In addition to the methods defined by the Future interface, a ServletFuture allows for the attachment of a single arbitrary object. • The object can be used to associate application-specific data or context required when consuming the result of the I/O operation. • This is important for cases where the same ServletAsyncHandler is used to consume the result of several I/O operations. 3
  • 4. ServletIoFuture JGD boolean cancel(boolean mayInterruptIfRunning) A attachment() A attach(A attachment) 4
  • 5. ServletAsyncHandler JGD • A handler for consuming the result of an asynchronous I/O operation. • The asynchronous ServletRequestChannel.read or ServletResponseChannel.write defined in this package allow a ServletAsyncHandler to be specified yo consume the result of an asynchronous operation. • When an operation completes the handler's completed method is invoked with the result. 5
  • 6. ServletAsyncHandler JGD void completed(ServletIoFuture<T,A> result) 6
  • 7. ServletRequestChannel JGD • An asynchronous channel for read stream-oriented operations. • Allow synchronous and asynchronous read operations • From a Class definition, the read operation will convert the request body into an instance of that Class definition. 7
  • 8. ServletRequestChannel JGD <T,A> ReadFuture<T,A> read (java.lang.Class<T> clazz, A attachment, ServletAsyncHandler<? super T,A> handler) <T,A> ReadFuture<T,A> read (java.lang.Class<T> clazz, long timeout, TimeUnit unit, A attachment, ServletAsyncHandler<? super T,A> handler) 8
  • 9. Example 1: Asynchronous Read JGD // Asynchronous Read // The request is automatically suspended when the getChannel() is invoked. // See Example 3 for a scenario when the request is not explicitly suspended. ServletRequestChannel channel = servletRequest.getChannel(); ReadFuture ioFuture = channel.read(Map.class,30,TimeUnits.SECONDS, null, new ServletAsyncHandler<ReadFuture<Map,Void>){ public void completed(ReadFuture<Map,Void> result){ Map map = result.getContent(); } }); 9
  • 10. Example 2: Synchronous Read JGD // Synchronous Read ServletRequestChannel channel = servletRequest.getChannel(); ReadFuture ioFuture = channel.read(Map.class); // Or ReadFuture ioFuture = channel.read(Map.class,null,null); ioFuture.get(30,TimeUnits.SECONDS); Map map = ioFuture.getContent() ; 10
  • 11. Example 3: Suspendable Request JGD // Asynchronous Read servletRequest.suspend(); ServletRequestChannel channel = servletRequest.getChannel(); ReadFuture ioFuture = channel.read( Map.class,30,TimeUnits.SECONDS, servletRequest, new ServletAsyncHandler<ReadFuture<Map,ServletRequest>){ public void completed(ReadFuture<Map,ServletRequest> result){ Map map = result.getContent(); result.attachment().resume(); } }); 11
  • 12. ServletResponseChannel JGD • An asynchronous channel for write stream-oriented operations. • Allow synchronous and asynchronous write operations 12
  • 13. ServletResponseChannel JGD <A> WriteFuture<Integer> write (Object object, A attachment, ServletAsyncHandler<Integer,A> handler) <A> WriteFuture<Integer> write (Object object, long timeout, TimeUnit unit, A attachment, ServletAsyncHandler<Integer,A> handler) 13
  • 14. Example 4: Asynchronous Write JGD // Asynchronous Write // The request is automatically suspended when the getChannel() is invoked. // See Example 6 for a scenario when the request is not explicitly suspended. ServletResponseChannel channel = servletResponse.getChannel(); WriteFuture ioFuture = channel.write(“Hello”,30,TimeUnits.SECONDS, null, new ServletAsyncHandler<WriteFuture<Integer,Void>){ public void completed(WriteFuture<Integer,Void> result){ System.out.println(“Bytes Written: “ + result.get()); } }); 14
  • 15. Example 5: Asynchronous Write JGD // Asynchronous Write ServletResponseChannel channel = servletResponse.getChannel(); WriteFuture ioFuture = channel.write(“Hello”,30,TimeUnits.SECONDS, null, new ServletAsyncHandler<WriteFuture<Integer,Void>){ public void completed(WriteFuture<Integer,Void> result){ System.out.println(“Bytes Written: “ + result.get()); } }); 15
  • 16. Example 6: Synchronous Write JGD // Asynchronous Write ServletResponseChannel channel = servletResponse.getChannel(); WriteIoFuture ioFuture = channel.write(“Hello”); ioFuture.get(30,TimeUnits.SECONDS); 16
  • 17. Example 2: Suspendable Request JGD // Asynchronous Read servletRequest.suspend(); ServletResponseChannel channel = servletResponse.getChannel(); WriteIoFuture ioFuture = channel.write( “Hello”,30,TimeUnits.SECONDS, servletRequest, new ServletAsynchronousIoHandler<WriteIoFuture<Integer,ServletRequest>){ public void completed(WriteIoFuture<Integer,ServletRequest> result){ result.attachment().resume(); } }); 17
  • 18. Summary JGD • Simple API. • No buffering of data • API can be used synchronously and asynchronously. • Easy to implement. 18