注意
rpccontext是乙個threadlocal的臨時狀態記錄器,當接收到rpc請求或發起rpc請求時,rpccontext的狀態都會變化。
比如:a呼叫b,b再呼叫c。在b呼叫c之前,a呼叫了b,那麼rpccontext中記錄的是a呼叫b的資訊;在b呼叫c之後,rpccontext記錄的是b呼叫c的資訊。
舉個栗子
id="democservice"
class="com.c.democserviceimpl"/>
inte***ce="com.c.democservice"
ref="democservice" />
id="democservice"
inte***ce="com.c.democservice" />
id="bbean"
class="com.b.bserviceimpl">
id="democservice"
ref="democservice" />
bean>
id="demobservice"
class="com.b.demobserviceimpl" />
inte***ce="com.b.demobservice"
ref="demobservice" />
id="demobservice"
inte***ce="com.b.demobservice" />
id="abean"
class="com.a.aserviceimpl">
id="demobservice"
ref="demobservice"/>
配置好服務提供方和服務消費方的dubbo之後,來看服務提供方和服務消費方如何獲取dubbo上下文資訊:
class a
//服務消費方
demobservice demobservice = (demobservice)context.getbean("demobservice");
//遠端呼叫
demobservice.***();
//本端是否為消費端
boolean isconsumerside = rpccontext.getcontext().isconsumerside();
//獲取最後一次呼叫的提供方ip位址
string serverip = rpccontext.getcontext().getremotehost();
//獲取當前服務配置資訊,所有配置資訊都將轉換為url引數
//...
//注意,每次發起新的rpc呼叫,上下文資訊都會變化
demobservice.yyy();
//...
class b
//服務提供方
public
class
demobserviceimpl
implements
demobservice
}
class c
public class c
}
上下文 上下文棧
全域性 函式 區域性 在執行全域性 前將window確定為全域性執行上下文 對全域性資料進行預處理 var定義的全域性變數 undefined,新增為window的屬性 function宣告的全域性函式 賦值 fun 新增為window的方法 this 賦值 window 開始執行全域性 在呼叫函式...
中斷上下文 程序上下文
在學習與作業系統相關的知識時候,我們經常遇到程序上下文 中斷上下文,看似熟悉又感覺不是特別清晰。這裡我們從如下幾個方面進行描述。上下文是從英文中context翻譯過來的,指的是一種環境。上下文我們看起來不怎麼熟悉,但是我們可以看context的中文翻譯,或者我們能更加的情形些。context n 語...
全域性上下文與上下文
全域性上下文由main函式載入系統的主架構和主事件迴圈和全域性資料構成。是上帝創造世界時,建立的基礎事物。萬物之始,大道至簡,衍化至繁。全域性上下文代表著程式執行所需要的基礎資源。是程式執行的基礎。全域性上下文的特徵是在程式執行期間常駐記憶體。全域性上下文的生命週期和應用程式的生命週期相同。與應用程...