Android API中IBinder接口的谷歌翻译

API文档原文:

public interface IBinderBase interface for a remotable object, the core part of a lightweight remote procedure call mechanism designed for high performance when performing in-process and cross-process calls. This interface describes the abstract protocol for interacting with a remotable object. Do not implement this interface directly, instead extend from Binder. 


The key IBinder API is transact() matched by Binder.onTransact(). These methods allow you to send a call to an IBinder object and receive a call coming in to a Binder object, respectively. This transaction API is synchronous, such that a call to transact() does not return until the target has returned from Binder.onTransact(); this is the expected behavior when calling an object that exists in the local process, and the underlying inter-process communication (IPC) mechanism ensures that these same semantics apply when going across processes. 


The data sent through transact() is a Parcel, a generic buffer of data that also maintains some meta-data about its contents. The meta data is used to manage IBinder object references in the buffer, so that those references can be maintained as the buffer moves across processes. This mechanism ensures that when an IBinder is written into a Parcel and sent to another process, if that other process sends a reference to that same IBinder back to the original process, then the original process will receive the same IBinder object back. These semantics allow IBinder/Binder objects to be used as a unique identity (to serve as a token or for other purposes) that can be managed across processes. 


The system maintains a pool of transaction threads in each process that it runs in. These threads are used to dispatch all IPCs coming in from other processes. For example, when an IPC is made from process A to process B, the calling thread in A blocks in transact() as it sends the transaction to process B. The next available pool thread in B receives the incoming transaction, calls Binder.onTransact() on the target object, and replies with the result Parcel. Upon receiving its result, the thread in process A returns to allow its execution to continue. In effect, other processes appear to use as additional threads that you did not create executing in your own process. 


The Binder system also supports recursion across processes. For example if process A performs a transaction to process B, and process B while handling that transaction calls transact() on an IBinder that is implemented in A, then the thread in A that is currently waiting for the original transaction to finish will take care of calling Binder.onTransact() on the object being called by B. This ensures that the recursion semantics when calling remote binder object are the same as when calling local objects. 


When working with remote objects, you often want to find out when they are no longer valid. There are three ways this can be determined: 


The transact() method will throw a RemoteException exception if you try to call it on an IBinder whose process no longer exists. 
The pingBinder() method can be called, and will return false if the remote process no longer exists. 
The linkToDeath() method can be used to register a IBinder.DeathRecipient with the IBinder, which will be called when its containing process goes away. 


谷歌翻译结果:

公共接口IBinderBase接口在一个远程目标,进程和跨进程调用表演时设计的高性能轻量的远程过程调用机制的核心组成部分。该接口描述了一个远程访问的对象交互的抽象协议。不要直接实现这个接口,而不是从活页夹延伸。


关键的IBinder API是办理()由Binder.onTransact匹配()。这些方法允许你把呼叫发送到一个IBinder对象,并接到一个电话进来一个Binder对象,分别。本次交易API是同步的,使得调用交易()之前,不会返回从Binder.onTransact返回的目标();这是预期的行为调用一个存在于本地进程对象时,和底层的进程间通信(IPC)机制,确保这些相同的语义跨进程会时适用。


()通过办理发送的数据是一个包,数据的一个通用的缓冲也保持一定的元数据有关的内容。元数据是用来在缓冲区管理的IBinder对象引用,让那些引用可以保持为跨进程缓冲动作。这个机制可以确保当一个IBinder被写入一个包裹和发送到另一个过程中,如果该其他过程中发送到相同的IBinder回原始处理的基准,则原工艺将接收相同的IBinder对象后面。这些语义允许的IBinder /捆扎机对象被用作唯一的标识(以用作令牌或用于其他目的),可以在整个过程进行管理。


系统维护事务的线程,它运行在每个进程池。这些线程用于调度其他进程的未来在所有的公益机构。例如,当一个IPC从处理A作出处理B,在办理()A嵌段调用线程作为其发送到处理B.在B中的下一个可用的池线程接收进入交易的交易,来电Binder.onTransact ()中的目标对象,并且其结果包裹答复上。收到它的结果,过程中的返回线程允许其继续执行。实际上,其他进程似乎使用你没有创建自己的过程执行额外的线程。


活页夹系统还支持跨进程递归。例如,如果在处理该事务上正处于执行,那么线程在一个一个IBinder当前等待原始交易完成将负责办理()调用过程A执行事务处理B,而进程B的调用对象上Binder.onTransact()被称为B.这确保了调用远程对象的粘合剂时,递归语义是相同的调用本地对象时。


当远程对象,你通常会想搞清楚的时候都不再有效。有三种方式这可以被确定:


如果你尝试调用它一个IBinder的进程不再存在办理()方法将抛出RemoteException异常。
该pingBinder()方法可以被调用,并且将返回false如果远程进程不再存在。
该linkToDeath()方法可以用来注册到的IBinder,当其含有进程消失,将被称为IBinder.DeathRecipient。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值