Google Ads
Wednesday, March 10, 2010
STOCK MARKET EXCHANGE INFORMATION USING CORBA
StockMarket.idl
module SimpleStocks
{
interface StockMarket
{
float get_price(in string symbol);
};
};
StockMarketImpl.java
import org.omg.CORBA.*;
import SimpleStocks.*;
public class StockMarketImpl extends StockMarketPOA
{
private ORB orb;
public StockMarketImpl(ORB orb)
{
this.orb=orb; }
public float get_price(String symbol)
{
float price = 0;
for(int i=0;i < symbol.length();i++)
{
price += (int)symbol.charAt(i);
}
price /= 5;
return price;
}
}
StockMarketServer.java
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import SimpleStocks.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import org.omg.CosNaming.NamingContextPackage.*;
public class StockMarketServer
{
public static void main(String[] args)
{
try
{
ORB orb = ORB.init(args,null);
StockMarketImpl stockMarketImpl = new StockMarketImpl(orb);
POA rootpoa=POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
org.omg.CORBA.Object ref=rootpoa.servant_to_reference(stockMarketImpl);
StockMarket href=StockMarketHelper.narrow(ref);
org.omg.CORBA.Object object = orb.resolve_initial_references("NameService");
NamingContextExt root = NamingContextExtHelper.narrow(object);
NameComponent name = new NameComponent("NASDAQ","");
NameComponent path[] = {name};
root.rebind(path,href);
System.out.println("Server is Ready.............");
orb.run();
}
catch(Exception e)
{
System.err.println("ERROR"+e);
}
}}
StockMarketClient.java
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import SimpleStocks.*;
import org.omg.CosNaming.NamingContextPackage.*;
public class StockMarketClient{
public static void main(String[] args)
{
try
{
ORB orb = ORB.init(args,null);
org.omg.CORBA.Object object=orb.resolve_initial_references("NameService");
NamingContextExt root = NamingContextExtHelper.narrow(object);
NameComponent name = new NameComponent("NASDAQ","");
NameComponent path[] = {name};
StockMarket market = StockMarketHelper.narrow(root.resolve(path));
System.out.println("Price of MY COMPANY is " + market.get_price("MY_COMPANY"));
}
catch(Exception e )
{
System.err.println( e ); } }}
Output:
C:\jdk1.5.0\bin>javac StockMarketServer.java
C:\jdk1.5.0\bin>javac StockMarketClient.java
C:\jdk1.5.0\bin>java StockMarketServer ORBInitialPort-2500
Server is Ready.............
C:\jdk1.5.0\bin>java StockMarketClient ORBInitialPort-2500
Price of MY COMPANY is 159.2
WEATHER FORECAST INFORMATION USING CORBA
Weather.idl
module Weather1
{
interface Weather
{
double FahToCel(in double degree);
};
};
WeatherImpl.java
import Weather1.*;
import org.omg.CORBA.*;
public class WeatherImpl extends WeatherPOA
{
private ORB orb;
public WeatherImpl(ORB orb)
{
this.orb = orb;
}
public double FahToCel(double F)
{
double c;
c = ((F-32)*5)/9;
return c;
}
}
WeatherServer.java
import Weather1.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
public class WeatherServer
{
public static void main(String args[])
{
try
{
ORB orb = ORB.init(args,null);
WeatherImpl impl = new WeatherImpl(orb);
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(impl);
Weather wref = WeatherHelper.narrow(ref);
org.omg.CORBA.Object objref = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objref);
NameComponent nc = new NameComponent("Weather","");
NameComponent path[] = {nc};
ncRef.rebind(path,wref);
System.out.println("Server ready & waiting.....");
orb.run();
}
catch(Exception e)
{
System.err.println("ERROR"+e);
}
System.out.println("Server Exiting............");
}
}
WeatherClient.java
import Weather1.*;
import java.io.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class WeatherClient
{
public static void main(String args[])
{
double F;
BufferedReader stdin;
try
{
ORB orb = ORB.init(args,null);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
NameComponent nc = new NameComponent("Weather","");
NameComponent path[] = {nc};
Weather impl = WeatherHelper.narrow(ncRef.resolve(path));
stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the temperature in Fah");
F = Double.parseDouble(stdin.readLine());
double cel = impl.FahToCel(F);
System.out.println("Temperature in Celcius:"+String.valueOf(cel));
}
catch(Exception e)
{
System.out.println("ERROR:"+e);
}
}
}
Output
C:\jdk1.5\bin>idlj -fall Weather.idl
C:\jdk1.5\bin>javac WeatherImpl.java
C:\jdk1.5\bin>javac WeatherServer.java
C:\jdk1.5\bin>javac WeatherClient.java
C:\jdk1.5\bin>orbd ORBInitialPort-2500
C:\jdk1.5\bin>java WeatherServer ORBInitialPort-2500
Server ready & waiting.....
C:\>cd jdk1.5\bin
C:\jdk1.5\bin>java WeatherClient ORBInitialPort-2500
Enter the temperature in Fah
45
Temperature in Celcius:7.222222222222222
module Weather1
{
interface Weather
{
double FahToCel(in double degree);
};
};
WeatherImpl.java
import Weather1.*;
import org.omg.CORBA.*;
public class WeatherImpl extends WeatherPOA
{
private ORB orb;
public WeatherImpl(ORB orb)
{
this.orb = orb;
}
public double FahToCel(double F)
{
double c;
c = ((F-32)*5)/9;
return c;
}
}
WeatherServer.java
import Weather1.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
public class WeatherServer
{
public static void main(String args[])
{
try
{
ORB orb = ORB.init(args,null);
WeatherImpl impl = new WeatherImpl(orb);
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(impl);
Weather wref = WeatherHelper.narrow(ref);
org.omg.CORBA.Object objref = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objref);
NameComponent nc = new NameComponent("Weather","");
NameComponent path[] = {nc};
ncRef.rebind(path,wref);
System.out.println("Server ready & waiting.....");
orb.run();
}
catch(Exception e)
{
System.err.println("ERROR"+e);
}
System.out.println("Server Exiting............");
}
}
WeatherClient.java
import Weather1.*;
import java.io.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public class WeatherClient
{
public static void main(String args[])
{
double F;
BufferedReader stdin;
try
{
ORB orb = ORB.init(args,null);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
NameComponent nc = new NameComponent("Weather","");
NameComponent path[] = {nc};
Weather impl = WeatherHelper.narrow(ncRef.resolve(path));
stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the temperature in Fah");
F = Double.parseDouble(stdin.readLine());
double cel = impl.FahToCel(F);
System.out.println("Temperature in Celcius:"+String.valueOf(cel));
}
catch(Exception e)
{
System.out.println("ERROR:"+e);
}
}
}
Output
C:\jdk1.5\bin>idlj -fall Weather.idl
C:\jdk1.5\bin>javac WeatherImpl.java
C:\jdk1.5\bin>javac WeatherServer.java
C:\jdk1.5\bin>javac WeatherClient.java
C:\jdk1.5\bin>orbd ORBInitialPort-2500
C:\jdk1.5\bin>java WeatherServer ORBInitialPort-2500
Server ready & waiting.....
C:\>cd jdk1.5\bin
C:\jdk1.5\bin>java WeatherClient ORBInitialPort-2500
Enter the temperature in Fah
45
Temperature in Celcius:7.222222222222222
Subscribe to:
Posts (Atom)