Google Ads

Wednesday, March 10, 2010

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


No comments:

Post a Comment