Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: help me out with the following code to solve the error

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy help me out with the following code to solve the error

    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
    Last edited by romilc; October 11th, 2009 at 11:32 AM.


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: help me out with the following code to solve the error

    This has been posted in the wrong forum so I have moved it to advanced Java.

    Can you please give us as much information about the error as possible. Does the code compile? When is the error generated etc.

    Last but not least, please remember to use code tags!! Check my signature if your unsure how.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Java error "java.lang.StackOverflowError"
    By sanatkumar in forum Exceptions
    Replies: 2
    Last Post: July 7th, 2009, 02:40 PM
  2. Replies: 3
    Last Post: June 14th, 2009, 09:31 PM
  3. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM
  4. Replies: 2
    Last Post: May 16th, 2009, 05:23 AM