【转载】ICE介绍(3)

Direct Versus Indirect Binding

The process of resolving the information in a proxy to protocol–address pair isknown as binding. Not surprisingly, direct binding is used for direct proxies, and indirect binding is used for indirect proxies.

The main advantage of indirect binding is that it allows us to move servers around (that is, change their address) without invalidating existing proxies that are held by clients. In other words, direct proxies avoid the extra lookup to locate the server but no 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 a conceptual entity that has a type, identity, and addressing information. However, client requests ultimately must end up with a concrete server-side processing entity that can provide the behavior for an operation invocation. To put this differently, a client request must ultimately end up executing code inside the server, with that code written in a specific programming language and executing on a specific processor.

The server-side artifact that provides behavior for operation invocations is known as a servant. A servant 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 the server developer and that is registered with the server-side run time as the servant for one or more Ice objects. Methods on the class correspond to the operations on the Ice object’s interface and provide the behavior for the operations.

A single servant can incarnate a single 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 the servant. If the latter, the servant is provided the identity of the Ice object with each request, so it can decide which object to incarnate for the duration of the request.

Conversely, a single Ice object can have multiple servants. For example, we might choose to create a proxy for an Ice object with two different addresses for different machines. In that case, we will have two servers, with each server containing a servant for the same Ice object. When a client invokes an operation on such an Ice object, the client-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, if that attempt fails, sends the request to the second server. Only if the second attempt 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-once semantics: the Ice run time does its best to deliver a request to the correct destination and, depending on the exact circumstances, may retry a failed request. Ice guarantees that it will either deliver the request, or, if it cannot deliver the request, inform the client with an appropriate exception; under no circumstances is a request delivered twice, that is, retries are attempted only if it is known that a previous attempt definitely failed.2

At-most-once semantics are important because they guarantee that operations that are not idempotent can be used safely. An idempotent operation is an operation that, if executed twice, has the same effect as if executed once. For example, x = 1; is an idempotent operation: if we execute the operation twice, the end result is the same as if we had executed it once. On the other hand, x++; is not idempotent: if we execute the operation twice, the end result is not the same as if we had executed it once.

Without at-most-once semantics, we can build distributed systems that are more robust in the presence of network failures. However, realistic systems require non-idempotent operations, so at-most-once semantics are a necessity, even though they make the system less robust in the presence of network failures. Ice permits you to mark individual operations as idempotent. For such operations, the Ice run time uses a more aggressive error recovery mechanism than for non idempotent operations.

  •   最多一次语义

ICE的请求有最多一次的语义:ICE运行时会尽力将请求传递到正确的目的地,根据实际情况的需要,也可以重复发送一个失败了的请求。ICE会确保:要么传递这个请求,要么,在不能传递这个请求时给客户端通知一个适当的异常;在任何情况下,一个请求都不会被传递二次,亦即,只有在明确的知道了先前一个次请求已经失败的情况下,才能再尝试发送第二次请求。

最多一次语义是非常重要的,因为它们确保非幂等(not idempotent)操作能够被安全的运用。所谓的幂等操作是这样的操作,如果执行两次,与它执行一次有相同的结果。例如,x=1; 是一个幂等操作:如果我们执行了两次这个操作,最后的结果与我们执行一次的结果是一样的。但是, x++;是一个非幂等操作:如果我们执行这个操作两次的话,结果与我们执行一次是不一样的。

如果没有最多一次的语义,我们能够在网络失败的情况下构建一个更加健壮的的分布式系统。但是,真实的系统需要一个非幂等操作,所以最多一次语义是个必要的,即使它们会使系统在网络失败的情况下缺乏健壮性。ICE允许你将单个的的操作标记为幂等操作(idempotent)。对这样的操作,ICE运行时会用一种比非幂等操作更积极的错误恢复机制。


原文地址:http://blog.csdn.net/abetman/article/details/337682

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值