org.omg.CORBA
是 OMG(Object Management Group) 定义的 CORBA(Common Object Request Broker Architecture) 标准的 Java 实现的一部分。CORBA 是一种分布式对象计算的标准,允许不同平台和编程语言之间的对象进行通信。以下是关于 org.omg.CORBA
的详细说明:
1. CORBA 的概述
CORBA 是一种 分布式对象计算 的标准,由 OMG 制定。它的核心目标是通过 对象请求代理(ORB,Object Request Broker) 实现跨平台、跨语言的分布式对象通信。CORBA 的主要特点包括:
- 语言无关性:支持多种编程语言(如 Java、C++、Python)。
- 平台无关性:可以在不同的操作系统和硬件平台上运行。
- 分布式通信:支持远程对象调用(RMI,Remote Method Invocation)。
- 接口定义语言(IDL):通过 IDL 定义对象接口,生成不同语言的实现代码。
2. org.omg.CORBA
的作用
org.omg.CORBA
是 Java 中实现 CORBA 标准的 API 包。它提供了以下功能:
- ORB 核心:支持对象请求代理的初始化和配置。
- 对象引用:表示远程对象的引用(如
org.omg.CORBA.Object
)。 - 异常处理:定义了 CORBA 标准的异常(如
org.omg.CORBA.SystemException
)。 - 类型映射:支持 IDL 类型到 Java 类型的映射。
- 服务上下文:支持在远程调用中传递上下文信息。
3. org.omg.CORBA
的核心类与接口
org.omg.CORBA
包中包含了许多核心类和接口,以下是一些重要的组件:
ORB
:
对象请求代理的核心类,用于初始化和配置 ORB。ORB orb = ORB.init(args, null);
Object
:
表示远程对象的引用,是 CORBA 对象的基类。SystemException
:
CORBA 标准异常的基类,表示系统级别的错误。Any
:
用于表示动态类型的值,支持 IDL 中的any
类型。NamedValue
:
用于表示命名值,通常用于传递参数或返回值。Context
:
用于传递调用上下文信息。
4. CORBA 的工作流程
使用 org.omg.CORBA
实现 CORBA 通信的典型工作流程如下:
- 定义 IDL 接口:
使用 IDL 定义远程对象的接口。interface Hello { string sayHello(); };
- 生成 Java 代码:
使用 IDL 编译器(如idlj
)生成 Java 代码。idlj -fall Hello.idl
- 实现服务端:
实现生成的接口,并将对象绑定到 ORB。HelloImpl helloImpl = new HelloImpl(); orb.connect(helloImpl);
- 实现客户端:
通过 ORB 获取远程对象的引用,并调用方法。org.omg.CORBA.Object obj = orb.string_to_object("IOR:..."); Hello hello = HelloHelper.narrow(obj); String message = hello.sayHello();
5. org.omg.CORBA
的应用场景
org.omg.CORBA
适用于以下场景:
- 跨语言通信:
需要 Java 与其他语言(如 C++、Python)进行通信的场景。 - 分布式系统:
需要在多个节点之间进行远程对象调用的场景。 - 遗留系统集成:
需要与使用 CORBA 的遗留系统进行集成的场景。
6. CORBA 的替代技术
尽管 CORBA 是一种强大的分布式通信技术,但现代开发中更常用以下替代技术:
- Web 服务(SOAP/REST):
基于 HTTP 的标准化通信协议,更适合 Web 应用。 - RMI(Remote Method Invocation):
Java 原生的远程调用技术,更适合纯 Java 应用。 - gRPC:
基于 HTTP/2 的高性能 RPC 框架,支持多种语言。 - 消息队列(如 Kafka、RabbitMQ):
适用于异步通信和事件驱动的场景。
7. 总结
org.omg.CORBA
是 OMG 定义的 CORBA 标准的 Java 实现,提供了分布式对象通信的核心功能。它通过 ORB 实现跨平台、跨语言的远程调用,适用于分布式系统和遗留系统集成。然而,随着现代技术的发展,CORBA 逐渐被 Web 服务、RMI、gRPC 等替代技术取代。对于需要与 CORBA 系统集成的场景,org.omg.CORBA
仍然是一个重要的工具。
org.omg.CORBA
是OMG (Object Management Group) 对象请求 brokers (ORBs) 的公共API标准的一部分。它定义了一系列接口和服务,用于实现分布式计算中的远程过程调用(RPC)。这个包本身不直接包含很多功能,而是作为其他一些子包(如org.omg.CORBA.ORBPackage
)的基础,这些子包提供了特定的功能,如异常处理。
具体来说,org.omg.CORBA
包内有若干子包,它们主要作用是提供异常类和用于支持接口和类的辅助类。例如,org.omg.CORBA.ORBPackage
提供了两个异常类型 InvalidName
和 InconsistentTypeCode
,这两个异常在处理命名错误和类型码一致性时可能会抛出。
要了解更详细的用法,通常会查看官方文档或者查阅具体的编程教程,因为这些异常的具体使用场景涉及到客户端和服务器之间的交互。
ORB (Object Request Broker) 是一种在分布式计算环境中常见的组件,它扮演着中间件的角色。ORB 主要负责在客户端和服务器之间透明地传递对象请求和服务,使得分布式系统的不同部分能够相互通信并协作。它通过定义标准接口来实现跨平台的对象互操作性,支持远程过程调用(RPC)。
在分布式计算中,ORB 的作用包括:
- 连接管理:ORB 负责建立和维护客户端与服务器之间的连接,允许它们跨越网络通信。
- 对象定位:当客户端需要访问远端的服务时,ORB 根据服务的名字空间找到相应的对象实例。
- 事务管理:保证在分布式环境下的事务一致性,如ACID属性。
- 安全性:提供加密和认证机制,保护通信过程中的数据安全。
一个典型的ORB 如CORBA(Common Object Request Broker Architecture)就是基于这些功能设计的,它促进了异构系统间的集成和通信。在对等计算模型中,虽然参与者地位平等,但ORB 的存在仍然有助于协调和管理这些平等节点间的交互。
Provides the mapping of the OMG CORBA APIs to the JavaTM programming language, including the class ORB, which is implemented so that a programmer can use it as a fully-functional Object Request Broker (ORB).
See: Description
Interface Summary Interface Description
ARG_IN
Signifies an "input" argument to an invocation, meaning that the argument is being passed from the client to the server.
ARG_INOUT
Signifies an argument used for both input and output in an invocation, meaning that the argument is being passed from the client to the server and then back from the server to the client.
ARG_OUT
A constant that signifies an "output" argument to an invocation, meaning that the argument is being passed from the server to the client.
BAD_POLICY
A PolicyErrorCode which would be filled in the PolicyError exception.
BAD_POLICY_TYPE
A PolicyErrorCode which would be filled in the PolicyError exception.
BAD_POLICY_VALUE
Contains the value used to indicate a policy value that is incorrect for a valid policy type in a call to the create_policy method defined in the ORB class.
CTX_RESTRICT_SCOPE
A flag that can be used as the second parameter to the method Context.get_values to restrict the search scope.
Current
Interfaces derived from the Current interface enable ORB and CORBA services to provide access to information (context) associated with the thread of execution in which they are running.
CurrentOperations
The interface for Current.
CustomMarshal
An abstract value type that is meant to be used by the ORB, not the user.
DataInputStream
Defines the methods used to read primitive data types from input streams for unmarshaling custom value types.
DataOutputStream
Defines the methods used to write primitive data types to output streams for marshalling custom value types.
DomainManager
Provides mechanisms for establishing and navigating relationships to superior and subordinate domains, as well as for creating and accessing policies.
DomainManagerOperations
Provides the DomainManager with the means to access policies.
DynAny Deprecated
Use the new DynAny instead
DynArray Deprecated
Use the new DynArray instead
DynEnum Deprecated
Use the new DynEnum instead
DynFixed Deprecated
Use the new DynFixed instead
DynSequence Deprecated
Use the new DynSequence instead
DynStruct Deprecated
Use the new DynStruct instead
DynUnion Deprecated
Use the new DynUnion instead
DynValue Deprecated
Use the new DynValue instead
IDLType
An abstract interface inherited by all Interface Repository (IR) objects that represent OMG IDL types.
IDLTypeOperations
This interface must be implemented by all IDLType objects.
IRObject
An IRObject IDL interface represents the most generic interface from which all other Interface Repository interfaces are derived, even the Repository itself.
IRObjectOperations
This is the Operations interface for the mapping from IRObject.
Object
The definition for a CORBA object reference.
OMGVMCID
The vendor minor code ID reserved for OMG.
Policy
Interfaces derived from the Policy interface allow an ORB or CORBA service access to certain choices that affect its operation.
PolicyOperations
Provides the operations for a Policy object.
PRIVATE_MEMBER
Constant to define a private member in the ValueMember class.
PUBLIC_MEMBER
Constant to define a public member in the ValueMember class.
UNSUPPORTED_POLICY
One of the PolicyErrorCodes which would be