设计问题:如何透明地访问IPC机制?

发布于 2024-07-07 22:09:44 字数 558 浏览 7 评论 0原文

我想这样做(没有特定的语言):

print(foo.objects.bookdb.books[12].title);

或者这样:

book = foo.objects.bookdb.book.new();
book.title = 'RPC for Dummies';
book.save();

foo 实际上是一个通过某些 IPC 连接到我的程序的服务,并且为了访问它的方法和对象,某些层实际上通过网络发送和接收消息。

现在,我并不是真的在寻找 IPC 机制,因为有很多可供选择。 它可能不是基于 XML,而是基于 s。 th。 例如 Google 的协议缓冲区、dbus 或 CORBA。 我不确定的是如何构建应用程序,以便我可以像访问任何对象一样访问 IPC。

换句话说,我怎样才能拥有在进程边界上透明映射的 OOP?

这并不是一个设计问题,而且我仍然在整体架构的相当高的水平上工作。 因此,我对将使用哪种语言还很不可知。不过,C#、Java 和 Python 都可能会被使用。

I want to do this (no particular language):

print(foo.objects.bookdb.books[12].title);

or this:

book = foo.objects.bookdb.book.new();
book.title = 'RPC for Dummies';
book.save();

Where foo actually is a service connected to my program via some IPC, and to access its methods and objects, some layer actually sends and receives messages over the network.

Now, I'm not really looking for an IPC mechanism, as there are plenty to choose from. It's likely not to be XML based, but rather s. th. like Google's protocol buffers, dbus or CORBA. What I'm unsure about is how to structure the application so I can access the IPC just like I would any object.

In other words, how can I have OOP that maps transparently over process boundaries?

Not that this is a design question and I'm still working at a pretty high level of the overall architecture. So I'm pretty agnostic yet about which language this is going to be in. C#, Java and Python are all likely to get used, though.

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

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

发布评论

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

评论(3

深白境迁sunset 2024-07-14 22:09:44

我认为完成您所要求的操作的方法是将所有对象通信视为消息传递。 这就是 Ruby 和 Smalltalk 等中处理对象方法的方式。

使用消息传递(而不是方法调用)作为对象通信机制,然后诸如调用编写代码时不存在的方法之类的操作变得明智,因为对象无论如何都可以对消息执行一些明智的操作(检查远程对象)过程,从数据库等中返回同名字段的值,或者抛出“找不到方法”异常,或者您能想到的任何其他内容)。

需要注意的是,对于不使用此作为默认机制的语言,您无论如何都可以进行消息传递(每个对象都有一个“handleMessage”方法),但您不会获得语法细节,也不会能够获得 IDE 帮助,而无需您付出额外的努力来让 IDE 解析您的 handleMessage 方法以检查有效输入。

I think the way to do what you are requesting is to have all object communication regarded as message passing. This is how object methods are handled in ruby and smalltalk, among others.

With message passing (rather than method calling) as your object communication mechanism, then operations such as calling a method that didn't exist when you wrote the code becomes sensible as the object can do something sensible with the message anyway (check for a remote procedure, return a value for a field with the same name from a database, etc, or throw a 'method not found' exception, or anything else you could think of).

It's important to note that for languages that don't use this as a default mechanism, you can do message passing anyway (every object has a 'handleMessage' method) but you won't get the syntax niceties, and you won't be able to get IDE help without some extra effort on your part to get the IDE to parse your handleMessage method to check for valid inputs.

流年已逝 2024-07-14 22:09:44

阅读 Java 的 RMI —— 介绍性材料展示了如何您可以拥有远程对象的本地定义。

诀窍是让两个类具有相同的方法签名。 该类的本地版本是某种网络协议的外观。 远程版本通过网络接收请求并执行对象的实际工作。

您可以定义一对类,以便客户端可以拥有

foo= NonLocalFoo( "http://host:port" )
foo.this= "that"
foo.save()

服务器从客户端连接接收 set_this() 和 save() 方法请求。 服务器端(通常)并不简单,因为您有很多发现和实例管理问题。

Read up on Java's RMI -- the introductory material shows how you can have a local definition of a remote object.

The trick is to have two classes with identical method signatures. The local version of the class is a facade over some network protocol. The remote version receives requests over the network and does the actual work of the object.

You can define a pair of classes so a client can have

foo= NonLocalFoo( "http://host:port" )
foo.this= "that"
foo.save()

And the server receives set_this() and save() method requests from a client connection. The server side is (generally) non-trivial because you have a bunch of discovery and instance management issues.

豆芽 2024-07-14 22:09:44

你不应该这样做! 对于程序员来说,在代码中看到并感受到 IPC/RPC 和本地方法调用之间的区别非常重要。 如果你这样做,他们就不必考虑它,他们就不会考虑它,这将导致代码性能非常差。

想一想:

foreach o, o.isGreen in someList { 
   o.makeBlue; 
}

程序员假设循环需要几纳秒才能完成,但如果 someList 恰好是远程的,则需要接近一秒的时间。

You shouldn't do it! It is very important for programmers to see and feel the difference between an IPC/RPC and a local method call in the code. If you make it so, that they don't have to think about it, they won't think about it, and that will lead to very poorly performing code.

Think of:

foreach o, o.isGreen in someList { 
   o.makeBlue; 
}

The programmer assumes that the loops takes a few nanoseconds to complete, instead it takes close to a second if someList happens to be remote.

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