SAP Fiori和WebClient UI的有狀態和無狀態行為設計原理
As is almost known to us all, Fiori ( at least deployed in Netweaver having ABAP as backend ) has stateless behavior and CRM WebClient UI is a set of stateful application. Physically both are running on ABAP Netweaver using ABAP BSP application. How are this different behavior implemented? There are documentation in SAP help about stateful and stateless BSP application. It is mentioned there:
Stateless
In the stateless case, the context is created each time that a request is received. The context is always destroyed when the response is sent. For the BSP runtime stateless means: runtime->keep_context = 0
Stateful
In the stateful case, the context is held by gone request to the next. For the BSP runtime stateful means: runtime->keep_context = 1 As a Fiori/CRM Webclient UI developer, the above mentioned difference is taken care by framework and completely transparent to me. The only point I need to be careful is that when I am developing service in the backend for stateful application, I can consider introducing some session buffer for performance improvement which will not work in stateless scenario.
Nevertheless I am still curious how framework treats these two kinds of application differently. PRD01 is a CRM Webclient UI component which I am responsible for. In SE80 the checkbox “Stateful” is marked as true.
CRM_OPPRTNTY is for CRM Fiori application “My Opportunity”, where “Stateful” is false.
How does ABAP HTTP framework treat this flag set in BSP application?
I debug the HTTP process implementation against a HelloWorld BSP application with stateful checkbox marked with true and draw the following diagram:
The stateful related evaluation and handling are involved in the following framework process steps.
(1) Buffer check in CL_HTTP_SERVER~EXECUTE_REQUEST ( red diamond )
The buffer is maintained in internal table http_ext_instances of CL_HTTP_SERVER.
When the index.html of BSP application is initially opened, no handler is created so buffer table is empty, create instance for the first time:
The instantiation of CL_HTTP_EXT_BSP will call CONSTRUCTOR of CL_BSP_RUNTIME and CL_BSP_CONTEXT, as displayed in the diagram.
(2) CL_HTTP_EXT_BSP~HANDLE_REQUEST
Once BSP handler CL_HTTP_EXT_BSP is initialized, its method HANDLE_REQUEST is called. Inside this method, method ANALYZE_URL ( green block in diagram ) of CL_BSP_RUNTIME is called to evaluate the accessed BSP application is stateful or stateless.
From the source code below we can know that the Stateful checkbox value for a given BSP application is stored in table o2appl, field stateful:
This stateful checkbox value will be filled to c_context->m_app_stateful:
And c_context->m_app_stateful will be used to fill if_bsp_runtime~keep_context:
Notice that before method ON_REQUEST_LEAVE is entered, its field KEEP_CONTEXT has value 1, which is consistent as what SAP help mentions.
(3) CL_BSP_RUNTIME~ON_REQUEST_LEAVE In ON_REQUEST_LEAVE ( purple in diagram ), since keep_context is and server->stateful is 0 ( default value ), so IF branch starting from line 42 is executed.
Here cookie field sap-contextid is set, and server->stateful is set as 1. This flag will be evaluated in the last step.
(4) buffer insertion If flag server->stateful set in previous step has value 1, currently instance of CL_HTTP_EXT_BSP is buffered.
Later when other requests from the same BSP application is raised, EXECUTE_REQUEST will be called again and this time the buffered BSP handler instance is used to serve the request:
So far we have gone through all branches in my diagram. The relationship among CL_HTTP_EXT_BSP, CL_BSP_RUNTIME, CL_BSP_CONTEXT could be found from below picture:
Further reading
So far this blog discusses the difference of Stateful and Stateless handling done in server side. For different behavior in client side, please refer to this blog: Stateless and Stateful – Different behavior in application side.
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2714423/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP BSP應用有狀態和無狀態行為差異比較
- 架構設計(五):有狀態服務和無狀態服務架構
- 系統設計架構:有狀態與無狀態架構
- SAP CRM WebClient UI和Fiori UI混搭並存WebclientUI
- 如何證明CRM WebClient UI上的應用是有狀態(Stateful)的WebclientUI
- 執行緒狀態和鎖執行緒
- 【架構設計】無狀態狀態機在程式碼中的實踐架構
- SAP 電商雲 UI State persistence 狀態持久化設計的入口 - initSyncUI持久化
- SAP 電商雲 Spartacus UI 有狀態 的 url 和 title 屬性的賦值程式碼UI賦值
- 物件導向程式設計和根本狀態物件程式設計
- 行為型設計模式 - 狀態模式詳解設計模式
- iOS UI狀態儲存和恢復(三)iOSUI
- 狀態機設計
- 工作流從無狀態切換到有狀態的好處
- 設計模式--直譯器模式和狀態模式設計模式
- 死鎖避免中的安全狀態和不安全狀態
- Flink的狀態程式設計和容錯機制(四)程式設計
- 狀態模式的理解和示例模式
- Memcached 多執行緒和狀態機執行緒
- 直播app原始碼,狀態列和導航欄設定成透明狀態APP原始碼
- 用設計模式去掉沒必要的狀態變數 —— 狀態模式設計模式變數
- HTTP狀態保持的原理HTTP
- 設計模式:狀態模式設計模式
- 設計模式-狀態模式設計模式
- flink 有狀態(stateful)的計算
- 系統狀態統計和檢視
- 統計TCP連線數和狀態TCP
- 行為型模式:狀態模式模式
- 程式的建立和程式的狀態
- 如何在SAP WebClient UI裡建立柱狀圖(bar chart)WebclientUI
- TCP為什麼是有狀態的?TCP
- 無狀態協議協議
- 扒一扒React計算狀態的原理React
- 設計模式(二十一)----行為型模式之狀態模式設計模式
- python設計模式狀態模式Python設計模式
- 設計模式(十五)狀態模式設計模式
- 設計模式之——狀態模式設計模式
- 談談RxSwift和狀態管理Swift