CORBA - STOCK APPLICATION


AIM:
    To write a Java program for the implementation of stock application using CORBA.

ALGORITHM:

SERVER SIDE:
Step 1: Start
Step 2: Define the class StockMarketServer
Step 3: Initialize the objects orb, StockMarketImpl, objRef, ncRef, nc, path[] in try
Step 4: Connect the object StockMarketImpl
Step 5: Rebind the objects path, StockMarketImpl
Step 6: Make ready the StockMarket server
Step 7: Call the method printStackTrace() in catch
Step 8: Stop

CLIENT SIDE:
Step 1: Start
Step 2: Define the class StockMarketClient
Step 3: Initialize the objects din, orb, ncRef , path[], market in try
Step 4: Read the company name
Step 5: Display the price of the company by calling the method get_price()
Step 6: Call the method printStackTrace() in catch
Step 7: Stop

SOURCE CODE:

StockMarket.idl
module SimpleStocks
{

    interface StockMarket
    {
        float get_price(in string symbol);
    };
};

StockMarketImpl.java
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import SimpleStocks.*;
public class StockMarketImpl extends _StockMarketImplBase
{
    public float get_price(String symbol)
    {
        float price=0;
        if(symbol.equals("TCS"))
            price=1000;
        else if(symbol.equals("CTS"))
            price=800;
        else if(symbol.equals("INFOSYS"))
            price=1200;
        else if(symbol.equals("WIPRO"))
            price=900;
        else
            price=0;
        return price;
    }
    public StockMarketImpl()
    {
        super();
    }
}

StockMarketServer.java
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import SimpleStocks.*;
public class StockMarketServer
{
    public static void main(String args[])
    {
        try
        {
            ORB orb=ORB.init(args,null);
            StockMarketImpl stockMarketImpl=new StockMarketImpl();
            orb.connect(stockMarketImpl);
            org.omg.CORBA.Object objRef=orb.resolve_initial_references("NameService");
            NamingContext ncRef=NamingContextHelper.narrow(objRef);
            NameComponent nc=new NameComponent("NASDAQ","");
            NameComponent path[]={nc};
            ncRef.rebind(path,stockMarketImpl);
            System.out.println("Stock market server is ready");
            Thread.currentThread().join();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

StockMarketClient.java
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import SimpleStocks.*;
import java.io.DataInputStream;
public class StockMarketClient
{
    public static void main(String args[])
    {
        try
        {
            DataInputStream din=new DataInputStream(System.in);
            ORB orb=ORB.init(args,null);
            NamingContext ncRef=NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
NameComponent path[]={new NameComponent("NASDAQ","")};
StockMarket market=StockMarketHelper.narrow(ncRef.resolve(path));
System.out.println("\nEnter the company name: ");
String company=din.readLine();
System.out.println("\nPrice of my company is: " +market.get_price(company));
}
        catch(Exception e)
        {
            e.printStackTrace();
        }
}
}

OUTPUT:

SERVER SIDE:

 CLIENT SIDE:



RESULT:
          Thus the Java program for the implementation of stock application was performed and the output was verified.

.
Previous
Next Post »

Still not found what you are looking for? Try again here.