Java Blog

 
 
 
----------------------------------------------------------------------------------
                    IDL
----------------------------------------------------------------------------------
module CircleApp
{
    interface Circle
    {
        float area(in float val);
        oneway void shutdown();
    };
};

-------------------------------------------------------------------------------------------------
                    Server
-------------------------------------------------------------------------------------------------

import CircleApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;

import java.util.Properties;

class CircleImpl extends CirclePOA
{
    private ORB orb;

    public void setORB(ORB orb_val)
    {
        orb = orb_val; 
    }

    public float area(float val)
    {
        float res = (float)( Math.PI * val * val );
        return res;
    }
    public void shutdown()
    {
        orb.shutdown(false);
    }
}


public class CircleServer
{

    public static void main(String args[])
    {
        try
        {
            ORB orb = ORB.init(args, null);
            POA rootpoa = POAHelper.narrow(orb.resolve_initial_references(\"RootPOA\"));
            rootpoa.the_POAManager().activate();

            CircleImpl circleImpl = new CircleImpl();
            circleImpl.setORB(orb); 

            org.omg.CORBA.Object ref = rootpoa.servant_to_reference(circleImpl);
            Circle href = CircleHelper.narrow(ref);

            org.omg.CORBA.Object objRef =orb.resolve_initial_references(\"NameService\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

            String name = \"Circle\";
            NameComponent path[] = ncRef.to_name( name );
            ncRef.rebind(path, href);

            System.out.println(\"CircleServer ready and waiting ...\");

            orb.run();
        } 

        catch (Exception e) 
        {
            System.err.println(\"ERROR: \" + e);
            e.printStackTrace(System.out);
        }

        System.out.println(\"CircleServer Exiting ...\");
    }
}

-------------------------------------------------------------------------------------------------
                    Client
-------------------------------------------------------------------------------------------------

import CircleApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import java.io.*;

public class CircleClient
{
    public float getValue() throws IOException
    {
        float val = 0;
        try
        {
            System.out.print(\"Enter the value : \");
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String s=br.readLine();
            val = Float.parseFloat (s);
        }
        catch (IOException e)
        {
            System.out.println(e);
        }
        return val;
    }

    public static void main(String args[])
    {
        Circle circleImpl=null;
        CircleClient cc = new CircleClient();

        try
        {
            ORB orb = ORB.init(args, null);
            org.omg.CORBA.Object objRef = orb.resolve_initial_references(\"NameService\");
            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
            String name = \"Circle\";
            circleImpl = CircleHelper.narrow(ncRef.resolve_str(name));

            float val = 0, res = 0;
            val = cc.getValue();
            res=circleImpl.area(val);
            System.out.println(\"Result : \" + res);

            circleImpl.shutdown();

        }
        catch (Exception e) 
        {
            System.out.println(\"ERROR : \" + e) ;
            e.printStackTrace(System.out);
        }
    }

}

-------------------------------------------------------------------------------------------------
                    Output
-------------------------------------------------------------------------------------------------

Enter the value : 2
Result : 12.566371

    Related Post:
  1. Program to show the use of operator (>>>) Shift Right, filling with zeros from the left

  2. Program to show an example of extracting subStrings from a String

  3. RMI based application, which reads a file with list of marks of student from a client, send it to server and find how many students having distinct

  4. Program that demonstrates type casting

  5. Program to show an example of Calling a Base Class Method from a Derived Class

  6. Program to show the use of Bitwise Operator (^) XOR (Exclusive OR)

  7. Program of linear search

  8. File handling program to copy characters from one file to another

  9. CORBA program for displaying the date and time of the server machine, client machine and the difference between these two date and time

  10. An applet program showing Clicked Event on canvas

  11. Program to show an example of extraction of characters from a StringBuffer objects

  12. Program to show an example of creating Character Arrays from String objects

  13. Program to show the use of Labeled Break Statement

  14. Program, which creates a three thread. One thread display the numbers from 1 to 5, second thread display the square root of that number etc

  15. Program of date server and client

  16. File handling program to display directory contents

  17. Corba program to develop a simple calculator with addition, subtraction, multiplication and division capabilities, data collection from client side

  18. An applet program to perform quick sort

  19. An applet program of passing parameters

  20. Create an interface coversions. Which have the following functions Inchestomillimeters(), hptowatts(),wattstohp(),poundstogram(),gramtopounds()