Account Example–
Application Level Request Primitives
In this lab session you are required to
produce a client and sever programs based on the CORBA static invocation
mechanism. CORBA static invocations are synchronous by default, that is to say
the client application blocks until the request is received,
processed and a result is sent back by a server application. In this lab
session you are asked to implement 3 other types of requests by using Java
threads, and substituting your implementations in the place of default
synchronous call. The request primitives considered for this exercise are
one-way, deferred synchronous and asynchronous. The server program should
support a sound generation service that can deposit a cheque in a bank account
and output the balance of the account upon the requests from a client
application. Different versions of the client application must make use of each
implementation of the three mentioned request primitives for invoking method
calls on the server application. The client should be implemented in Java and
the server in C++. You will use the CORBA library from the Java Development Kit
for the Java version of CORBA and MICO for the C++ version of CORBA. They are
both pre-configured on your machines. (HINT: Use the server file in C++ and the
client in Java from previous classes to help you to accomplish this exercise).
Application Development
For the development of above described
system follow the below instructions and repeat for each different variation of
the client application:
- Interface Definition – Define the Account interface using CORBA IDL. This
interface must declare the deposit and balance methods and their
parameters, so that they can be made accessible to remote clients.
- Stub/Skeleton Generation – Use the IDL compiler to generate client stub code and server
skeleton code with a Java mapping from account.idl.
Use the idlj command to generate the
stubs and skeletons in Java. Do the same compilation to generate the stub
and skeleton in C++ using idl command.
The commands are therefore: idlj account.idl idl - -boa -
-no-poa account.idl
- Servant Implementation – Implement the servant class AccountImpl
in C++ that inherits from the automatically generated Account_skel
skeleton class file. The servant must provide implementation for the deposit
and balance methods so that the cheque deposit is made upon
request as well as the display of the balance.
- Server Implementation – Implement the server class Server in C++ that is
responsible for creating an instance of AccountImpl,
registering and activating it with Basic Object Adapter (BOA) and
obtaining a reference to it (1). Create an instance of Account_impl(2). Use the CORBA::ORB_var.object_to_string()
method to get a textual representation of an object reference for
writing to a file (3). This reference must be exported into an external file(4), made accessible to the client application so
that it can make invocations on the object reference. Note that this
approach allows your client to connect to different Account server
objects by configuring the client to read from different reference files.
Finally, tell the adapter the implementation is ready and then run the orb(5).
- Client Implementation – Implement the client application Client in Java that first
obtains a reference to the Account object by reading in a reference
from the text file described in the above step. In order to this you will
need to use the org.omg.CORBA.ORB.string_to_object() method.
Note that this means that the client application will need to know about
the exact location of the server object. Using this reference the client
should invoke the balance method supplying it with an int type parameter. Define a second
class that invokes the deposit method from the server on the reference
obtained from the client, whilst using Java threads to simulate the
request primitive you are currently modelling: one-way, deferred
synchronous or asynchronous. (HINT: You may notice the behaviour of the
request primitives if
you put a delay, e.g. using java.io.Thread.sleep()
before calling the method balance() of the server).
- Application Execution – Now run the Server application so that an instance of
the AccountImpl servant class is loaded
and the reference to this object is exported to a file. Finally run the Client
application, in a different Unix shell, to verify
that it can cause the server to deposit into a bank account and display
the balance as requested.
- Compile the sources as follows: ( copy into a shell script)
mico-c++ -I. -I/opt/ucl/include -c account.cc -o account.o
mico-c++ -I. -I/opt/ucl/include -c server1.cc -o
server1.o
mico-ld -L /opt/ucl/lib account.o server1.o
-lmico2.3.10 -o server1
javac *.java. (to
compile all the Java side, i.e. the client, the stub and the skeleton)
- Run the application: Run the Server application so that an instance of the AccountImpl servant class is loaded and the
reference to this object is exported to a file.
- Run the Client application
in a different Unix shell, to verify that it can
cause the server to deposit into a bank account and display the balance as
requested.
java AccountClient
- Run on another server: use telnet to log on to another machine: telnet chaiwan
- Start the server in the shell running telnet. Run the client on a local shell
terminal.