|
Downloads: You will need JavaIDL to test the client Getting Started: Win95 system environment settings for JavaIDL:
|
REM SET PATH=C:\jdk1.2beta4\bin;%path% REM |
Introduction: This example extends the IDL from the previous pages, and also demonstrates Threading. Ship.idl
|
// Ship.idl #pragma prefix "Waveman"
interface Aircraft {
interface AircraftCarrier {
};
|
Server.java |
// Building Distributed Object Applications with CORBA // Infowave (Thailand) Co., Ltd. // http://www.waveman.com // Jan 1998 import java.io.*;
public class Server
org.omg.CORBA.BOA boa = null;
// TIE uses these two new lines AircraftCarrierImpl new_carrier = new
AircraftCarrierImpl(boa);
try {
org.omg.CORBA.Object initRef = null;
NamingContext initContext = null;
// Write object reference to an IOR file so Orbix Client can access try
NameComponent[] name = new NameComponent[1];
NamingContext milContext = null;
try {
System.out.println(carrier + " ready for launch !!!"); try {
|
Client.java |
// Building Distributed Object Applications with CORBA // Infowave (Thailand) Co., Ltd. // http://www.waveman.com // Aug 1998 import java.io.*;
public class Client
org.omg.CORBA.Object initRef = null;
// Read IOR from file try
// End IOR NamingContext initContext = null;
NameComponent[] name = new NameComponent[3];
org.omg.CORBA.Object objRef = null;
Ship.AircraftCarrier carrier = null;
// Standard program continues String flight = args.length > 0 ? args[0]: "Ghost Rider 101"; Ship.Aircraft aircraft = null;
String designation = null;
try {
|
AircraftCarrierImpl.java |
// Building Distributed Object Applications with CORBA // Infowave (Thailand) Co., Ltd. // http://www.waveman.com // Jan 1998 import java.util.*; public class AircraftCarrierImpl implements Ship.AircraftCarrierOperations
// data member and constructor for TIE private org.omg.CORBA.BOA _boa;
public AircraftCarrierImpl(org.omg.CORBA.BOA boa)
public synchronized Ship.Aircraft launch(String name)
if (aircraft == null)
// TIE uses _boa. instead of _boa(). _boa.obj_is_ready(aircraft); System.out.println(aircraft
+ " on Catapult 2");
|
AircraftImpl.java |
// Building Distributed Object Applications with CORBA // Infowave (Thailand) Co., Ltd. // http://www.waveman.com // Jan 1998 public class AircraftImpl implements Ship.AircraftOperations, Runnable
public void run()
this.engineThread = new Thread(this);
public String codeNumber()
public int fuelCapacity()
|
Building the server with VisiBroker: Create a directory and place Ship.idl, Server.java, AircraftCarrierImpl.java,
and AircraftImpl.java into it.
|
prompt> idl2java Ship.idl prompt> vbjc Server.java |
Building the client with OrbixWeb: Place Client.java into the same directory as above
|
prompt> idl Ship.idl prompt> owjavac Client.java java_output\Ship\*.java |
Building the client with JavaIDL: Place Client.java into the same directory as above
|
prompt> idltojava Ship.idl prompt> javac Client.java |
Running the program: Three windows will be required Smart Agent and NameService in one window, server in one window, client
in another
|
prompt> osagent prompt> vbj -DJDKrenameBug -DORBservices=CosNaming com.visigenic.vbroker.services.CosNaming.ExtFactory objects navy.log prompt> vbj -DORBservices=CosNaming -DSVCnameroot=objects Server prompt> owjava Client or prompt> java Client
|
Note: It is usually easier to create two BAT files to contain the commands above.
|