arch-3: context management in the openedge® reference architecture john sadd engineering fellow and...
TRANSCRIPT
ARCH-3: Context Management in the OpenEdge® Reference Architecture
John Sadd
Engineering Fellow and OpenEdge Evangelist
© 2006 Progress Software Corporation2ARCH-3 Context Management in the OERA
Agenda
Client to Database – a brief history AppServer™ modes and issues Thinking about procedures and context Maintaining context on the client Maintaining context on the server Conclusions
© 2006 Progress Software Corporation3ARCH-3 Context Management in the OERA
The good (very) old days: host-based
FIND FIRST Customer
FIND NEXT Customer
/* Process Customer 1 */
/* Process Customer 2 */
Everything on one box
© 2006 Progress Software Corporation4ARCH-3 Context Management in the OERA
The good (not so) old days: client/server
FIND FIRST Customer
FIND NEXT Customer
/* Process Customer 1 */
/* Process Customer 2 */
Clien
t ne
two
rkin
g
Client PC Server
© 2006 Progress Software Corporation5ARCH-3 Context Management in the OERA
Client/server limitations: Performance
FIND FIRST Customer
FIND NEXT Customer
/* Process Customer 1 */
/* Process Customer 2 */
Clien
t ne
two
rkin
g
Client PC
All code executes on the client
Server
© 2006 Progress Software Corporation6ARCH-3 Context Management in the OERA
Client/server limitations: OpenEdge client platform only
FIND FIRST Customer
FIND NEXT Customer
/* Process Customer 1 */
/* Process Customer 2 */
Clien
t ne
two
rkin
g
Server
© 2006 Progress Software Corporation7ARCH-3 Context Management in the OERA
What to do, what to do…
Host-basedClient/Server
AppServer
© 2006 Progress Software Corporation8ARCH-3 Context Management in the OERA
OpenEdgeAppServer
PO ProDataSet™
The Bigger Picture – Today and Tomorrow
Purchase Order Business Logic
HeaderData
DetailData
OtherData
PurchaseOrderProxy
.NET™ User Interface
Jonas Grumby
110 Desert Isle Path
Minnow, HI
OK
Cancel
C#
OpenEdge.NET Interface
Flexibility for client platforms and integration needs
ABL or
WebSpeed™
Interface
WebClient™ / HTML
User InterfaceJonas Grumby
110 Desert Isle Path
Minnow, HI
OK
Cancel
OpenEdgeABL Interface
ABL
OpenEdgeWeb Services Interface
© 2006 Progress Software Corporation9ARCH-3 Context Management in the OERA
Agenda
Client to Database – a brief history AppServer modes and issues Thinking about procedures and context Maintaining context on the client Maintaining context on the server Conclusions
© 2006 Progress Software Corporation10ARCH-3 Context Management in the OERA
Improving network performance with the AppServer
RUN CustProc.p ON hAppServ
(“FIRST”, OUTPUT ttCust)C
ustP
roc.p
Client AppServer
Business logic code
executes on the server
© 2006 Progress Software Corporation11ARCH-3 Context Management in the OERA
Using a bound AppServer session in “state-aware” mode
RUN FindCust IN hCust
(“FIRST”, OUTPUT ttCust)
RUN FindCust IN hCust
(“NEXT”, OUTPUT ttCust)
/* Process Customer 1 */
/* Process Customer 2 */
RUN CustProc.p ON hAppServer
PERSISTENT set hCust.C
ustP
roc.p
Client AppServer
© 2006 Progress Software Corporation12ARCH-3 Context Management in the OERA
Scalability and bound AppServers
client
client
client
client
client
client
AppServer session
AppServer session
AppServer session
AppServer session
AppServer session
AppServer session
© 2006 Progress Software Corporation13ARCH-3 Context Management in the OERA
Using the AppServer in “stateless” mode
AppServer session
AppServer session
AppServer session
AppServer session
AppServer session
AppServer session
Ap
pS
erver bro
ker
All clien
t requ
ests
© 2006 Progress Software Corporation14ARCH-3 Context Management in the OERA
Using the AppServer in “stateless” mode– FIND FIRST
AppServer session 1
AppServer session
AppServer session
AppServer session
AppServer session
AppServer session
Ap
pS
erver bro
ker
RUN CustProc.p ON hAS
(“FIRST”, OUTPUT ttCust)
© 2006 Progress Software Corporation15ARCH-3 Context Management in the OERA
Using the AppServer in “stateless” mode – FIND NEXT
AppServer session
AppServer session 2NEXT What??
AppServer session
AppServer session
AppServer session
AppServer session
Ap
pS
erver bro
ker
RUN CustProc.p ON hAS
(“NEXT”, OUTPUT ttCust)
© 2006 Progress Software Corporation16ARCH-3 Context Management in the OERA
Advantages to using stateless mode
Allows sharing of server resources by many clients Promotes scalability Allows for load balancing and other optimizations Allows AppServer access from other platforms
© 2006 Progress Software Corporation17ARCH-3 Context Management in the OERA
Challenges using stateless mode
Can’t run procedures PERSISTENT without binding the AppServer session• Server procedure won’t keep track of you
• Can’t run internal procedures
Can’t get a procedure handle for non-persistent procedures
Can’t maintain client-specific context within an AppServer session
© 2006 Progress Software Corporation18ARCH-3 Context Management in the OERA
Unmanaged “state-free” mode
Not even a persistent CONNECTION-ID for the AppServer broker
Recommended for use with Web services or other connectionless environment• Service-Oriented Application on the bus
Issues are essentially the same as with stateless
© 2006 Progress Software Corporation19ARCH-3 Context Management in the OERA
Agenda
Client to Database – a brief history AppServer modes and issues Thinking about procedures and context Maintaining context on the client Maintaining context on the server Conclusions
© 2006 Progress Software Corporation20ARCH-3 Context Management in the OERA
Context Management Basics
Target environment is client to stateless or statefree AppServer
Each interaction is independent Maintain context between related interactions
© 2006 Progress Software Corporation21ARCH-3 Context Management in the OERA
Dealing with context in a stateless world: binding for the duration of a task
Run a procedure PERSISTENT on a stateless AppServer session• This binds the session for the life of the
procedure
• Supports multiple calls that are part of a single ‘task’
• The session is unbound when the procedure instance is deleted
© 2006 Progress Software Corporation22ARCH-3 Context Management in the OERA
Managing context for a task
Agreement
Validate
Customer if ? then
Context
Enter
Order if ? then
Confirm
Inventory if ? then
Calculate
Price if ? then
Agreement
Order
Entry
Task
Agreement
Customer Entity
Order Entity
Inventory Entity
Pricing Entity
© 2006 Progress Software Corporation23ARCH-3 Context Management in the OERA
Managing a task by binding a stateless AppServer
Agreement
Validate Customer
if ?
Context
Enter
Order
if
?
Confirm
Inventory
if ? Calculate
Price
if ?Agreement
Task
Agreement
Client
RUN PERSISTENT
DELETE PROCEDURE
AppServer
This method is strongly discouraged!• Uncontrolled binding to client
• Not suitable for SOA direction
© 2006 Progress Software Corporation24ARCH-3 Context Management in the OERA
Accessing shared procedure instances
Pre-start commonly used PERSISTENT procedures as part of AppServer start-up
Use a ‘gateway’ (Service Interface) procedure to route client requests
Or: • Have the Service Interface start procedures
the first time they are needed Session manager on the server
© 2006 Progress Software Corporation25ARCH-3 Context Management in the OERA
Using a Service Interface procedure and session manager
Client Server
UI Procedure
DATASET dsOrder
Business Entity
DATASET dsOrder
Data-Access Object
DATASET dsOrder
RUN fetchOrder
IN hdsOrder
(. . . ,
OUTPUT
DATASET
dsOrder
BY-REFERENCE)
RUN FetchWhere
IN hEntity
(. . .,
OUTPUT
DATASET
phFetchDataSet
BY-REFERENCE)
fetchWhere:
FILL
ATTACH
Cli
ent
Pro
xy
Ser
vice
In
terf
ace
Session Manager
© 2006 Progress Software Corporation26ARCH-3 Context Management in the OERA
Using a Session Manager
DEFINE TEMP-TABLE ttEntity FIELD EntityName AS CHARACTER
FIELD EntityHandle AS HANDLE FIELD DAOHandle AS HANDLE INDEX EntityName EntityName.
FUNCTION getEntityHandle RETURNS HANDLE (INPUT pcEntityName AS CHARACTER): DEFINE VARIABLE hEntity AS HANDLE. FIND FIRST ttEntity WHERE ttEntity.EntityName
= pcEntityName NO-ERROR. IF NOT AVAILABLE (ttEntity) THEN hEntity = startEntity(pcEntityName). ELSE hEntity = ttEntity.EntityHandle. RETURN hEntity.END FUNCTION. /* getEntityHandle */
© 2006 Progress Software Corporation27ARCH-3 Context Management in the OERA
Using a Session Manager - 2
FUNCTION startEntity RETURNS HANDLE (INPUT pcEntityName AS CHARACTER): DEFINE VARIABLE hEntity AS HANDLE. DEFINE VARIABLE hAccess AS HANDLE. RUN VALUE("be" + pcEntityName + ".p") PERSISTENT SET hEntity NO-ERROR. IF VALID-HANDLE(hEntity) THEN DO:
CREATE ttEntity. ASSIGN ttEntity.EntityName = pcEntityName ttEntity.EntityHandle = hEntity. END. RETURN hEntity.END FUNCTION. /* startEntity */
© 2006 Progress Software Corporation28ARCH-3 Context Management in the OERA
Alternatives for maintaining context
Pass context information back and forth between client and server• The context is held on the client
Store context between client requests in a shared data store • All AppServer sessions can read and write it
• The context is held on the server
© 2006 Progress Software Corporation29ARCH-3 Context Management in the OERA
Using the AppServer in “stateless” mode
AppServer session
AppServer session
AppServer session
AppServer session
AppServer session
AppServer session
Ap
pS
erver bro
ker
All clien
t requ
ests
© 2006 Progress Software Corporation30ARCH-3 Context Management in the OERA
Agenda
Client to Database – a brief history AppServer modes and issues Thinking about procedures and context Maintaining context on the client Maintaining context on the server Conclusions
© 2006 Progress Software Corporation31ARCH-3 Context Management in the OERA
Passing Context between Client and Server
Context/Parameter temp-table passes context back and forth
Name & Value fields allow flexibility Or just use a delimited list in a CHAR param Context is maintained on the client Useful for moderate amounts of data
• Also for context used on the client
• And for context modified on the client
© 2006 Progress Software Corporation32ARCH-3 Context Management in the OERA
context/parameter
temp-table
Context Between Client and Server -- Batching
Client Server
UI Procedure
DATASET dsOrder
Business Entity
DATASET dsOrder
RUN fetchOrder
IN hdsOrder
(. . . ,
OUTPUT
DATASET
dsOrder
BY-REFERENCE)
RUN FetchWhere
IN hEntity
(. . .,
OUTPUT
DATASET
phFetchDataSet
BY-REFERENCE)
Clie
nt
Pro
xy P
roce
du
re
Ser
ver
Gat
eway
Pro
ced
ure
WhereString = “…”
NextRowid = 63524
© 2006 Progress Software Corporation33ARCH-3 Context Management in the OERA
Using a context temp-table
FIND ttContext WHERE ttContext.ContextName = "WhereString" NO-ERROR.IF NOT AVAILABLE(ttContext) THENDO: CREATE ttContext. ttContext.ContextName = "WhereString".END.ttContext.ContextValue = "OrderNum = " + STRING(iOrderNum).
/* …and the same for NextRowid */
Useful for any flexible set of parameters or context values in a single interface
© 2006 Progress Software Corporation34ARCH-3 Context Management in the OERA
Agenda
Client to Database – a brief history AppServer modes and issues Thinking about procedures and context Maintaining context on the client Maintaining context on the server Conclusions
© 2006 Progress Software Corporation35ARCH-3 Context Management in the OERA
Context Maintained on the Server
Hold context in a shared server-side data store• Typically a database table
Useful for context not to pass back and forth• Session context such as language, authorization
that does not change
• Also useful for large amounts of context data
Storing context on the server can be the best universal approach
© 2006 Progress Software Corporation36ARCH-3 Context Management in the OERA
Built-in support for UUIDs and GUIDs in 10.1A
Requires a Context ID passed from the client GENERATE-UUID
• Universal Unique IDentifier• Returns a 16-byte RAW (binary) value• Guaranteed unique across all space and time
GUID (<uuid-value> )• Global Unique IDentifier• Converts a UUID into a 36-character GUID
– XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
SUBSTRING(BASE64-ENCODE(GENERATE-UUID),1,22)• Yields a more compact 22-character string
© 2006 Progress Software Corporation37ARCH-3 Context Management in the OERA
Context ID parameter
Context Stored on the Server
Client Server
UI Procedure
DATASET dsOrder
Business Entity
DATASET dsOrder
RUN fetchOrder
IN hdsOrder
(. . . ,
OUTPUT
DATASET
dsOrder
BY-REFERENCE)
RUN FetchWhere
IN hEntity
(. . .,
OUTPUT
DATASET
phFetchDataSet
BY-REFERENCE)
Clie
nt
Pro
xy P
roce
du
re
Ser
ver
Gat
eway
Pro
ced
ure
ContextID = 95847
Context
95847 English Auth …
© 2006 Progress Software Corporation38ARCH-3 Context Management in the OERA
ProDataSet and Temp-Table Context
Store retrieved data in a context table• For WebSpeed or other clients with no
ProDataSet support
• RAW fields and BLOBs for generic storage
• Or store as XML in CHARACTER format
Store successive updates before commit• Allows partial validation on the server
• Final update ProDataSet rebuilt from context
© 2006 Progress Software Corporation39ARCH-3 Context Management in the OERA
ProDataSet or Temp-Table Data as Context
Client Server
Web browser Business Entity
DATASET dsOrderBrowser code
RUN FetchWhere
IN hEntity
(. . .,
OUTPUT
DATASET
phFetchDataSet
BY-REFERENCE)
Ser
ver
Gat
eway
Pro
ced
ure
ContextID = 95847
Context
95847 Order 1 Line 1
95847 Order 1 Line 2
95847 Order 1 Line 1
“OrderNum = 1”
95847 Ord 1 L 1 Q 20
95847 Ord 1 L 1 Q 20
Application
© 2006 Progress Software Corporation40ARCH-3 Context Management in the OERA
Defining a context management table
SessionID – identify a client session ContextID – identify a specific task or transaction
within a session ContextName – Table name or other tag (like
‘WhereString’) ContextValue – Primary key value for a table, or
string value for another tag isBeforeRow – flag for ProDataSet rows RowSequence – for ordering table rows TimeStamp – when the row was created or last
updated (also a DeleteTime for cleanup) RawData – temp-table row data
© 2006 Progress Software Corporation41ARCH-3 Context Management in the OERA
Creating a context row
phBuffer:RAW-TRANSFER(TRUE, /* from buffer to RAW */
BUFFER ContextStore:BUFFER-FIELD("RawData")).
ASSIGN ContextStore.TimeStamp = NOW ContextStore.DeleteTime = DATETIME-TZ( DATE(NOW) + 1, MTIME (NOW), TIMEZONE(NOW)).
CREATE ContextStore.ASSIGN ContextStore.ContextID = pcContextID ContextStore.ContextName = phBuffer:Name ContextStore.ContextValue = cKeyValues ContextStore.RowSequence = piSequence ContextStore.isBeforeRow = FALSE.
© 2006 Progress Software Corporation42ARCH-3 Context Management in the OERA
ContextStore rows
wxyz eOrder 27 1 FALSEabcd raw buffer
wxyz eOline 27 1 1 FALSEabcd raw buffer
wxyz eOline 27 2 2 FALSEabcd raw buffer
Sessio
nID
Co
ntextID
Co
ntextN
ame
Co
ntextV
alue
Ro
wS
equ
ence
isBefo
reRo
w
Raw
Data
© 2006 Progress Software Corporation43ARCH-3 Context Management in the OERA
RAW-TRANSFER limitations
Low-level – does not recognize fields or other buffer specifics
Temp-table definitions must match exactly Use for short-term storage
© 2006 Progress Software Corporation44ARCH-3 Context Management in the OERA
Agenda
Client to Database – a brief history AppServer modes and issues Thinking about procedures and context Maintaining context on the client Maintaining context on the server Conclusions
© 2006 Progress Software Corporation45ARCH-3 Context Management in the OERA
Design for the OpenEdge AppServer
AppServer lets you locate business logic where it belongs to improve performance
AppServer is the basis for all Open Client access, .NET support, Web services, etc.
Stateless or statefree mode gives you the greatest flexibility and scalability
Avoid binding the AppServer to a client session
© 2006 Progress Software Corporation46ARCH-3 Context Management in the OERA
Design context management into your application as a “feature”
Store small amounts of context on client Store larger amounts of data on server Design general solutions into your application
architecture Consider needs of platforms like WebSpeed
and Web services for SOA
© 2006 Progress Software Corporation47ARCH-3 Context Management in the OERA
Design for the future
Prepare your application for future requirements• WebSpeed for a browser-based UI
• .NET, PDA, or other new UI platforms
• Access as Web Services
• Service Oriented Architecture
© 2006 Progress Software Corporation48ARCH-3 Context Management in the OERA
PSDN white papers on Implementing the OpenEdge Reference Architecture
-- The Service Interface Layer
-- Context Management
© 2006 Progress Software Corporation49ARCH-3 Context Management in the OERA
Questions?
© 2006 Progress Software Corporation50ARCH-3 Context Management in the OERA
Thank you foryour time
© 2006 Progress Software Corporation51ARCH-3 Context Management in the OERA