1 ObjectRiver Metadata Compilers Programmatic WebSockets JavaOne 2014 – Steven Lemmo.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

15-May-15 RMI Remote Method Invocation. 2 “The network is the computer” Consider the following program organization: If the network is the computer, we.
C# and Windows Programming Application Domains and Remoting.
Implementing Remote Procedure Calls Andrew Birrell and Bruce Nelson Presented by Kai Cong.
Network Programming Chapter 11 Lecture 6. Networks.
6/11/2015Page 1 Web Services-based Distributed System B. Ramamurthy.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Advanced Java Class Network Programming. Network Protocols Overview Levels of Abstraction –HTTP protocol: spoken by Web Servers and Web Clients –TCP/IP:
Lecture 10: Web Services. Outline Overview of Web Services Create a Web Service with Sun J2EE (JAX-RPC)
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
CS490T Advanced Tablet Platform Applications Network Programming Evolution.
CSE331: Introduction to Networks and Security Lecture 11 Fall 2002.
Introduction to Remote Method Invocation (RMI)
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
1 Java Server Programming zLecture 1 focuses on: yIntroduction to web services y Web Services using Axis y The bigger Picture: Introduction to J2EE y Java.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 12 Communicating over.
The Client-Server Model – part II
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
Serialization. Serialization is the process of converting an object into an intermediate format that can be stored (e.g. in a file or transmitted across.
1 Cisco Unified Application Environment Developers Conference 2008© 2008 Cisco Systems, Inc. All rights reserved.Cisco Public Introduction to Etch Scott.
IBM TSpaces Lab 1 Introduction. Summary TSpaces Overview Basic Definitions Basic primitive operations Reading/writing tuples in tuplespace HelloWorld.
14-1 JXTA for J2ME Learning Objectives ● This module will help you... – Learn about the architecture of JXTA for J2ME – Learn the JXTA for J2ME.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
Abhishek Bachchan Vishal Patangia
RMI Remote Method Invocation Distributed Object-based System and RPC Together 2-Jun-16.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
 Remote Method Invocation  A true distributed computing application interface for Java, written to provide easy access to objects existing on remote.
CS390- Unix Programming Environment CS 390 Unix Programming Environment Java Socket Programming.
Dynamic Architectures (Component Reconfiguration) with Fractal.
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Spring Remoting Simplifying.
CSE 451: Operating Systems Winter 2015 Module 22 Remote Procedure Call (RPC) Mark Zbikowski Allen Center 476 © 2013 Gribble, Lazowska,
Update on CORBA Support for Babel RMI Nanbor Wang and Roopa Pundaleeka Tech-X Corporation Boulder, CO Funded by DOE OASCR SBIR.
Server-side Programming The combination of –HTML –JavaScript –DOM is sometimes referred to as Dynamic HTML (DHTML) Web pages that include scripting are.
Li Tak Sing COMPS311F. RMI callbacks In previous example, only the client can initiate a communication with the server. The server can only response to.
Server-Side Java Mapping Copyright © ZeroC, Inc. Ice Programming with Java 6. Server-Side Java Mapping.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
Using WebSockets in Web apps Presenter: Shahzad Badar.
UMBC Distributed Computing with Objects RMI/Corba CMSC 432 Shon Vick.
Remote Method Invocation RMI architecture stubs and skeletons for remote services RMI server and client in Java Creating an RMI Application step-by- step.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Java API for distributed computing.
The Java API for XML-Based Web Services. A Web Service example in Java SOAP-awareServlet (e.g. Apache Axis2) SOAP-awareServlet Any class processing the.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Echo Networking COMP
Threads in Java Two ways to start a thread
CS5220 Advanced Topics in Web Programming Introduction to WebSocket
Chapter 5 Remote Procedure Call
Client-server Programming
Remote Method Invocation
WEB API.
Inventory of Distributed Computing Concepts and Web services
CSE 451: Operating Systems Autumn 2003 Lecture 16 RPC
CIS Distributed and Parallel Architectures
Introduction to Web Services
Creating a Distributed System with Remote Procedure Calls and Web Services Ch.5 B.Ramamurthy 2/17/2019 B.Ramamurthy.
WS/XML Service Utility Library (WS and LEGO?)
WebServices Using JAX-RPC
Introduction to Web Services
Distributed System using Web Services
J2EE Lecture 13: JMS and WebSocket
CSE 451: Operating Systems Winter 2003 Lecture 16 RPC
Distributed System using Web Services
Chengyu Sun California State University, Los Angeles
Java Chapter 5 (Estifanos Tilahun Mihret--Tech with Estif)
Message Passing Systems
Presentation transcript:

1 ObjectRiver Metadata Compilers Programmatic WebSockets JavaOne 2014 – Steven Lemmo

2 Before the Web ( Internal applications behind the firewall. – Sockets – RPC ( Sun ONC/RPC ) – DCE Open Software Foundation – CORBA Binary protocols State-full Low latency Web Now – HTTP, XML, JSON String based protocols Stateless HTTP5 WebSockets – State-full – Full duplex peer to peer. – Low latency – String and binary protocols. – All through port 80! Sockets for the Web Finally!

3 WebSockets into port 80 Application Web Server HTTP 5 request gets promoted to WebSockets HTTP 5  ws://objectriver.net/… Port 80 Fire Wall Bi-directional full duplex WebSockets

4 Buy this book. This book describes the JSR356 Java WebSocket API specification. Today we are going to look at an example of a professional document style RPC mapping for WebSockets. JSR356 WebSocket API

Public class EchoServer public String echo(String msg) { Annotation is good for quick simple demos etc… Small programs like chat, logging, etc. But what is happening underneath? Annotation Programmatic vs. Annotation

6 It’s here now! WebSocket Server Stacks Web Application Web Server Application Glassfish 4JBoss WildFly Tomcat 8WebLogic 12c Jetty 9.1 Android Tyrus Client …

7 Endpoints Java Application Web Server stub Endpoints are listeners on their own thread. WebSockets is truly peer to peer. There is no request/response type methods in the architecture For synchronous requests, asynchronous responses must be synchronized on the client. Each client has it’s own connection and thread on the server. Endpoints are listeners on a thread endpoint stub Request Response Server Endpoint Client Endpoint

8 Full duplex True peer to peer requires a thread that is separate from the endpoint. This is required for an application that needs to turn the connection around where the server becomes the client and client becomes server. Separate execution thread on server Java Application Web Server stubendpoint Request stub Response Client Endpoint Server Endpoint

9 Hello World interface definition String[] String Boolean throwSomething) throws HelloException; Breakdown of request/responses – void hello(String hello, Boolean throwSomething); – void helloResponse(String[] result); – void raiseHelloException(HelloException ex); – void raiseWebSocketException(WebSocketException ex); Not your father’s Hello World Java Application Web Server hello(String hello, Boolean throwSomething); helloResponse(String[] result); raiseHelloException(HelloException ex); raiseWebSocketException(WebSocketException ex); Hello World Client Endpoint Server Endpoint

10 Java wait/notify synchronizes request hello_wait() Client Endpoint Application Client Stub WebSockets Web Server RPC Request RPC Response OnMethod() RPC Response Java Notify session Java Wait session Network Client sends request to server Client blocks on session with Java wait() with timeout from client handle Client endpoint in onMessage() wakes up client with Java notify synchronising two asynchronous methods

11 Sending Objects – sendObject(envelope) Today we will be using the object abstraction for marshalling data between the client and server. Fixed length Clob/Blob support – sendText() – sendBinary() Give me the pipe – getSendStream() – Java InputStream – getSendWriter() – Java Writer Binary & Text Transport

12 Basic Code layout Core WebSocket methods Application Web Server Client Stub Server Stub Server Endpoint Client Endpoint WebSockets Encode/Decode Decode/Encode Connect connectToServer() onOpen() Call Method sendObject(envelope) onMessage() Close disconnect() onClose() Method sendObject(envelope) Response onMessage() Method

13 ws:// : / / / web-apps In Tomcat this is the name of the war. Glassfish does not have a web-apps context-root This is the path leading to the application specific uri-path Application specific portion. Can contain templates, and rest style urls. Example: ws://example.org/employee/tools/chat web-apps=employee root-context=tools uri-path=chat ws://bank.com/stock/price?ticker=CRM web-apps=stock root-context=price uri-path=?ticker=CRM ws://localhost:8080/HelloApp/Test/Hello ws://localhost/HelloApp/Test/Hello URL Path

14 public class HelloMain { public static void main(String[] args) { HelloClient client = null; try { client = HelloClient.connect("ws://localhost:8101/HelloApp/Test/Hello“); String[] worlds = client.hello("Hello",false); for(String world: worlds) { System.out.println(world); } client.hello("Hello",true); } catch(HelloException ex) { System.out.println(ex.getMessage()); } catch(DeploymentException ex) { System.err.println(ex.getMessage()); } catch(WebSocketException ex) { ex.printCauseTrace(); } finally { if(client!=null) client.disconnect(); } Client-side Hello World Hello Implementation

15 public class HelloEndpointServerSessionImpl_V1 implements HelloEndpointServerInterface { protected Session session__ = null; public void onOpen(Session session, EndpointConfig endpointConfig) { this.session__ = session; } public void onClose(Session session, CloseReason closeReason) { } public void onError(Session session, java.lang.Throwable thr) { System.out.println(thr.getMessage()); thr.printStackTrace(); } /** * Implementation */ public String[] hello( String hello, Boolean throwSomething) throws HelloException { System.out.println(hello); if(throwSomething.booleanValue()) throw new HelloException("World"); return new String[]{"World","World","World","World"}; } Server-side Hello World Hello Implementation

16 public class HelloEnvelope_V1 extends HelloEnvelope { public HelloMethods method; // enumeration /** Documents */ protected HelloDocument_V1 helloDocument_V1; protected HelloResponseDocument_V1 helloResponseDocument_V1; protected HelloException helloException; /** getters / setters */ public HelloException getHelloException() public void setHelloException(HelloException helloException) public HelloDocument_V1 getHelloDocument_V1() public void setHelloDocument_V1(HelloDocument_V1 helloDocument_V1) public HelloResponseDocument_V1 getHelloResponseDocument_V1() public void setHelloResponseDocument_V1(HelloResponseDocument_V1 } Envelope contains a single document sendObject(Envelope)

17 public class HelloDocument_V1 { public HelloDocument_V1(String hello, Boolean throwSomething) { … } protected String hello; protected Boolean throwSomething; /** Getters /Setters */ } public class HelloResponseDocument_V1 { public HelloResponseDocument_V1(String[] result) { … } protected String[] result; /** Getters /Setters */ } public class HelloException extends WebSocketException { public HelloException(String message,Throwable cause) { super(message,cause); } Each method has documents Document

18 public static T connect(T client, String path) throws IOException, DeploymentException, URISyntaxException { WebSocketContainer wsc = ContainerProvider.getWebSocketContainer(); ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().configurator(new HelloClientConfigurator()).encoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).decoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).build(); client.session = wsc.connectToServer(client, clientEndpointConfig, new URI(path)); return client; } ClientEndpointConfig & connectToServer Connect & Client Config

19 public class HelloServerApplicationConfig implements ServerApplicationConfig { public Set getEndpointConfigs(Set > set) { return new HashSet () { { add(ServerEndpointConfig.Builder.create(HelloServerEndpoint.class, EndpointPathName).configurator(new HelloServerConfigurator()).encoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).decoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).build()); } }; } public Set > getAnnotatedEndpointClasses(Set > set) { return Collections.emptySet(); } ServerEndpointConfig Server-side Config

20 public String[] hello( String hello, Boolean throwSomething ) throws HelloException { HelloDocument_V1 inDoc = new HelloDocument_V1(hello,throwSomething); try { HelloEnvelope_V1 envelope = new HelloEnvelope_V1(); envelope.setMethod(HelloMethods.hello_1_instance); envelope.setHelloDocument_V1(inDoc); session.getBasicRemote().sendObject(envelope); } catch (EncodeException ex) { throw new WebSocketException("Encode Exception encoding hello”, ex); } catch (IOException ex) { throw new WebSocketException("IOException Encoding Hello, ex); } HelloResponseDocument_V1 outDoc = hello_wait(); String[] result = outDoc.getResult(); return result; } Stub packages document in envelopes Client Stub

21 public class HelloMessageHandler implements MessageHandler.Whole { protected HelloEndpointServerInterface_V1 impl = null; public HelloMessageHandler(HelloEndpointServerInterface_V1 impl) { this.impl = impl; } public void onMessage(HelloEnvelope envelope) { try { dispatch((HelloEnvelope_V1)envelope); } catch (Exception ex) { try { envelope.setMethod(HelloMethods.raiseWebSocketException_1_instance); envelope.setWebSocketException( new WebSocketException("onMessage() ", ex)); session.getBasicRemote().sendObject(envelope); } catch(IOException ignore) {} catch(EncodeException ignore) {} return; } Endpoint listeners for envelope Server Endpoint OnMessage

22 private void dispatch(HelloEnvelope_V1 envelope) { switch(envelope.getMethod().getEnum()) { case hello_1: { HelloDocument_V1 request = envelope.getHelloDocument_V1(); String hello = request.getHello(); Boolean throwSomething = request.getThrowSomething(); try { String[] result = impl.hello( hello, throwSomething ); HelloResponseDocument helloResponse = new HelloResponseDocument(); helloResponse.setResult(result); envelope.setMethod(HelloMethods.helloResponse_1_instance); envelope.setHelloResponseDocument_V1(helloResponse); } catch(HelloException ex) { envelope.setMethod(HelloMethods.raiseHelloException_1_instance); envelope.setHelloException(ex); } session.getBasicRemote().sendObject(envelope); } Dispatch calls remote method Server Endpoint Dispatch

23 Encode/Decode handlers Java Application Web Server encode JavaScript Application Binary Stream  XDR, IIOP, ASN1, ProtocolBuffers, etc… Text Stream  XML, JSON, etc… decodeencodedecode encodedecodeencode sendObject(envelope) sendObject(envelope) takes envelope object. Encode/Decode routines are added to session’s configuration, on client and server Envelope object is a choice object containing documents for all request and responses. Registered handler -> MessageHandler.Whole

24 ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create().configurator(new HelloClientConfigurator()).encoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).decoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).build(); Encoder and Decoder’s are the same class Register Client Encoders

25 public class HelloServerApplicationConfig implements ServerApplicationConfig { public Set getEndpointConfigs(Set > set) { return new HashSet () { { add(ServerEndpointConfig.Builder.create(HelloServerEndpoint.class, EndpointPathName).configurator(new HelloServerConfigurator()).encoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).decoders(Arrays. >asList( HelloBinaryStreamEnvelopeEncodeDecode.class, HelloTextStreamEnvelopeEncodeDecode.class )).build()); } }; } Encoder and Decoder’s are the same class Register Server Encoders

26 public class XdrHelloDocument_V1 extends XdrMarshal { public boolean execute(XDR xdrs, XdrThing thing1) throws WebRpcMarshallingException { HelloDocument_V1 request_response = (HelloDocument_V1) thing1.getThing(); XdrThing thing2 = new XdrThing(); if(xdrs.x_op== XDR.op.XDR_DECODE) { request_response = new HelloDocument_V1(); thing1.setThing(request_response); } try { thing2.setThing(request_response.getHello()); if(!xdr_string.instance.execute(xdrs, thing2)) { return false; } request_response.setHello((String)thing2.getThing()); thing2.setThing(request_response.getThrowSomething()); if(!xdr_pointer(xdrs, thing2, xdr_bool.instance)) { return false; } request_response.setThrowSomething((Boolean)thing2.getThing()); } HelloDocument Binary Encode/Decode Binary XDR Encode/Decode

27 public class JsonHelloDocument_V1 extends JsonMarshal { public boolean execute(JSON jsons, JsonThing thing1) throws WebRpcMarshallingException { HelloDocument_V1 request_response = (HelloDocument_V1) thing1.getThing(); JsonThing thing2 = new JsonThing(); if(jsons.x_op== JSON.op.JSON_DECODE) { request_response = new HelloDocument_V1(); thing1.setThing(request_response); } try { thing2.setJvalue("hello",request_response.getHello()); if(!json_string.instance.execute(jsons, thing2)) { return false; } request_response.setHello((String)thing2.getThing()); jsons.separator(); thing2.setJvalue("throwSomething",request_response.getThrowSomething()); if(!json_pointer(jsons, thing2, json_bool.instance)) { return false; } request_response.setThrowSomething((Boolean)thing2.getThing()); } catch (JsonParsingException ex) { throw new WebRpcMarshallingException("JsonHelloDocument_V1",ex); } HelloDocument Text Encode/Decode Text JSON Encode/Decode

28 Server Architecture Session Server – This is where each client has it’s own statefull copy of the server’s implementing class. – The state lasts for the duration of the WebSockets session with the client – It’s exactly like each client have it’s own copy of the server. Singleton Server – This is where there is a single instance of the implementing class, and the server’s state is shared. – Therefore multiple client threads of execution are executing on the single singleton class. – Implementing class must be thread safe. – Individual client state can be stored in the sessions user properties. Session vs Singleton Server

29 Session Server Client 1 Web Server Client 2 Session Server – This is where each client has it’s own state-full copy of the server’s implementing class. – The state lasts for the duration of the WebSockets session with the client – It’s exactly like each client have it’s own copy of the server. Implementation Class Implementation Class

30 WebSocket Endpoints are session objects public class HelloServerEndpoint extends Endpoint { protected HelloEndpointServerInterface_V1 impl = null; … public void onOpen(final Session session, EndpointConfig config) { impl = new HelloEndpointServerSessionImpl(); … Session Server

31 Singleton Server Client 1 Web Server Client 2 Singleton Server – This is where there is a single instance of the implementing class, and the server’s state is shared. – Therefore multiple client threads of execution are executing on the single singleton class. – Implementing class must be thread safe. – Individual client state can be stored in the sessions user properties. Implementation Singleton Class

32 Singleton design pattern public class HelloServerEndpoint extends Endpoint { protected HelloEndpointServerInterface_V1 impl = null; … public void onOpen(final Session session, EndpointConfig config) { HelloEndpointServerInterface_V1 impl = HelloEndpointServerInterface_V1.getInstance(); …} public class HelloEndpointServerInterface_V1 implements ServerEndPointInterface { private static HelloEndpointServerInterface_V1 ourInstance; public synchronized static HelloEndpointServerInterface_V1 getInstance() { if (ourInstance == null) { ourInstance = new HelloEndpointServerInterface_V1 (); } return ourInstance; } Singleton Server

33 Standard Java sockets interface for the web. Full duplex Low latency Complex data Example from presentation – Steven Lemmo CTO & Founder ObjectRiver Inc Summary