Using OMG IDL with ILU
ILU also supports the use of the interface definition language OMG IDL, defined
by the Object Management Group (OMG) for their Common Object Request Broker
Architecture (CORBA).
A D V E R T I S E M E N T
OMG IDL uses a C++-like syntax, so it may be easier for
Java and C++ programmers to use than ILU ISL. Unfortunately, CORBA doesn't
include some of the concepts in ILU, such as garbage collection for transient
objects, or OPTIONAL types, so not every ILU interface can be
expressed in OMG IDL, but many of them can. For example, here is the OMG IDL
version of the Tutorial interface:
module Tutorial {
exception DivideByZero {};
interface Calculator {
// Set the value of the calculator to `v'
void SetValue (in double v);
// Return the value of the calculator
double GetValue ();
// Adds `v' to the calculator's value
void Add (in double v);
// Subtracts `v' from the calculator's value
void Subtract (in double v);
// Multiplies the calculator's value by `v'
void Multiply (in double v);
// Divides the calculator's value by `v'
void Divide (in double v) raises (DivideByZero);
};
interface Factory {
// Create and return an instance of a Calculator object
Calculator CreateCalculator();
};
};
This can be used with the java-stubber:
% java-stubber Tutorial.idl
writing file javastubs/Tutorial/DivideByZero.java
writing file javastubs/Tutorial/Factory.java
writing file javastubs/Tutorial/FactoryStub.java
writing file javastubs/Tutorial/Calculator.java
writing file javastubs/Tutorial/CalculatorStub.java
%
This will be a bit slower than running the java-stubber on the
equivalent ISL file, as the program works by converting the OMG IDL into ISL,
then compiling from the ISL description. OMG IDL interfaces can be checked by
running the OMG IDL-to-ILU ISL converter, idl2isl, directly:
% idl2isl Tutorial.idl
INTERFACE Tutorial;
EXCEPTION DivideByZero;
TYPE Calculator = OBJECT OPTIONAL
METHODS
SetValue (v : REAL),
GetValue () : REAL,
Add (v : REAL),
Subtract (v : REAL),
Multiply (v : REAL),
Divide (v : REAL)
RAISES DivideByZero END
END;
TYPE Factory = OBJECT OPTIONAL
METHODS
CreateCalculator () : Calculator
END;
%
You will notice that the ISL interface generated by idl2isl is a
bit different, in that the object type modifier OPTIONAL is used in
the description of the Calculator and Factory types.
This is because CORBA has the notion that any object type instance passed as a
parameter or return value (or field in an array, or element of a sequence, etc.)
may be null, instead of being a valid instance pointer. Thus, when
working with OMG IDL descriptions of your interfaces, it is necessary to check
the return type of methods like Tutorial.Factory.CreateCalculator
to see that a valid object reference has been returned, before using the object.
ISL allows you to have these CORBA-style objects, by using the OPTIONAL
modifier in the declaration of an object type, but it also allows object
pointers which can't be null. By default ILU object instances may
not be null.
Transient and Permanent Objects
Keen-eyed readers will have seen that the Calculator type in `Tutorial.isl'
is marked with the modifier COLLECTIBLE, while the Factory
type is not. ILU differentiates between two kinds of objects, which we call
transient and permanent.
Transient objects are typically created for a specific use, and typically
have a fixed lifetime. They often have state associated with them. They are
frequently used to represent some ongoing computation or operation.
Permanent objects are usually expected to be around forever (or until some
activity not captured by a programming concept terminates). Permanent objects
are often gateways to some sort of service, or represent some external piece of
data, such as a cell in a spreadsheet, or a file on a disk somewhere. They are
often stateless; when they do have state, it is typically backed by some form of
stable storage, as they have to be available across crashes of their server
program.
ILU provides an automatic system for distributed garbage collection of
transient objects; that is, of removing them from everyone's address space when
everyone is done with them. This uses the underlying garbage collection
techniques of the particular programming language being used. With Java, the ILU
garbage collector works in conjunction with the Java collector; with ANSI C, we
use the extremely primitive collector provided for C; that is, when the process
terminates, the objects are collected. To indicate to ILU that a particular
object type is to be treated as transient, you mark the object type
specification, in the ISL, with the keyword COLLECTIBLE.
For permanent objects, like the Tutorial.Factory object type,
the ILU Java support will maintain a reference to the instance, preventing the
Java collector from collecting it.
|