Back to Naming Service Examples Page
The LoadBalancing example shows how to use OpenFusion's LoadBalancer in CosNaming. The example shows how to create multiple CORBA Objects and bind them to the Naming Service with a specific, predefined OpenFusion LoadBalancing policy. The Object bound into the Naming Service in this example is called "Server".
A Client is then able to resolve a Server by resolving it from the Naming Service. Which object is returned depends on the Load Balancing policy that was set when the "Server" Objects were bound to the Naming Service.
The example assigns a unique name to each of the "Server" objects so that the user is able to see clearly which "Server" object is returned by the Naming Service, and hence see what effect the LoadBalancing policies have.
The example consists of a Server object which is bound into the Naming Service, an LBServer object, and an LBClient object. The LBServer is used to place the Server objects into the Naming Service and then waits so that the LBClients are able to resolve a reference to the Server objects. The example consists of three objects: ServerImpl, LBServer, and LBClient.
ServerImpl.java is the CORBA Object that gets bound into the Naming Service. When instantiated it assigns a unique name to itself and provides a method so that other objects can retrieve its unique name. The first Server object to be instantiated has the name "Server 0". The second has the name "Server 1", and so on.
LBServer.java creates three Server objects (see above), and binds them to the Naming Service with a "RoundRobin" LoadBalancing policy.
The LBServer will perform the following tasks:
LBClient.java will resolve the Server Object from the Naming Service, and invoke a method on it to retrieve the Server's name.
The LBClient will perform the following tasks:
getName
method resolved Server object.
First make sure the OpenFusion Naming Service is running on your network with the LoadBalancing option enabled (see above).
If using an ORB which requires persistent POAs to be registered
before they can be activated, ensure that the OpenFusion.NamingLBServer
POA is registered.
run -x com.prismt.cos.CosNaming.examples.LoadBalance.LBServer
This will start the server which has bound a number of objects under the same name in the Naming Service. This should output "Entering Server Loop..." upon successful execution.
run -x com.prismt.cos.CosNaming.examples.LoadBalance.LBClient
This will resolve a number of Server objects and display their unique ID to the screen, in the order they were resolved under the RoundRobin LoadBalancing policy.