COM IDL与UUID简介

IDL(Interface Definition Language)即接口定义语言,是CORBA规范的一部分,是跨平台开发的基础。IDL提供一套通用的数据类型,并以这些数据类型来定义更为复杂的数据类型。可变化 IDL 基本类型 整数类型 OMG IDL 摒弃int 类型在不同平台上取值范围不同带来的多义性的问题。常数定义常数可以是整数、字符、浮点数、字符串、Boolean、octet 或枚举型,不能是 any 类型或用户定义的类型。OMG IDL数组类型IDL array 和 sequence,可以轻易地被映射到实现语言中。序列可以包含所有类型的元素,不管是基本类型还是用户定义的类型。

IDL(Interface Definition Language)即接口定义语言,是CORBA规范的一部分,是跨平台开发的基础。IDL提供一套通用的数据类型,并以这些数据类型来定义更为复杂的数据类型。可变化 IDL 基本类型 整数类型 OMG IDL 摒弃int 类型在不同平台上取值范围不同带来的多义性的问题。常数定义常数可以是整数、字符、浮点数、字符串、Boolean、octet 或枚举型,不能是 any 类型或用户定义的类型。OMG IDL数组类型IDL array 和 sequence,可以轻易地被映射到实现语言中。序列可以包含所有类型的元素,不管是基本类型还是用户定义的类型。


OMG IDL文件概述
  从本质上讲,OMG IDL接口定义语言不是作为程序设计语言体现在CORBA体系结构中的,而是用来描述产生对象调用请求的客户对象和服务对象之间的接口的语言。OMG IDL文件描述数据类型和方法框架,而服务对象则为一个指定的对象实现提供上述数据和方法。
  OMG IDL文件描述了服务器提供的服务功能,客户机可以根据该接口文件描述的方法向服务器提出业务请求。在大多数CORBA产品中都提供IDL到相关编程语言的编译器。程序设计人员只需将定义的接口文件输入编译器,设定编译选项后,就可以得到与程序设计语言相关的接口框架文件和辅助文件。

IDL文件应用过程如图1所示。

图1 OMG IDL文件编译过程


  在语法规则方面,类似于C++或Java中关于接口或对象的定义,OMG IDL增加了一些构造方法支持IDL特有的方法调用机制。OMG IDL只是一种说明性的语言,支持C++语法中的常量、类型和方法的声明。采用OMG IDL这样的说明性语言,其目的在于克服特定编程语言在软件系统集成及互操作方面的限制,这正是CORBA的诱人之处,同样也体现出采用CORBA构造分布式应用程序在网络时代的强大生命力。OMG IDL已经为C、C++、Java等主要高级程序设计语言制定了IDL到高级编程语言的映射标准。项目开发人员可以根据需要选择自己最熟悉的编程语言来独立开发基于CORBA的应用,而对软件系统的互操作能力不产生影响。
OMG IDL的语法规则
1. OMG IDL文件举例
  module Compute
  { typedef double radius;
  typedef long times;
  interface PI
  { double getResult( in radius aRadius, in times time); }
  }
  上述接口定义文件主要用于客户端向服务对象提出请求:计算π值。因此,模块中定义了一个方法getResult(),以圆的直径(aRadius)和迭代次数(times)作为该方法的输入参数。
2. OMG IDL词法规则
  OMG IDL采用ASCII字符集构成接口定义的所有标识符。标识符由字母、数字和下划线的任意组合构成,但第一个字符必须是ASCII字母。IDL认为大写字母和小写字母具有相同的含义,例如anExample和AnExample是相同的。
  与C++和Java类似,采用以“/*”开始,以“*/”结束来注释一段代码,以“//”开始注释从“//”开始直至行尾的所有内容。
  另外,IDL保留了47个关键字,程序设计人员不能将关键字用作变量或方法名。需要注意的是关键字的大小写,例如:
  typedef double context;
  //错误:定义的变量context是关键字
  typedef double CONTEXT;
  //错误:CONTEXT与关键字context冲突
3. 数据类型
  (1)基本数据类型:OMG IDL基本数据类型包括short、long和相应的无符号(unsigned)类型,表示的字长分别为16、32位。
  (2)浮点数类型:OMG IDL浮点数类型包括float、double和long double类型。其中float表示单精度浮点数,double表示双精度浮点数,long double表示扩展的双精度浮点数。
  (3)字符和超大字符类型:OMG IDL定义字符类型char为面向字节的码集中编码的单字节字符; 定义类型wchar为从任意字符集中编码的超大字符。
  (4)逻辑类型:用boolean关键字定义的一个变量,取值只有true和false。
  (5)八进制类型:用octet关键字定义,在网络传输过程中不进行高低位转换的位元序列。
  (6)any数据类型:引入该类型用于表示OMG IDL中任意数据类型。
4. 常量
  OMG IDL用const关键字声明一个常量,用于模块(module)或接口(interface)中定义保持不变的量,如:
  const double PI = 3.1415926;
  在IDL中,可以定义long、unsigned long、unsigned short、char、boolean、float、double、string类型的常量。
5. 构造数据类型
  类似于C和C++的语法规则,OMG IDL中构造数据类型包括结构、联合、枚举等形式。如下例:
(1)结构类型:
  typedef long GoodsNumber;
  struct
  { GoodsNumber number;
  string name;
  float price; }
(2)联合类型:
  union stockIn switch( short )
  { case 1: stocker : long;
  case 2: goodsName1 : string;
  case 3: goodsName2 : string; }
(3)枚举类型:
  enum GoodsStatus { GOODS_SALED, GOODS_INSTOCK};
6. 数组类型
  OMG IDL的数组类型提供了多维定长、统一数据格式的数据存储方式——数组。每一维的长度必须在定义时给定,所有数据单元必须存储相同类型的元素。如下例定义一个长度为20×100的整数数组:
  typedef long aDimension[20][100];
7.模板(template)类型
  OMG IDL提供两种类型的模板:
(1) 序列(sequence)类型:
  用该方法定义长度可变的任意数值类型的存储序列,通常在定义时可以指定长度,也可以不指定,如:
  typedef sequence <long,80> aSequence;
  //长度定义为80
  typedef sequence <long> anotherSequence;
  //长度不定
(2) 字符串(string)序列:
  同样对于字符串序列类型,也有两种定义方式:
  typedef string <80> aName; //长度定义为80
  typedef string anotherName; //长度不定
8.接口(interface)
  在前几讲中,均提到了CORBA接口,接口作为服务对象功能的详细描述,封装了服务对象提供服务方法的全部信息,客户对象利用该接口获取服务对象的属性、访问服务对象中的方法。
  接口用关键字interface声明,其中包含的属性和方法对所有提出服务请求的客户对象是公开的,如下例:
  interface JobManager
  { readonly attribute string FirstName;
  attribute string status;
  string QueryJobStatus( in long Number, out string property); }

UUID

UUID就是Universal Unique IDentifier的缩写,它是一个128位,16字节的值,并确保在时间和空间上唯一。
它是把硬件地址、时间以及随机数结合在一起,来确保其唯一性的。
一般情况下,生成算法用计算机网卡的地址和一个60位的timestamp生成,时间是以100ns为时间间隔。

例如,一台300PL 6862的计算机,主板集成的网卡的MAC地址为00-04-AC-2E-B7-DC,而UUID的最后六个字节也会是0004AC2EB7DC

 

### Spring Framework ApplicationEventPublisher Example and Usage In the context of the Spring framework, `ApplicationEventPublisher` is an interface that allows beans to publish events to the application context. This mechanism facilitates a loosely coupled architecture where components can notify each other about significant occurrences without being directly dependent on one another. The core classes involved in this event-driven model include: - **ApplicationEvent**: A class extending from which all custom events should derive. - **ApplicationListener<E extends ApplicationEvent>**: An interface implemented by any bean wishing to listen for specific types of events. - **ApplicationEventMulticaster**: The component responsible for broadcasting events to registered listeners within the ApplicationContext[^1]. To demonstrate how these pieces work together using `ApplicationEventPublisher`, consider the following code snippets illustrating both publishing and listening capabilities. #### Publishing Events with ApplicationEventPublisher A service or repository layer might want to inform others when certain actions occur. For instance, after saving data into storage, it could broadcast such activity as shown below: ```java @Service public class MyService { private final ApplicationEventPublisher publisher; @Autowired public MyService(ApplicationEventPublisher publisher) { this.publisher = publisher; } void performAction() { // Action logic here... CustomEvent event = new CustomEvent(this); publisher.publishEvent(event); // Publishes the event through the context } } ``` Here, upon executing some action inside `performAction()`, a new `CustomEvent` gets created and published via injection of `ApplicationEventPublisher`. #### Listening for Specific Events Using ApplicationListener On the receiving end, interested parties implement `ApplicationListener<SpecificEventType>` to react accordingly whenever their targeted type occurs: ```java @Component public class EventConsumer implements ApplicationListener<MyCustomEvent> { @Override public void onApplicationEvent(MyCustomEvent event) { System.out.println("Received my custom event : " + event.getMessage()); } } ``` This listener will automatically receive notifications every time a matching event (`MyCustomEvent`) happens anywhere across different parts of your application[^2]. Additionally, annotations like `@EventListener` provide even more concise syntax while offering flexibility regarding method signatures and parameters used during handling processes. By leveraging these constructs effectively, developers gain powerful tools enabling robust communication patterns throughout complex systems built atop Spring's foundation.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值