ICE介绍(3)

来源:百度文库 编辑:神马文学网 时间:2024/04/19 15:39:25
DirectVersus Indirect Binding
The process ofresolving the information in a proxy to protocol–address pair isknown asbinding. Not surprisingly, direct binding is used for direct proxies, and indirectbinding is used for indirect proxies.
The main advantage ofindirect binding is that it allows us to move servers around (that is, changetheir address) without invalidating existing proxies that are held by clients.In other words, direct proxies avoid the extra lookup to locate the server butno longer work if a server is moved to different machine. On the other hand,indirect proxies continue to work even if we move (or migrate) a server.
  直接绑定 vs 间接绑定
绑定就是将代理中的信息解析为协议-地址对的过程。无疑,直接绑定用于直接代理,间接绑定就用于间接代理。
间接绑定的优点是在服务器移动时(也就是说,改变它们的地址)不会使已经存在的代理失效,这些代理已经被客户端所持有。那么,直接代理能避免额外的查找和定位服务器的工作,但是在服务器移到不同的机器上时,它就不能工作了。另一方面,即使我们移动(或迁移)一个服务器时,间接代理仍然能够工作。
Servants
As we mentioned on page 10, an Ice object is aconceptual entity that has a type, identity, and addressing information.However, client requests ultimately must end up with a concrete server-sideprocessing entity that can provide the behavior for anoperation invocation. To put this differently, a client request must ultimatelyend up executing code inside the server, with that code written in a specificprogramming language and executing on a specific processor.
The server-side artifact thatprovides behavior for operation invocations is known as a servant. Aservant provides substance for (or incarnates) one or more Ice objects.In practice, a servant is simply an instance of a class that is written by theserver developer and that is registered with the server-side run time as the servantfor one or more Ice objects. Methods on the class correspond to the operations onthe Ice object’s interface and provide the behavior for the operations.
A single servant can incarnate asingle Ice object at a time or several Ice objects simultaneously. If the former,the identity of the Ice object incarnated by the servant is implicit in theservant. If the latter, the servant is provided the identity of the Ice objectwith each request, so it can decide which object to incarnate for the durationof the request.
Conversely, a single Ice objectcan have multiple servants. For example, we might choose to create a proxy foran Ice object with two different addresses for different machines. In thatcase, we will have two servers, with each server containing a servant for thesame Ice object. When a client invokes an operation on such an Ice object, theclient-side run time sends the request to exactly one server. In other words,multiple servants for a single Ice object allow you to build redundant systems:the client-side run time attempts to send the request to one server and, ifthat attempt fails, sends the request to the second server. Only if the secondattempt fails is an error reported back to the client-side application code.
   服务者
就象我们在第10页提到的,ICE对象是一个概念上的实体,它有类型、标识和地址信息。但是,客户端的请求最终一定要落到在服务器端的具体的处理实体上,由这个处理实体来完成操作调用的行为。换句话说,客户端的请求最终必需要由服务器的一段代码来执行,这段代码是用一种特定的程序语言来编写的,并在一个特定的处理器中执行的。
这个位于服务器端的提供操作调用的行为的东西就是服务者(Servant)。一个服务者为一个或多个ICE对象提供了实现(或者说是具体化了)。实际上,服务者就是服务器开发人员写的类的一个实例。做为一个或多个ICE对象的服务者,它们会注册到服务器运行时中。类中的方法与在ICE对象接口上的操作相对应,并提供这个操作的具体的行为。
一个单个的服务者能每次实现一个ICE对象,也可以同时实现几个ICE对象。如果是前一种情况,被服务者实现的ICE对象的标识是隐含在服务者中的。如果是后一种情况,每一次请求都要给孝服务者提供一个ICE对象的标识,这样它才能确定请求时应该实现哪一个对象。
反过来说,一个ICE对象可以拥有多个服务者。例如,我们可以选择为在不同的机器上的两个地址上的一个ICE对象创建一个代理。这种情况下,我们将有两个服务器,每一个服务器都这个相同的对象包含一个服务者。当客户端在这样的ICE对象上调用操作时,客户端要在运行时发送请求到一个确定的服务器上。换句话说,一个ICE对象的多个服务者允许你构建一个冗余的系统:客户端在运行时试图发送请求到一个服务器,如果这个请求失败,发送这个请求到第二个服务器。只有第二个请求也失败了,都会向客户端的应用程序的代码返回错误。
At-Most-Once Semantics
Ice requests have at-most-oncesemantics: the Ice run time does its best to deliver a request to thecorrect destination and, depending on the exact circumstances, may retry afailed request. Ice guarantees that it will either deliver the request, or, ifit cannot deliver the request, inform the client with an appropriate exception;under no circumstances is a request delivered twice, that is, retries areattempted only if it is known that a previous attempt definitely failed.2
At-most-oncesemantics are important because they guarantee that operations that are not idempotentcan be used safely. An idempotent operation is an operation that, ifexecuted twice, has the same effect as if executed once. For example, x = 1; is anidempotent operation: if we execute the operation twice, the end result is thesame as if we had executed it once. On the other hand, x++; is notidempotent: if we execute the operation twice, the end result is not the sameas if we had executed it once.
Without at-most-once semantics,we can build distributed systems that are more robust in the presence ofnetwork failures. However, realistic systems require non-idempotent operations,so at-most-once semantics are a necessity, even though they make the systemless robust in the presence of network failures. Ice permits you to mark individualoperations as idempotent. For such operations, the Ice run time uses a moreaggressive error recovery mechanism than for non idempotent operations.
  最多一次语义
ICE的请求有最多一次的语义:ICE运行时会尽力将请求传递到正确的目的地,根据实际情况的需要,也可以重复发送一个失败了的请求。ICE会确保:要么传递这个请求,要么,在不能传递这个请求时给客户端通知一个适当的异常;在任何情况下,一个请求都不会被传递二次,亦即,只有在明确的知道了先前一个次请求已经失败的情况下,才能再尝试发送第二次请求。
最多一次语义是非常重要的,因为它们确保非幂等(not idempotent)操作能够被安全的运用。所谓的幂等操作是这样的操作,如果执行两次,与它执行一次有相同的结果。例如,x=1; 是一个幂等操作:如果我们执行了两次这个操作,最后的结果与我们执行一次的结果是一样的。但是, x++;是一个非幂等操作:如果我们执行这个操作两次的话,结果与我们执行一次是不一样的。
如果没有最多一次的语义,我们能够在网络失败的情况下构建一个更加健壮的的分布式系统。但是,真实的系统需要一个非幂等操作,所以最多一次语义是个必要的,即使它们会使系统在网络失败的情况下缺乏健壮性。ICE允许你将单个的的操作标记为幂等操作(idempotent)。对这样的操作,ICE运行时会用一种比非幂等操作更积极的错误恢复机制。