Safe Electronic Postcard Application with CORBA (part III)
Name
Short: Central Coordinator CORBA server
Long: Safe Electronic Postcard Application with CORBA (part III)
Objective
The purpose of this lab is to implement a safe way of using the Corba CardWriter server.
CardWriter Server Problem
The current implementation of the CardWriter class has a problem that potentially
occurs when two clients access concurrently the CardWriter object.
Assume for example, that there are two clients that create two references to the CardWriter: c1 and c2.
Client1
c1.setCard(inputCardName1, x1,y1,width1,height1);
c1.setMesage("message1");
c1.writeCard(outputFileName1);
Client2
c2.setCard(inputCardName2, x2,y2,width2,height2);
c2.setMesage("message2");
c2.writeCard(outputFileName2);
Imagine that these operations are performed in the following order:
c1.setCard(inputCardName1, x1,y1,width1,height1);
c1.setMesage("message1");
c2.setCard(inputCardName2, x2,y2,width2,height2);
c2.setMesage("message2");
c1.writeCard(outputFileName1);
c2.writeCard(outputFileName2);
As a result, Client1 will get the card writen by Client2 (actually it can realize that something
went wrong because the name returned by the CardWriter is not the one supplied by Client1).
Client2 will not encounter any misbehavings.
Assumption
One solution would be to make the operations from the CardWriter
that are involved in creating the picture atomic.
However, this requires access to the CardWriter code. We assume that we
can not modify the CardWriter class.
Instead, your task is to design "polite" clients and a central coordinator
that grants access to the clients that want to use the CardWriter object.
Time allocation
Four hours are allocated to complete this lab assignment.
Exercise
You will have to implement in (C++ or Java) the Coordinator server for
the application written in the previous assignments and then modify the client to use the Coordinator
for requesting and releasing the access to the CardWriter object.
The IDL interface for the Coordinatoris given.
TO DO
- Make sure that you completed the first 2 steps in Assignment 3.
- Show an example of a possible misbehaviour of the CardWriter when is concurrently accessed by two clients
- Modify the "Hello world" example in order to implement the Coordinator object:
- Create the stub and the skeleton (if you haven't created them before):
- idl Coordinator.idl (C++)
- jidl --package database Coordinator.idl (Java)
- Write a class Coordinator_impl which implements the Coordinator interface
- class Coordinator_impl : public POA_Coordinator,
public PortableServer::RefCountServantBase (C++)
- class Coordinator_impl extends CoordinatorPOA (Java)
- Modify the Server.cpp(.java) file by replacing all "Hello" with "Coordinator" and "hello" with "coordinator".
- Remove the lines which save the object reference in a file.
Instead, you will have to make the Coordinator 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 Coordinator 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 coordName;
coordName.length(1);
coordName[0].id = CORBA::string_dup("Coordinator");
coordName[0].kind = CORBA::string_dup("alean_cpp");
nc -> bind(coordName, coordinator.in());
- Java:
NameComponent[] nc = new NameComponent[1];
nc[0]=new NameComponent("Coordinator","alean_java");
((NamingContext)root).bind(nc, rootPOA.servant_to_reference(coordImpl));
The above source code will bind the Coordinator object through the name
Coordinator.alean_cpp (or Coordinator.alean_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 Coordinator 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 Coordinator 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 Coordinator object each time it wants
to create a new postcard with the CardWriter. It should use the RequestAccess() method in order to ask permission
to use the CardWriter and then ReleaseAccess() method when it finishes such that other clients can use the Card Writer as well.
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