黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

Application Fundamentals--Remote procedure c

系統 1925 0
Remote procedure calls--遠程過程調用

Android has a lightweight mechanism for remote procedure calls (RPCs) — where a method is called locally, but executed remotely (in another process), with any result returned back to the caller. This entails decomposing the method call and all its attendant data to a level the operating system can understand, transmitting it from the local process and address space to the remote process and address space, and reassembling and reenacting the call there. Return values have to be transmitted in the opposite direction. Android provides all the code to do that work, so that you can concentrate on defining and implementing the RPC interface itself.

翻譯:Android提供了對遠程調用(RPC)的輕量級支持--RPC從表面上看是一個本地調用,但是實際是在另外一個進程中執行遠程方法,執行結果返回本地調用者。這個過程要求操作系統能夠對方法調用、方法參數及返回值具有解析能力;能夠把數據對象從本地進程、本地地址空間傳遞到遠程進程、遠程地址空間;而且返回值能夠逆向傳遞到本地進程中。所有這些,Android都提供了支持,作為開發者只需要關注遠程過程調用(RPC)接口的定義和實現。

An RPC interface can include only methods. By default, all methods are executed synchronously (the local method blocks until the remote method finishes), even if there is no return value.

翻譯:RPC接口可以只是包含方法定義,接口中的方法默認都是同步執行(也就是說本地方法的執行需要等待遠程方法執行完成方可繼續執行,即使遠程方法沒有返回值。)

In brief, the mechanism works as follows: You'd begin by declaring the RPC interface you want to implement using a simple IDL (interface definition language). From that declaration, the aidl tool generates a Java interface definition that must be made available to both the local and the remote process. It contains two inner class, as shown in the following diagram:

翻譯:簡單說,實際過程是:開發者先聲明RPC接口(使用IDL接口定義語言),然后用aidl 工具生成該接口的Java接口定義,該接口對于本地和遠程進程都必須是可見的,這個Java接口中包含兩個內部類,如下圖所示:
Application Fundamentals--Remote procedure calls(遠程過程調用)

The inner classes have all the code needed to administer remote procedure calls for the interface you declared with the IDL. Both inner classes implement the IBinder interface. One of them is used locally and internally by the system; the code you write can ignore it. The other, called Stub, extends the Binder class. In addition to internal code for effectuating the IPC calls, it contains declarations for the methods in the RPC interface you declared. You would subclass Stub to implement those methods, as indicated in the diagram.

翻譯:這兩個內部類中提供了所有必要的代碼,用于基于你所定義的接口的遠程過程調用管理,這兩個類都實現了IBinder接口,其中一個內部類用于本地,與操作系統交互。作為遠程方法的開發者可以不必考慮它,另外一個內部類也叫Stub(存根),是Binder的子類,該類除了負責RPC調用的相關代碼外,還包含RPC接口中所聲明的方法聲明,開發者應該把這個Stub(存根)類作為基類擴展出子類,在子類中實現接口定義的方法,請參考上圖。

Typically, the remote process would be managed by a service (because a service can inform the system about the process and its connections to other processes). It would have both the interface file generated by the aidl tool and the Stub subclass implementing the RPC methods. Clients of the service would have only the interface file generated by the aidl tool.

翻譯:通常,遠程進程是由一個服務來管理的(因為服務可以向系統通知進程以及和其他進程的連接),這樣的服務既包含了aidl工具生成的接口文件也包含遠程方法開發者由Stub類擴展出的子類實現的遠程方法,使用該服務的客戶端代碼只需要aidl工具生成的接口文件。

Here's how a connection between a service and its clients is set up:

下面是服務使用方和服務本身之間連接創建的過程:

??? * Clients of the service (on the local side) would implement onServiceConnected() and onServiceDisconnected() methods so they can be notified when a successful connection to the remote service is established, and when it goes away. They would then call bindService() to set up the connection.

????? 翻譯:服務客戶端 (運行在本地) 需要實現 onServiceConnected() 和 onServiceDisconnected() 方法,這兩個方法在與遠程服務連接建立完成后或是連接斷開時被系統調用。一旦連接建立,onServiceConnected()方法繼續調用 bindService() 方法。
???
?? * The service's onBind() method would be implemented to either accept or reject the connection, depending on the intent it receives (the intent passed to bindService()). If the connection is accepted, it returns an instance of the Stub subclass.

????? 翻譯:服務的bindService()的作用要么是接受要么是拒絕連接,具體取決于方法的參數intent,如果接受連接,那么該方法返回Stub類的子類實例對象(IBinder接口的實現類)。

??? * If the service accepts the connection, Android calls the client's onServiceConnected() method and passes it an IBinder object, a proxy for the Stub subclass managed by the service. Through the proxy, the client can make calls on the remote service.

????? 翻譯:如果服務接受了連接,Android將立刻調用客戶端的onServiceConnected()方法,同時為該方法傳遞一個IBinder對象,這個IBinder對象是一個Stub類的子類代理的概念,由服務負責管理它,借助這個代理實例,客戶端就可以對遠程服務做調用。

This brief description omits some details of the RPC mechanism. For more information, see Designing a Remote Interface Using AIDL and the IBinder class description.

翻譯:以上簡要描述的過程中忽視了RPC過程的一些細節,更多信息請查閱Designing a Remote Interface Using AIDL and the IBinder class description.

Application Fundamentals--Remote procedure calls(遠程過程調用)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論