远程和动态代理

发布于 2024-08-14 01:37:53 字数 337 浏览 7 评论 0原文

  1. 我知道,曾经,开发远程代理包括生成存根/骨架,尽管今天由于反射而不再需要它。 (动态代理)

我想得到一个关于反射为什么以及如何取代这种需求的清晰解释。 例如,我知道存根应该处理网络上的通信(如果远程对象位于不同的计算机上),再加上负责序列化/反序列化等......现在谁负责?

也许我对动态代理的概念完全错误。

  1. 另外,我读到了有关 Java 和 Rmi 的主题,我将如何在 C++ 中实现远程代理, 我可能可以使用 DCOM,还有其他更简单的方法吗? (我是否需要 DCom 中的存根/骨架或不再像 java 那样?)

谢谢

  1. i understand that ,once, developing remote proxy included generating stub/skeleton , though today this is no longer needed thanks to reflection. (dynamic proxy)

i want to get a clear explanation as to why and how reflection replaces this need.
for example i understood the stub was suppose to handle the communication over the network (in case the the remote object is on a different computer) , plus in charge of serialization/deserialization , etc... who's in charge of that now ?

maybe i got the concept of dynamic proxy all wrong.

  1. in addition i read about that subject regarding Java and Rmi, how would i implement remote proxy in C++,
    i probably can use DCOM, is there another, maybe easier, way ? (and do i need stub/skeleton in DCom or like java no more ? )

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

放肆 2024-08-21 01:37:53

假设您有一个接口 A,并且类 B 实现了 A

服务器VM有一个B实例;它与一个名字相关联;服务器监听 TCP 端口以进行客户端通信。像这样:

Server server = new Server(localhost, port);
server.bind("bbbb", new B() );

在客户端 VM 上,您想要访问驻留在服务器 VM 上的 B 对象。您需要获取对它的引用(类型 A)

A bb = lookup(serverIp, port, "bbbb");

bbA 的子类,使用 java.lang.reflect.Proxy 创建。 bb 上的任何方法调用都由 InitationHandler 处理,它以任何方式对调用进行编码,并通过线路将其发送到服务器。服务器收到“在名为 bbbb 的对象上调用此名称的方法[使用这些参数]”的请求,并且服务器通过反射执行该任务没有问题。然后以类似的方式将返回值发送回客户端。

所以自己做这件事其实并不难。 Sun 的 RMI 可能正在做同样的事情(RMI 还有一些其他功能,例如远程垃圾收集)。请参阅 http://java.sun.com/j2se /1.5.0/docs/guide/rmi/relnotes.html

say you have an interface A, and class B implements A.

the server VM has one instance of B; it's associated with a name; the server listens on a TCP port for client communication. something like this:

Server server = new Server(localhost, port);
server.bind("bbbb", new B() );

on the client VM, you want to access that B object residing on the server VM. You need to obtain a reference (of type A) to it

A bb = lookup(serverIp, port, "bbbb");

bb is a subclass of A, created with java.lang.reflect.Proxy. any method call on bb is handled by an InvocationHandler, which encodes the invocation in whichever way, and send it to ther server over the wire. the server receives a request of "calling this method of this name [with these arguments] on the objected named bbbb", and the server has no problem performing that task with reflection. then the return value is sent back to client in the similar way.

So it is really not hard to do this by yourself. Sun's RMI is probably doing the same thing (RMI has some other features, like remote garbage collection). see http://java.sun.com/j2se/1.5.0/docs/guide/rmi/relnotes.html

涙—继续流 2024-08-21 01:37:53

如果我没记错的话,存根/骨架是由 rmic 工具静态创建的,而现在整个过程是动态的。

这并不是说它一定“更好”,而只是消除了编译存根和框架的麻烦。在这两种情况下,请求参数和响应几乎在同一级别以相同的方式序列化。

至于问题#1:RMI 的某些实现使用 Corba,因此如果代码可用,您可能需要查看一下。

您所需要的只是将 C++ 代码与 Corba 层连接起来,就像存根/骨架一样。

If I'm not mistaking, the stub/skeleton was statically created by the rmic tool while now the whole process is dynamic.

Its not that its necessarily 'better', but just removes the hassle of compiling a stub and skeleton. In both cases, the request parameters and response is serialized in the same way pretty much at the same level.

As for question #1: Some implementation of RMI uses Corba, so if the code is available, you may want to look at that.

All you would need is to interface your C++ code with the Corba layer as the stub/skeleton did.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文