General ILU Info
The Inter-Language Unification system (ILU) is a multi-language object interface
system. The object interfaces provided by ILU hide implementation distinctions
between different languages, between different address spaces, and between
operating system types.
A D V E R T I S E M E N T
ILU can be used to build multi-lingual object-oriented
libraries ("class libraries") with well-specified language-independent
interfaces. It can also be used to implement distributed systems. It can also be
used to define and document interfaces between the modules of non-distributed
programs.
The 2.0 release of ILU contains support for the programming languages ANSI C,
C++, Modula-3, Java, and Common Lisp. It has been installed on many flavors of
UNIX, including SPARC machines running SunOS 4.1.3 and Solaris 2, SGI MIPS
machines running IRIX 5.2, Intel 486 machines running Linux 1.1.78, DEC Alpha
machines with OSF/1, IBM RS/6000 machines running AIX, and HP machines running
HP/UX. It runs on Microsoft Windows 3.1, Windows 95, and Windows NT
environments. It supports both threaded and non-threaded operation. Since one of
the implementation goals of ILU is to maximize compatibility with existing open
standards, ILU provides support for use of the OMG CORBA IDL interface
description language, and can be thought of as a CORBA ORB system (though with
omissions from and extensions to the CORBA spec). As another result, ILU
includes a self-contained implementation of ONC RPC.
ILU is available free from ftp://ftp.parc.xerox.com/pub/ilu/ilu.html.
Commandline mumbojumbo
Before running any java stuff, a few environment variables need to be set up.
Make sure the "java" interpreter is on your PATH, and that "$(ILUHOME)/bin"
is on your path. If you use the literal expression "$(ILUHOME)/bin", make sure
that the environment variable ILUHOME is properly defined.
2. Make sure "./classes" and "$(ILUHOME)/lib/ilu.jar" are on your CLASSPATH.
3. Make sure your LD_LIBRARY_PATH has "$(ILUHOME)/lib" on it.
Tutorial.isl
INTERFACE Tutorial;
EXCEPTION DivideByZero
"this error is signalled if the client of the Calculator calls
the Divide method with a value of 0";
TYPE Calculator = OBJECT COLLECTIBLE
DOCUMENTATION "4-function calculator"
METHODS
SetValue (v : REAL) "Set the value of the calculator to `v'",
GetValue () : REAL "Return the value of the calculator",
Add (v : REAL) "Adds `v' to the calculator's value",
Subtract (v : REAL) "Subtracts `v' from the calculator's value",
Multiply (v : REAL) "Multiplies the calculator's value by `v'",
Divide (v : REAL) RAISES DivideByZero END
"Divides the calculator's value by `v'"
END;
TYPE Factory = OBJECT
METHODS
CreateCalculator () : Calculator
END;
CalculatorImpl.java
package Tutorial;
/*
* While this class matches the Tutorial.isl specification
* it is a local implementation. Its instances need to be
* registered explicitely or implicitely with Ilu before they
* are publicly accessible.
*/
public class CalculatorImpl implements
Tutorial.Calculator {
double theValue = 0.0;
public CalculatorImpl(){
theValue = 0.0;
}
public void SetValue(double v) {
theValue = v;
}
public double GetValue() {
return theValue;
}
public void Add(double v) {
theValue = theValue + v;
}
public void Subtract(double v) {
theValue = theValue - v;
}
public void Multiply(double v) {
theValue = theValue * v;
}
public void Divide(double v) throws Tutorial.DivideByZero {
if (v==0.0) throw new Tutorial.DivideByZero();
theValue = theValue / v;
}
} //CalculatorImpl
simple1.java
/*
* A simple client program that demonstrates the use of the
* Calculator module as a library.
*/
/*
* Run this like
* java Tutorial.simple1 number [number...]
*/
package Tutorial;
public class simple1 {
public static void main(String argv[]) {
CalculatorImpl calc;
//create the calculator
calc = new CalculatorImpl();
if (calc==null) {
System.err.println("Got null TapeCalculator");
System.exit(1);
}
//clear the calculator before using it
calc.SetValue(0.0);
//now loop over the arguments, adding each in turn
int i = 0;
while (i<argv.length) {
Double v = Double.valueOf(argv[i]); //don't bother about exceptions
calc.Add(v.doubleValue());
i = i+1;
}
//and print the result
System.out.println("The sum is " + calc.GetValue());
} //main
} //simple1
simple2.java
/*
* A simple client program that demonstrates the use of the
* Calculator stub module with a local implementation.
*/
/*
* Run this like
* java Tutorial.simple2 number [number...]
*/
package Tutorial;
public class simple2 {
public static void main(String argv[]) {
Tutorial.Calculator calc; //Interface from stubbing...
try {
//create the calculator
calc = new Tutorial.CalculatorImpl();
if (calc==null) {
System.err.println("Couldn't create calculator");
System.exit(1);
}
//clear the calculator before using it
if (argv.length<1) {
calc.SetValue(0.0);
} else {
Double v = Double.valueOf(argv[0]);
calc.SetValue(v.doubleValue());
}
//now loop over the arguments, adding each in turn
int i = 1;
while (i<argv.length) {
Double v = Double.valueOf(argv[i]); //don't bother...
calc.Divide(v.doubleValue());
i = i+1;
}
//and print the result
System.out.println("the 'sum' is " + calc.GetValue());
} catch (Tutorial.DivideByZero e) {
System.err.println("raised DivideByZero exception: " + e);
} catch (xerox.ilu.IluSystemException e) {
System.err.println("raised IluSystemException exception: " + e);
}
} //main
} //simple2
TutorialServer.java
/*
* Run this like
* java Tutorial.TutorialServer servername
*/
package Tutorial;
import Tutorial.Calculator;
import Tutorial.Factory;
import Tutorial.DivideByZero;
import Tutorial.CalculatorStub;
import Tutorial.FactoryStub;
import Tutorial.CalculatorImpl;
import xerox.ilu.Ilu;
import xerox.ilu.IluSimpleBinding;
import xerox.ilu.IluSystemException;
import xerox.ilu.IluServer;
class FactoryImpl implements Tutorial.Factory {
xerox.ilu.IluServer server;
public FactoryImpl(xerox.ilu.IluServer server) {
this.server = server;
}
public Tutorial.Calculator CreateCalculator()
throws xerox.ilu.IluSystemException
{
Tutorial.Calculator calc = new Tutorial.CalculatorImpl();
Ilu.registerTrueObject(
Ilu.inventID(),
calc,
this.server,
Tutorial.CalculatorStub.iluClass(),
Ilu.unspec
);
return calc;
}
} //FactoryImpl
public class TutorialServer {
static FactoryImpl factory;
static xerox.ilu.IluServer trueServer;
public static void main(String argv[]) {
try {
String serverId;
if (argv.length < 1) {
System.out.println("Must specify a server id");
return;
}
//Create a server with appropriate server id (which is
//taken from the first argument)
serverId = argv[0];
trueServer = xerox.ilu.IluServer.createServer(serverId);
//Now create an instance of a Factory object on the server
//with an instance handle "theFactory"
factory = new FactoryImpl(trueServer);
xerox.ilu.Ilu.registerTrueObject(
"theFactory",
factory,
trueServer,
Tutorial.FactoryStub.iluClass(),
xerox.ilu.IluLifetimeArgs.iluLifetimeRemember
);
//Make the factory well known by publishing it
xerox.ilu.IluSimpleBinding.publish(factory);
//Now we print the string binding handle (the object's name
//plus its location) of the new Factory instance
System.out.println("Factory instance published");
System.out.println("Its SBH is '" + Ilu.sbhOfObject(factory) + "'");
//the program doesn't terminate because the server is still alive...
} catch (xerox.ilu.IluSystemException e) {
System.out.println("raised IluSystemException: " + e);
}
}
} //TutorialServer
simple3.java
/*
* A simple client program that finds the Calculator-Factory,
* creates a calculator, and adds up its arguments.
*/
/*
* Run this like
* java Tutorial.simple3 servername number [number...]
* after making sure a server is running.
*/
package Tutorial;
public class simple3 {
/* We define a new routine, "Get_Tutorial_Calculator", which
* finds the tutorial factory, then creates a new Calculator
* object for us.
*/
public static Tutorial.Calculator
GetTutorialCalculator(String serverId, String factoryId) {
Tutorial.Factory factory = null;
Tutorial.Calculator calc = null;
System.out.println("Looking up factory");
try {
/* We have to call lookup with the object ID of
* the factory object, and the "type" of the object
* we're looking for.
*/
factory = (Tutorial.Factory)
xerox.ilu.IluSimpleBinding.lookup(
serverId,
factoryId,
Tutorial.FactoryStub.iluClass()
);
} catch (xerox.ilu.IluSystemException e) {
System.err.println("Failed to get factory: " + e);
System.exit(1);
}
if (factory==null) {
System.err.println("Got null factory");
System.exit(1);
}
System.out.println("Got factory " + factory);
System.out.println("Looking up Calculator");
try {
calc = factory.CreateCalculator();
} catch (xerox.ilu.IluSystemException e) {
System.err.println("Failed to get Calculator: " + e);
System.exit(1);
}
if (calc==null) {
System.err.println("Got null Calculator");
System.exit(1);
}
System.out.println("Got Calculator " + calc);
return calc;
} //GetTutorialCalculator
public static void main(String argv[]) {
Tutorial.Calculator calc;
if (argv.length < 2) {
System.err.println("usage: java Tutorial.simple3 number*");
System.exit(1);
}
//Find a calculator
String serverId = argv[0];
calc = GetTutorialCalculator(serverId, "theFactory");
if (calc==null) {
System.out.println("Null calculator");
System.exit(1);
}
try {
//clear the calculator before using it
calc.SetValue(0.0);
//now loop over the arguments, adding each in turn
int i = 1;
while (i<argv.length) {
Double v = Double.valueOf(argv[i]);//exceptions possible
calc.Add(v.doubleValue());
i = i+1;
}
//and print the result
System.out.println("The sum is " + calc.GetValue());
/* This is awfull but Java does not let you catch exceptions which
* are not raised. What an idiotic feature!
* } catch (Tutorial.DivideByZero e) {
* System.err.println("Division by zero: " + e);
*/
} catch (xerox.ilu.IluSystemException e) {
System.err.println("Some IluSystemException: " + e);
}
} //main
} //simple3/*
* A simple client program that finds the Calculator-Factory,
* creates a calculator, and adds up its arguments.
*/
/*
* Run this like
* java Tutorial.simple3 servername number [number...]
* after making sure a server is running.
*/
package Tutorial;
import xerox.ilu.Ilu;
import xerox.ilu.IluException;
import xerox.ilu.IluServer;
import Tutorial.DivideByZero;
public class simple3 {
/* We define a new routine, "Get_Tutorial_Calculator", which
* finds the tutorial factory, then creates a new Calculator
* object for us.
*/
public static Tutorial.Calculator
GetTutorialCalculator(String serverId, String factoryId) {
Tutorial.Factory factory = null;
Tutorial.Calculator calc = null;
System.out.println("Looking up factory");
try {
/* We have to call lookupObject with the object ID of
* the factory object, and the "type" of the object we're looking
* for.
*/
factory = (Tutorial.Factory)
xerox.ilu.Ilu.lookupObject(
serverId,
factoryId,
Tutorial.FactoryStub.iluClass()
);
} catch (xerox.ilu.IluException e) {
System.err.println("Failed to get factory: " + e);
System.exit(1);
}
if (factory==null) {
System.err.println("Got null factory");
System.exit(1);
}
System.out.println("Got factory " + factory);
System.out.println("Looking up Calculator");
try {
calc = factory.CreateCalculator();
} catch (xerox.ilu.IluException e) {
System.err.println("Failed to get Calculator: " + e);
System.exit(1);
}
if (calc==null) {
System.err.println("Got null Calculator");
System.exit(1);
}
System.out.println("Got Calculator " + calc);
return calc;
} //GetTutorialCalculator
public static void main(String argv[]) {
Tutorial.Calculator calc;
if (argv.length < 2) {
System.err.println("usage: java Tutorial.simple3 number*");
System.exit(1);
}
//Find a calculator
String serverId = argv[0];
calc = GetTutorialCalculator(serverId, "theFactory");
if (calc==null) {
System.out.println("Null calculator");
System.exit(1);
}
try {
//clear the calculator before using it
calc.SetValue(0.0);
//now loop over the arguments, adding each in turn
int i = 1;
while (i<argv.length) {
Double v = Double.valueOf(argv[i]);//exceptions possible
calc.Add(v.doubleValue());
i = i+1;
}
//and print the result
System.out.println("The sum is " + calc.GetValue());
} catch (xerox.ilu.IluException e) {
System.err.println("Some IluException: " + e);
}
} //main
} //simple3
Tutorial2.isl
INTERFACE Tutorial2 IMPORTS Tutorial END;
TYPE OpType = ENUMERATION
SetValue, Add, Subtract, Multiply, Divide END;
TYPE Operation = RECORD
op : OpType,
value : REAL,
accumulator : REAL
END;
TYPE RegisterTape = SEQUENCE OF Operation;
TYPE TapeCalculator = OBJECT COLLECTIBLE
SUPERTYPES Tutorial.Calculator END
DOCUMENTATION "4 function calculator with register tape"
METHODS
GetTape () : RegisterTape
END;
TYPE Factory = OBJECT SUPERTYPES Tutorial.Factory END
METHODS
CreateTapeCalculator () : TapeCalculator
END;
TapeCalculatorImpl.java
package Tutorial2;
import java.util.Vector;
import Tutorial2.OpType;
import Tutorial2.Operation;
/*
* While this class complies to the Tutorial2.isl specification
* it is a local implementation. Its instances need to be
* registered with Ilu before they are publicly accessible.
*/
public class TapeCalculatorImpl implements
Tutorial2.TapeCalculator {
double value;
java.util.Vector tape;
public TapeCalculatorImpl() {
value = 0.0;
tape = new java.util.Vector();
}
public void SetValue(double v) {
value = v;
Operation op = new Operation(OpType.SetValue, v, value);
tape.addElement(op);
}
public double GetValue() {
return value;
}
public void Add(double v) {
value = value + v;
Operation op = new Operation(OpType.Add, v, value);
tape.addElement(op);
}
public void Subtract(double v) {
value = value - v;
Operation op = new Operation(OpType.Subtract, v, value);
tape.addElement(op);
}
public void Multiply(double v) {
value = value * v;
Operation op = new Operation(OpType.Multiply, v, value);
tape.addElement(op);
}
public void Divide(double v) throws Tutorial.DivideByZero {
if (v==0.0) throw new Tutorial.DivideByZero();
if (v==1.0) tape = null; //raise an unexpected exception for debugging
value = value / v;
Operation op = new Operation(OpType.Divide, v, value);
tape.addElement(op);
}
public Operation[] GetTape() {
Operation retVal[];
//We protect structural integrity even if we don't care
//about the value in case of a conflict.
synchronized (tape) {
retVal = new Operation[tape.size()];
tape.copyInto(retVal);
}
return retVal;
}
} //TapeCalculatorImpl
|