ARCH4 A Stateful Application in a Stateless World













































- Slides: 45
ARCH-4: A Stateful Application in a Stateless World Jamie Townsend Solutions Architect EMEA
Agenda § The problem with Stateless today § Different kinds of “State” § Maintaining State § The Ideal Solution § Getting There § Conclusions 2 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
The good (very) old days: host-based FIND FIRST Customer /* Process Customer 1 */ FIND NEXT Customer /* Process Customer 2 */ Everything on one box 3 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
The good (not so) old days: client/server FIND FIRST Customer /* Process Customer 1 */ /* Process Customer 2 */ All code executes on the client Client networking FIND NEXT Customer Server 4 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Improving network performance with the App. Server (“FIRST”, OUTPUT tt. Cust) Cust. Proc. p RUN Cust. Proc. p ON h. App. Serv Business logic code executes on the server Client 5 ARCH-4: A stateful application in a stateless world App. Server™ © 2007 Progress Software Corporation
Using a bound App. Server session in state-aware/state-reset mode PERSISTENT set h. Cust. RUN Find. Cust IN h. Cust (“FIRST”, OUTPUT tt. Cust) Cust. Proc. p RUN Cust. Proc. p ON h. App. Server /* Process Customer 1 */ RUN Find. Cust IN h. Cust (“NEXT”, OUTPUT tt. Cust) /* Process Customer 2 */ Client 6 ARCH-4: A stateful application in a stateless world App. Server © 2007 Progress Software Corporation
Session Managed Model State-Aware and State-Reset Operating Modes App. Server Client 1 Client 3 Agent 1 Name. Server Client 2 App. Server Agents Client 4 Agent 2 ABL Data Agent 3 Application Broker Message Queue 7 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Session Managed Model Stateless Operating Mode App. Server Client 1 Client 3 Agent 1 Name. Server Client 2 Client 4 8 App. Server Agents ARCH-4: A stateful application in a stateless world Agent 2 Application Broker ABL Data Agent 3 Message Queue © 2007 Progress Software Corporation
Using the App. Server in stateless mode– FIND FIRST App. Server broker RUN Cust. Proc. p ON h. AS (“FIRST”, OUTPUT tt. Cust) App. Server session 1 App. Server session 9 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Using the App. Server in stateless mode – FIND NEXT App. Server broker RUN Cust. Proc. p ON h. AS (“NEXT”, OUTPUT tt. Cust) App. Server session 2 NEXT What? ? App. Server session 10 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
The Problem Simply migrating your application to stateless App. Servers does not mean you have a stateless application 11 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Agenda § The problem with Stateless today § Different kinds of “State” § Maintaining State § The Ideal Solution § Getting There § Conclusions 12 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Context vs. State vs. Operating Parameters § Context § State • UI State (no impact on business logic) • Business Logic Object State § Operating Parameters 13 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Context § “Fixed” data for a session • Eg. User Name, Login Company, Language § Must be restored with each Service Request • Should be kept as small as practical § Use CLIENT-PRINCIPAL 14 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Context § Using the CLIENT-PRINCIPAL • • Instantiate (Authenticate) & Seal What to contain? CLIENT-PRINCIPAL USER-ID Serialise/Deserialise SESSION-ID How many? ROLES § Pass or Store DOMAIN-NAME … • Context database must be secure and fast 15 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Business Logic Object State § “Volatile” data for a session • Eg. variable value, temp-tables, query position, etc. § In Existing Application • Possibly (probably) long lived • May span multiple App. Server Requests § In SOA Application • Should not span Service Requests – Not stored on server side 16 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Operating Parameters § “Fixed” data for single Service Request • Passed Client to Server and back • Pass minimal dataset required § Eg. Current Customer, Complete Order, etc. 17 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Agenda § The problem with Stateless today § Different kinds of “State” § Maintaining “State” § The Ideal Solution § Getting There § Conclusions 18 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Sample Business Logic Order Entry Task Agreement Validate Customer Agreement if ? then Customer Entity Confirm Inventory Entity 19 ARCH-4: A stateful application in a stateless world if ? then Order Entity Agreement if ? then Enter Order Calculate Price if ? then Pricing Entity © 2007 Progress Software Corporation
Managing a task by …binding a stateless App. Server Validate RUN PERSISTENT if ? Agreement Customer Enter if ? Order Task Agreement Confirm Inventory if ? Agreement Calculate Price DELETE PROCEDURE Context Client App. Server § This method is strongly discouraged! - Uncontrolled binding to client - Not suitable for SOA direction 20 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Managing a task by …passing state RUN. . . State State Client Validate if ? Agreement Customer Enter if ? Order Task Agreement Confirm Inventory if ? Agreement Calculate Price Context App. Server § This method is better + Stateless AS - Client Maintains State 21 ARCH-4: A stateful application in a stateless world - SOA design - Performance © 2007 Progress Software Corporation
Managing a task by …saving state RUN. . . if ? Task Agreement RUN. . . if ? OP OP Validate Customer Enter Order Agreement RUN. . . if ? OP OP Agreement RUN. . . OP OP Client Confirm Inventory State Store Calculate Price App. Server § This is an alternative ? Performance - Service Request Dependency - Not SOA - Client must “know” state 22 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Agenda § The problem with Stateless today § Different kinds of “State” § Maintaining State § The Ideal Solution § Getting There § Conclusions 23 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
The Bigger Picture – Today and Tomorrow § Flexibility for client platforms and integration needs Open. Edge. NET Interface . NET™ User Interface Jonas Grumby 110 Desert Isle Path Minnow, HI OK Cancel Purchase Order Proxy Open. Edge® App. Server Purchase Order Business Logic Header Data PO Pro. Data. Set™ Detail Data C# Other Data Web. Client™ / HTML User Interface Jonas Grumby 110 Desert Isle Path Minnow, HI OK Cancel ABL or Web. Speed Interface Open. Edge ABL Interface Open. Edge Web Services Interface ABL 24 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Encapsulation Required for SOA Call Business Task SOA Client OP OP Validate Customer Enter Order Confirm Inventory Calculate Price App. Server § True SOA Application + Granular + Service Request Independency ? Performance 25 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Encapsulation Required for SOA Call Business Task SOA Client RUN. . . OP OP if ? Task Agreement RUN. . . if ? OP OP Agreement RUN. . . App. Server OP OP Validate Customer Enter Order Confirm Inventory Calculate Price App. Server § True SOA Application + Granular + Service Request Independency ? Performance 26 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Agenda § The problem with Stateless today § Different kinds of “State” § Maintaining State § The Ideal Solution § Getting There § Conclusions 27 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? § Pass required data as parameters § Refactor any “Block 0” objects DEFINE SHARED. . . VARIABLE TEMP-TABLE QUERY . . . that change value 28 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? AND DON’T FORGET… Default Buffers for Database Tables!! PROCEDURE my. Proc: DEFINE BUFFER Customer FOR Customer. END PROCEDURE. 29 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? DEFINE SHARED VARIABLE c. User AS CHARACTER DEFINE VARIABLE c. Where AS CHARACTER DEFINE QUERY q. Cust FOR customer. NO-UNDO. PROCEDURE initialise. Query: c. Where = "salesrep = '" + c. User + "'". QUERY q. Cust: QUERY-PREPARE( "FOR EACH Customer WHERE " + c. Where). QUERY q. Cust: QUERY-OPEN(). END PROCEDURE get. Next. Cust. Num: DEFINE OUTPUT PARAMETER p. Cust. Num AS INTEGER INIT ? . QUERY q. Cust: GET-NEXT(). IF AVAILABLE(Customer) THEN p. Cust. Num = Cust. Num. END PROCEDURE. 30 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? RUN initialise. Query ON h. AS. REPEAT: RUN get. Next. Cust. Num ON h. AS (OUTPUT i. Cust. Num). IF i. Cust. Num = ? THEN LEAVE. DISPLAY i. Cust. Num. END. 31 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? DEFINE SHARED VARIABLE c. User AS CHARACTER DEFINE VARIABLE c. Where AS CHARACTER DEFINE QUERY q. Cust FOR customer. NO-UNDO. PROCEDURE initialise. Query: c. Where = "salesrep = '" + get. User() c. User + "'". QUERY q. Cust: QUERY-PREPARE( "FOR EACH Customer WHERE " + c. Where). QUERY q. Cust: QUERY-OPEN(). END PROCEDURE get. Next. Cust. Num: DEFINE OUTPUT PARAMETER p. Cust. Num AS INTEGER INIT ? . QUERY q. Cust: GET-NEXT(). IF AVAILABLE(Customer) THEN p. Cust. Num = Cust. Num. END PROCEDURE. 32 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? DEFINE VARIABLE c. Where AS CHARACTER DEFINE QUERY q. Cust FOR customer. NO-UNDO. PROCEDURE initialise. Query: DEFINE VARIABLE c. Where AS CHARACTER NO-UNDO. c. Where = "salesrep = '" + get. User() + "'". QUERY q. Cust: QUERY-PREPARE( "FOR EACH Customer WHERE " " + + c. Where). "FOR QUERY q. Cust: QUERY-OPEN(). QUERY END PROCEDURE get. Next. Cust. Num: DEFINE OUTPUT PARAMETER p. Cust. Num AS AS INTEGER INIT ? . DEFINE QUERY q. Cust: GET-NEXT(). QUERY IF AVAILABLE(Customer) THEN p. Cust. Num = = Cust. Num. IF END PROCEDURE. 33 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? DEFINE QUERY q. Cust FOR customer. PROCEDURE initialise. Query: DEFINE VARIABLE c. Where AS CHARACTER NO-UNDO. c. Where = "salesrep = '" + get. User() + "'". QUERY q. Cust: QUERY-PREPARE( "FOR EACH Customer WHERE " + c. Where). QUERY q. Cust: QUERY-OPEN(). END PROCEDURE get. Next. Cust. Num: DEFINE OUTPUT PARAMETER p. Cust. Num AS INTEGER INIT ? . QUERY q. Cust: GET-NEXT(). IF AVAILABLE(Customer) THEN p. Cust. Num = Cust. Num. END PROCEDURE. 34 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? PROCEDURE initialise. Query PRIVATE: DEFINE INPUT PARAMETER ph. QSales AS HANDLE NO-UNDO. DEFINE VARIABLE c. Where AS CHARACTER NO-UNDO. c. Where = "salesrep = '" + get. User() + "'". ph. QSales: QUERY-PREPARE( "FOR EACH Customer WHERE " + c. Where). ph. QSales: QUERY-OPEN(). Position Query END PROCEDURE get. Next. Cust. Num: DEFINE OUTPUT PARAMETER p. Cust. Num AS INTEGER INIT ? . DEFINE QUERY q. Cust FOR customer. RUN initialise. Query(QUERY q. Cust: HANDLE). QUERY q. Cust: GET-NEXT(). IF AVAILABLE(Customer) THEN p. Cust. Num = Cust. Num. END PROCEDURE. 35 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? RUN initialise ON h. AS. REPEAT: RUN get. Next. Cust. Num ON h. AS (OUTPUT i. Cust. Num). Current Cust. Num IF i. Cust. Num = ? THEN LEAVE. DISPLAY i. Cust. Num. END. 36 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
What do I need to change? DEFINE TEMP-TABLE tt. Cust FIELD Cust. Num AS INTEGER. RUN get. List. Of. Cust. Nums ON h. AS (OUTPUT TABLE tt. Cust. Nums). FOR EACH tt. Cust: DISPLAY tt. Cust. Num. END. 37 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Encapsulation Required for SOA Call Business Task RUN. . . OP if ? OP Task Agreement RUN. . . if ? SOA Client Customer Enter Order Agreement RUN. . . if ? Validate Agreement RUN. . . App. Server Confirm Inventory Calculate Price App. Server § True SOA Application + Granular + Service Request Independency + Performance 38 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Agenda § The problem with Stateless today § Different kinds of “State” § Maintaining State § The Ideal Solution § Getting There § Conclusions 39 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Conclusions § Stateless App. Server <> Stateless Application § Stateless Application requires Stateless Design § Test with stateless App. Servers 40 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
In Other Words § Stateless is not hard… App. Server <> …making perform is Statelessit. Application Stateless Application § Refactoring Stateless Design isrequires not redesign!! Test with stateless App. Servers § Develop stateless App. Servers 41 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Relevant Exchange Sessions 42 § ARCH-1: Application Architecture Made Simple § ARCH-13: Transactions in an SOA World § INT-3: Realistic Service Oriented Architecture Approaches § INT-10: Understanding The App. Server, Inside-out ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Questions? 43 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
Thank you for your time 44 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation
45 ARCH-4: A stateful application in a stateless world © 2007 Progress Software Corporation