将 CORBA 服务器上的整个对象传输到客户端
我正在使用JDK中默认提供的Java IDL在CORBA中开发分布式应用程序,当然,客户端和服务器都是用Java开发的。
我正在服务器上维护某些对象状态。
现在,在客户端,我想从服务器端获取该对象的整个状态(快照)。 这是某种 Java 类型的对象。 由于 IDL 定义以及 CORBA 功能(因为它是语言中立的),我无法将任何 Java 类型的整个对象从服务器传递到客户端。
我发现的一种方法是使用 JSON,
我会将任何类型的整个 Java 对象展平为字符串,并使用字符串数据类型将其传递给客户端,稍后在客户端上我可以将字符串展平对象。 我还可以在 idl.h 中定义字符串类型。
但这增加了双方展平/展平的一些处理
还有其他方法可以从客户端传递对象吗?或者我可能错过了什么?
更新:
以下类型的对象被传输
class MyObject{ Map
I am developing the distributed application in CORBA Using the Java IDL provided by default in JDK , and of course , both client and server developed in Java.
I am maintaining the some object state on server.
Now, on client side I want to bring whole state (snapshot) of that object from server side.
and this is object is of some Java type .
As I cannot pass the whole object of any Java type from server to client, because of IDL definition and of course CORBA feature as it is language neutral.
One way I found, is using JSON
I will flatten the whole Java Object of any type into string and pass same to client using string data type, later on client I can deflatten the object from string.
also I can define the string type in idl.
but this adds the some processing for flattening/ deflattening on both sides
is there any other way to pass object from client? or may be I missed something?
Update:
Objects of Following types are transferred
class MyObject{ Map<String,String> object; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CORBA 已经有了 按值对象的概念,因此如果您的 ORB 支持,您就可以使用它。将状态变量放入
valuetype
中,然后从那里开始。请记住,CORBA 不是 Java。 CORBA 可以与多种语言一起使用,因此如果您发现自己试图弄清楚如何通过 CORBA 系统发送仅 Java 的内容,您会发现这非常困难。要在 CORBA 中传输任何内容,它首先必须能够在 IDL 中表示。如果
valuetype
不能满足您的需求,则使用其他答案建议的结构方法。CORBA already has the concept of Objects-By-Value, so you could use that if your ORB supports it. Put your state variables in a
valuetype
and go from there.Keep in mind that CORBA is not Java. CORBA can be used with many languages so if you find yourself trying to figure out how to send Java-only things across a CORBA system, you're going to find that very difficult. To transmit anything in CORBA it's got to be representable in IDL first and foremost. If
valuetype
doesn't meet your needs then use the struct approach that the other answer suggested.您只需将 MyObjects 定义为 CORBA 对象即可。为此,您将使用 IDL。您的地图是一个简单的名称、值列表。
这将在 Java 中创建一个 MapEntry 对象数组。如果您想将它们重新映射到 Java 映射中,请随意。这是传输某事物的映射的 CORBA 方式。创建一个结构体,将其放入序列中,完成。
这也适用于 CORBA 支持的其他语言(例如 C++)
You just have to define your MyObjects as CORBA objects. For that you'll use the IDL. Your Map is a simple name,value list.
This will create an Array of MapEntry Objects in Java. If you want to remap them into a Java Map, feel free. This is the CORBA way of transferring a map of something. Create a struct, put it into a sequence, done.
This also works properly for other languages supported by CORBA (e.g., C++)
这听起来好像您想让对象状态成为接口的一部分(因为如果您实际传输状态,能否重新创建对象取决于接收者理解传输的状态,因此它成为一个接口)。
因此,定义一个包含IDL中的数据字段的
struct
,并向对象接口添加一个方法以返回此形式的状态。然后,传输由常规 CORBA 编组器处理。That sounds as if you want to have the object state become part of the interface (because if you actually transfer the state, being able to recreate the object depends on the receiver to understand the transmitted state, hence it becomes an interface).
Thus, define a
struct
containing the data fields in the IDL, and add a method to the object interface to return the state in this form. The transfer is then handled by the regular CORBA marshaller.