Please enable JavaScript.
Coggle requires JavaScript to display documents.
CORBA (Define the Interface (idlj compiler, which is used to map IDL…
CORBA
Define the Interface
-
-
-
-
-
-
IDL defines three parameter-passing modes: in (for input from client to server), out (for output from server to client), and inout (used for both input and output).
FileInterface.idl
interface FileInterface {
typedef sequence<octet> Data;
Data downloadFile(in string fileName);
};
idlj compiler, which is used to map IDL definitions into Java declarations and statements.
generate client stubs, server skeletons, or both
-
Develop a client
When the FileTransfer service is found, the downloadFile method is invoked.
// create and initialize the ORB
ORB orb = ORB.init(argv, null);
Once a reference to the naming service has been obtained, it can be used to access the naming service and find other services (for example the FileTransfer service)
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
NameComponent nc = new NameComponent("FileTransfer", " ");
// Resolve the object reference in naming
NameComponent path[] = {nc};
FileInterfaceOperations fileRef =
FileInterfaceHelper.narrow(ncRef.resolve(path));
Develop the server
//Initializes the ORB
ORB orb = ORB.init(args, null);
// create the servant and register it with the ORB
FileServant fileRef = new FileServant();
orb.connect(fileRef);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// Wait for invocations from clients
java.lang.Object sync = new java.lang.Object();
synchronized(sync){
sync.wait();
}
Running the application
Run the client. Now you can run the client using the following command, assuming that the naming service is running on port 2500.
prompt> java FileClient hello.txt -ORBInitialPort 2500
Generate Stubs for the client. Before we can run the client, we need to generate stubs for the client. To do that, get a copy of the FileInterface.idl file and compile it using the idlj compiler specifying that you wish to generate client-side stubs, as follows:
prompt> idlj -fclient FileInterface.idl
-
Running the the CORBA naming service. This can be done using the command tnameserv. By default, it runs on port 900.
tnameserv -ORBinitialPort 2500
Implement the interface
-
This implementation is known as a servant,
FileServant extends the _FileInterfaceImplBase class to specify that this servant is a CORBA object. #
-
-
-
-
Define an interface in IDL
Map the IDL interface to Java (done automatically)
Implement the interface
Develop the server
Develop a client
Run the naming service, the server, and the client.
-