Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Think Async Masoud Kalali, Software Engineer, Embrace and.

Slides:



Advertisements
Similar presentations
16 Copyright © 2005, Oracle. All rights reserved. Developing Message-Driven Beans.
Advertisements

Copyright © 2013, Oracle and/or its affiliates. All rights reserved. 1.
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Your customer as a segment of one That changes every second! Hein Van Der Merwe Chief.
 2002 Prentice Hall. All rights reserved. Chapter 9: Servlets Outline 9.1 Introduction 9.2 Servlet Overview and Architecture Interface Servlet and.
MVC in JavaEE 8 Manfred Riem Principal Member of Technical Staff September, 2014 Copyright © 2014, Oracle and/or its affiliates. All rights reserved.
Jim Ferrentino Elizabeth West
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Oracle SQL Developer Tips & Tricks Jeff Smith
A Java Architecture for the Internet of Things Noel Poore, Architect Pete St. Pierre, Product Manager Java Platform Group, Internet of Things September.
G O B E Y O N D C O N V E N T I O N WORF: Developing DB2 UDB based Web Services on a Websphere Application Server Kris Van Thillo, ABIS Training & Consulting.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 34 Servlets.
Copyright © 2014 Oracle and/or its affiliates. All rights reserved. | Oracle SQL Developer What’s New in Version 4.1 Jeff Smith
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Advanced Metadata Modeling Modeling for the Oracle Business Intelligence Cloud.
ECSE Software Engineering 1I HO 7 © HY 2012 Lecture 7 Publish/Subscribe.
The Safe Harbor The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | Title Slide without Picture Subtitle Presenter’s Name Presenter’s Title Organization,
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. JD Edwards Summit The Newest JDE Module – Rental Management Joel Sandberg Sales Consultant.
QAD .Net UI: New Enhancements
© 2011 IBM Corporation Overview on Modeling RESTful Services August, 2011 Manoj Paul, Software Developer, Rational,
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. JD Edwards Summit PaaS from an Applications Perspective Charles McGuinness Director,
MVC 1.0 Manfred Riem Oracle Geertjan Wielenga Oracle Copyright © 2014, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | How to work from home, effectively! Masoud Kalali Software engineer ORACLE twitter:
1Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 Reporting from Contract.
Oracle E-Business Suite Order Management: Presenting the HTML and Mobile User Experience Durgaprasad Bodapati Director, Product Management Bhavana Sharma.
Presented by Robert Zaremba.  Remote messages must be sent to a message queue so that components are decoupled  Both sides of a communication must be.
What Is New and Noteworthy in Jersey Miroslav Fuksa, Jakub Podlešák Software Developers Oracle, Application Server Group October 1, 2014 Copyright ©
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Real-World RESTful Service Development Problems and Solutions Masoud Kalali, Software.
RMB Billing UX Design Concepts / Proposals Peter Picone.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 1.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. An Auto-Join Network of Things Wong, H. and Wesson, B. Oracle Confidential – Internal/Restricted/Highly.
Message Driven Beans & Web Services INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Hadoop 2 cluster with Oracle Solaris Zones, ZFS and unified archives Orgad Kimchi - Principal Software Engineer September 29, 2014 Oracle Confidential.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 1 Quick Tutorial – Part 2 Open Data Web Services for Oracle BPM August, 2013 Forms.
1Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 8 Contract Management.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. JD Edwards Summit Really Cool Demo Stuff – 2015 Edition!!!!! For demo content, please.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
Introduction to Server-Side Web Development Introduction to Server-Side Web Development Session II: Introduction to Server-Side Web Development with Servlets.
1 Java Servlets l Servlets : programs that run within the context of a server, analogous to applets that run within the context of a browser. l Used to.
Workforce Scheduling Release 5.0 for Windows Implementation Overview OWS Development Team.
RESTful Microservices In Java With Jersey Jakub Podlešák Software Engineer Oracle, Application Server Group September 29, 2014 Copyright © 2014, Oracle.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, Responds oriented other.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Planning & Budgeting Cloud Service (PBCS) Overview Business Analytics Product Group.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
©SoftMoore ConsultingSlide 1 Overview of Servlets and JavaServer Pages (JSP)
Performance/Scalability with JDBC, UCP & Oracle Database 12c
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. JD Edwards Summit Recruit and Learn Solutions Extend HR into the Cloud Marie Scott.
Message Framework Topic subscribe for javascript/flex client.
The Chain of Responsibility Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
Travel and Transportation General Session and Industry Excellence Awards Vijay Anand, Oracle Sundar Swaminathan, Oracle September 30, 2014 Copyright ©
September 28, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
Copyright © 2013, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 12 1.
© 2010 IBM Corporation RESTFul Service Modelling in Rational Software Architect April, 2011.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Oracle Java Cloud Service Oracle Develop July 2013.
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | What You Need to Know About User Defined Objects (UDOs) With Tools Release 9.2.
Introduction to Servlets
CS5220 Advanced Topics in Web Programming Introduction to WebSocket
Java Servlets By: Tejashri Udavant..
OpenWorld 2018 How to Combine Data from Source Sites
Project Helidon Deep Dive
Java Messaging Service (JMS)
Chapter 26 Servlets.
OpenWorld 2018 Oracle API Platform: How to Manage Typical Workflows
Java Messaging Service (JMS)
J2EE Lecture 13: JMS and WebSocket
Oracle Java SE Subscriptions; Protect Your Investment in Java SE
Presentation transcript:

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Think Async Masoud Kalali, Software Engineer, Embrace and Get Addicted to the Asynchronicity of Java SE and EE

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Program Agenda Introduction Why to think Async A simple case of using Async JMS (2.0) Async Servlet Async JAX-RS Async EJBs

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Speakers Masoud Kalali Software engineer, author, blogger Long advocate of GlassFish and Java EE Tweets

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Why to think Async? To better model what we develop for To further decouple – Ease of administration – Ease of tuning – Ease of maintenance Improve consumers experience – An API consumer – A direct GUI for human use – etc.

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Java EE And ASynchronicity Long present JMS – To be used almost everywhere Servlet 3.0/ 3.1 – Asynchronous Servlets – None blocking IO JAX-RS 2.0 – Server side – Client side Asynchronous Session Beans – Server side – Client side

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | A simple asynchronous nourished use case Client Cache Query Processor JMS Queue Async Servlet MDB ID, AsyncContext Query Requests in JMS Chunks of Query results Consume result chunks and send it back via AsyncContext …. 5….6….7…. 8….

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | A simple asynchronous nourished use case One JMS queue for sending the query requests One JMS queue which will get chunks of query results An MDB which will consume the query result messages – Uses the cache and the id in the message to pick up the right AsyncContext – As long as the message does not say it is done it will not conclude the response Complete the response when JMS message implies More details of the Messaging components

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | A simple asynchronous nourished use case Asynchronous Servlet receiving the requests Caching the AsynContext and a query Id Sending the Query message to the JMS queue – Including the query Id Leave it to the MDB to update the response Have a AsyncListener to send proper response if timeouts More details of the Servlet components

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | A simple asynchronous nourished use case A browser Can be – A SSE client – A COMET, Long Polling request Some basics on the client side

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JMS (2.0) A brief overview

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JMS: A brief overview I Broker Message Queue – Producers – Consumers Topic – Publishers – Subscribers

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | JMS 2.0: A brief overview: Multiple Consumers Allowed on the Same Topic Subscription Delivery Delay Sending Messages Asynchronously – Send the message and get callback when it is acknowledged by broker JMSXDeliveryCount message property No longer optional Standard MDB Configuration Properties as part – destinationType – subscriptionDurability – acknowledgeMode – subscriptionName –...

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.0 Asynchronous servlet

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.0 Asynchronicity Why we want it – More throughput – Better architecture mapping How it works async-supported in XML config! – AsyncContext – AsyncListener

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.0 Asynchronicity : AsyncContext Adding listeners Doing request dispatching Accessing ServletRequest Accessing ServletResponse Concluding the request/response Setting, getting timeouts

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.0 Asynchronicity : AsyncListener Get callback on important events on an async request processing onComplete(AsyncEvent asyncEvent) onError(AsyncEvent asyncEvent) onStartAsync(AsyncEvent asyncEvent) onTimeout(AsyncEvent asyncEvent)

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.0 Asynchronicity : A little bit of = true, value = ”/query-servlet") public class QueryServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String id=...; cache.put(id,request.startAsync()); sendQueryMessage(id, request); }

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.1 Non-blocking IO

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.1: Non-Blocking IO Why do we want it? How does it work? – ReadListener: To read inbound data when available – WriteListener: To write data when possible – Changes in ServletOutputStream isReady() setWriteListener(…) – Changes in ServletInputStream isFinished() isReady() setReadListener(…)

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.1: Non-Blocking IO: ReadListener To get callbacks on ServletInputStream events – onDataAvailable – OnAllDataRead – onError

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Servlet 3.1: Non-Blocking IO: WriteListener To get notified on ServletOutputStream events – onError – onWritePossible

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asyncronicity in JAX-RS 2.0 Why would we need it? How does it work? – ExecutionContext for programmatic decision to do or not to do async – AsyncResponse – CompletionCallback – ConnectionCallbck

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asyncronicity in JAX-RS 2.0: Server-side I On the serverside: Annotate a sub-resource as Asynchronous – AsyncResponse: Provides results an actions on the running request setting timeout registering callbacks resume, cancel suspended request processing updating the response To inject a suspended AsyncResponse into a sub-resource parameter How to mark a resource as Asynchronous

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asyncronicity in JAX-RS 2.0: Server-side simple public class MyResource private public void AsyncResponse String p1… ) { executor.submit( new Runnable() { public void run() { JsonObject response = getQueryResult(p1…); ctx.resume(response); //container thread picks up and continue } }); ctx.suspend();// Suspend connection and return } … } Server Code:

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asyncronicity in JAX-RS 2.0: client-side simple code Future future = client. target(“/api/query/matching- query”).queryParam(...).request().async().get(JsonObject.class); try { JsonObject queryResult = future.get(30, TimeUnit.SECONDS); } catch (TimeoutException ex) { // } Client-Side with future

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asyncronicity in JAX-RS 2.0: client-side simple code Client-Side with callback Future future = client. target(“/api/query/matching-query”). queryParam(...).request().async().get(new InvocationCallback () public void completed(JsonObject response) { //Invocation happens and some response is back (404, 200, etc.) public void failed(Throwable throwable) { //Invocation fails (client side) } });

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asyncronicity in JAX-RS 2.0: Server-side II Single method interface void onComplete(Throwable t) signal completion of serving a request CompletionCallback

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asyncronicity in JAX-RS 2.0: Server-side III Single method interface void onDisconnect(AsyncResponse disconnected) signals interruption in client connection before completion ConnectionCallback

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asynchronous And long running jobs in REST Multi-step long running jobs not suitable with JAX-RS Async Send 202 where response is not ready with Location header – Intelligent enough client can query the resource Location with the given Retry-After header Don’t keep unnecessary resources for where not needed!

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | EJB 3.1 Asynchronicity in Session Beans

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asynchronicity in EJB 3.1 Works on session beans – fire and forget – Using Future to decide on completion AsyncResult as container specific vehicle – Passes the result to Future As simple as on method/bean Method should return Future Client can poll the future for Completion

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asynchronicity in EJB 3.1: Simple code public class QueryProcessor public Future processQuery(QueryCrit crit){ try{ QueryResult result= prepQueryResult(crit); return new AsyncResult(result); }catch(Exception e){ //handle return new AsyncResult(FAILURE_RESULT); } }} Server-side code

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Asynchronicity in EJB 3.1: Simple code QueryProcessor queryProcessor; private JsonObject prepareQueryResult(String... params){ QueryCrit crit = new QueryCrit(params) Future result=queryProcessor.prepQueryResult(crit); //poll the Future.. There is no callback here... } cliet-side code

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Java EE 7 and SSE Asynchronicity in SSE

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Server-Sent Events  HTML 5 component  Client subscribe to event source  Unidirectional channel between server and client  Events can be streamed from server to client when happens  Connection stays open  event handling on client side  onMessage  onError  etc.  Subscription resuming

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Server-Sent Events  Can be developed using a plain Servlet  use the right media type  use the correct message format  Jersey provides support not JAX-RS yet  Server side to turn a JAX-RS endpoint to SSE broadcaster  Client side to subscribe and consume SS events

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Comments, Questions?

Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | RESTful Services Patterns and best practices By Bhakti Mehta Bhakti’s blog: Book’s sample codes: CCL photos used in slides: Resources