the program is to be implemented using JAVA and CORBA architecture
CountPOAServer.java
// CountPOAServer.java: The Count Server main program import org.omg.PortableServer.*; import org.omg.CosNaming.*; class CountPOAServer { static public void main(String[] args) { try { // Initialize the ORB org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); // get a reference to the root POA POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA")); // Create policies for our persistent POA org.omg.CORBA.Policy[] policies = { rootPOA.create_lifespan_policy(LifespanPolicyValue.TRANSIENT) }; // Create myPOA with the right policies POA myPOA = rootPOA.create_POA( "count_poa", rootPOA.the_POAManager(), policies ); // Create the servant CountPOAServant[] countServer = new CountPOAServant[1000]; String str; long startTime=System.currentTimeMillis(); for(int i=0;i<1000;i++) { str="my Count "+i; // Decide on the ID for the servant byte[] countId = "count".getBytes(); countServer[i] = new CountPOAServant(); System.out.println("my count "+i+" created"); // Activate the servant with the ID on myPOA /*CountPOAServant countobj = new CountPOAServant(); countobj = countServer[i]; [U] myPOA.activate_object_with_id(countId,countServer[i]);[/U][QUOTE]shown as an error[/QUOTE] } long stoptime=System.currentTimeMillis(); System.out.println("Average time="+(stoptime-startTime)/1000f+" msec"); // Activate the POA manager rootPOA.the_POAManager().activate(); // get a reference to the Naming Service root context org.omg.CORBA.Object nameServiceObj = orb.resolve_initial_references("NameService"); if (nameServiceObj == null) { System.out.println("nameServiceObj = null"); return; } NamingContextExt nameService = NamingContextExtHelper.narrow(nameServiceObj); if (nameService == null) { System.out.println("nameService = null"); return; } // bind the Count object in the Naming service for(int j=0;j<=1000;j++) { NameComponent[] countName = {new NameComponent("countName", "")}; [U]nameService.rebind(countName, myPOA.servant_to_reference(countServer[j]));[/U][QUOTE]shown as an error[/QUOTE] [U] System.out.println(myPOA.servant_to_reference(countServer[j]) +" is ready.");[/U][QUOTE]shown as an error[/QUOTE] } // Wait for incoming requests orb.run(); } catch(Exception e) { System.err.println(e); } } }
the following is the error generated:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method activate_object_with_id(byte[], Servant) in the type POAOperations is not applicable for the arguments (byte[], CountPOAServant)
The method servant_to_reference(Servant) in the type POAOperations is not applicable for the arguments (CountPOAServant)
The method servant_to_reference(Servant) in the type POAOperations is not applicable for the arguments (CountPOAServant)
at CountPOAServer.main(CountPOAServer.java:39)
CountPOAClient.java
// CountPOAClient.java Static Client, VisiBroker for Java import org.omg.CosNaming.*; class CountPOAClient { public static void main(String args[]) { try { // Initialize the ORB System.out.println("Initializing the ORB"); org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, null); // Get a reference to the Naming service org.omg.CORBA.Object nameServiceObj = orb.resolve_initial_references ("NameService"); if (nameServiceObj == null) { System.out.println("nameServiceObj = null"); return; } org.omg.CosNaming.NamingContext nameService = org.omg.CosNaming.NamingContextHelper.narrow (nameServiceObj); if (nameService == null) { System.out.println("nameService = null"); return; } // resolve the Count object in the Naming service /* NameComponent[] countName = {new NameComponent("countName", "")}; CounterPOA.Count counter = CounterPOA.CountHelper.narrow(nameService.resolve(countName));*/ [U]CounterPOACount[] countObj = new CounterPOACount[1000];[/U][QUOTE]shown as an error[/QUOTE] for(int i=0;i<1000;i++) { NameComponent[] countName= { new NameComponent("My Count"+(i+1),"")}; countObj[i] = [U] CounterPOACount.CountHelper.narrow(nameService.resolve(countName));[/U][QUOTE]shown as an error[/QUOTE] countObj[i].sum((int)0); } // Set sum to initial value of 0 System.out.println("Setting sum to 0"); // counter.sum((int)0); // Calculate Start time long startTime = System.currentTimeMillis(); // Increment 1000 times System.out.println("Incrementing"); for (int i = 0 ; i < 1000 ; i++ ) { int random=(int)(Math.random()*1000); countObj[random].increment(); //counter.increment(); } // Calculate stop time; print out statistics long stopTime = System.currentTimeMillis(); System.out.println("Avg Ping = " + ((stopTime - startTime)/1000f) + " msecs"); int sum=0; for(int i=0;i<1000;i++) { sum= sum + countObj[i].sum(); } System.out.println(" Avg Sum=" +sum/countObj.length); // System.out.println("Sum = " + counter.sum()); } catch(Exception e) { System.err.println("Exception"); System.err.println(e); } } }
the following is the error generated:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
CounterPOACount cannot be resolved to a type
CounterPOACount cannot be resolved to a type
CounterPOACount cannot be resolved
at CountPOAClient.main(CountPOAClient.java:34)
CountPOAServant.java
// CountPOAServant.java: The Count Implementation class CountPOAServant extends CounterPOA.CountPOA { private int sum; // Constructors CountPOAServant() { super(); System.out.println("Count Object Created"); sum = 0; } // get sum public synchronized int sum() { return sum; } // set sum public synchronized void sum(int val) { sum = val; } // increment method public synchronized int increment() { sum++; return sum; } }
the program is to be implemented using JAVA and CORBA architecture