Electronic Postcard Application with CORBA (part II)
Name
Short: CORBA server
Long: Electronic Postcard Application with CORBA (part II)
Objective
The purpose of this lab is to implement the server part of a distributed
application using CORBA.
Time allocation
Four hours are allocated to complete this lab assignment.
Exercise
You will have to implement in (C++ or Java) the Database server for
the application written in the previous assignment. The IDL interface for
the Database
is given, along with the information regarding the existing card
database.
TO DO
- Make sure that you completed the first 2 steps in Assignment 3.
- Modify the "Hello world" example in order to implement the Database object:
- Create the stub and the skeleton (if you haven't created them before):
- idl Database.idl (C++)
- jidl --package database Database.idl (Java)
- Write a class Database_impl which implements the Database interface
- class Database_impl : public POA_Database,
public PortableServer::RefCountServantBase (C++)
- class Database_impl extends DatabasePOA (Java)
- Modify the Server.cpp(.java) file by replacing all "Hello" with "Database" and "hello" with "database".
- Remove the lines which save the object reference in a file.
Instead, you will have to make the Database object accessible through the NameService.
- Obtain a reference to the NameService:
- C++:
CORBA::Object_var obj = orb -> resolve_initial_references("NameService");
CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj.in());
- Java:
org.omg.CORBA.Object rootObj = orb.resolve_initial_references("NameService");
org.omg.CosNaming.NamingContext root = org.omg.CosNaming.NamingContextHelper.narrow(rootObj);
- Bind the name of the Database object to the NameService. In order to do this,
you'll first have to create a name component wich will be used for binding.
- C++:
CosNaming::Name dbName;
dbName.length(1);
dbName[0].id = CORBA::string_dup("Database");
dbName[0].kind = CORBA::string_dup("trapo_cpp");
nc -> bind(dbName, database.in());
- Java:
NameComponent[] nc = new NameComponent[1];
nc[0]=new NameComponent("Database","trapo_java");
((NamingContext)root).bind(nc, rootPOA.servant_to_reference(dbImpl));
The above source code will bind the Database object through the name
Database.trapo_cpp (or Database.trapo_java, respectively).
It is recommended that you create unique name components, so that your
bindings will not conflict with the bindings of your colleagues.
For more details about naming service concepts, you can take a look at
chapters 9.4 and 9.5 in the
ORBacus documentation.
- Compile and start your Database server. Also, make sure that you specify the location of the NameService:
- java Server -ORBInitRef NameService=corbaloc::mir14:10000/NameService (Java)
- ./server -ORBInitRef NameService=corbaloc::mir14:10000/NameService (C++)
- Test your Database server. In order to do this, you will
have to modify the client you have written in the previous assignment.
The client should access now your Database object instead of the
one provided by us.
Reporting your work
The lab is reported by showing the assistant the working application.
All members of the lab group should be present when reporting.
Appendices