Docstoc

DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA

Document Sample
DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING WEATHER FORECAST INFORMATION USING CORBA Powered By Docstoc
					  DEVELOP A MIDDLEWARECOMPONENT FOR RETRIEVING
    WEATHER FORECAST INFORMATION USING CORBA

AIM: To Create a Component for retrieving stock market exchange information using
CORBA
DESCRIPTION:
      Steps required:
       1. Define the IDL interface
       2. Implement the IDL interface using idlj compiler
       3. Create a Client Program
       4. Create a Server Program
       5. Start orbd.
       6. Start the Server.
       7. Start the client
// Define IDL Interface
module weather{
interface forecast
{
  float get_min();
  float get_max();};};
Note: Save the above module as weather.idl
Compile the saved module using the idlj compiler as follows .
C:\sowmi\weather>idlj weather.idl
 After compilation a sub directory called weather same as module name will be created
and it generates the following files as listed below.
C:\sowmi\weather>cd weather
C:\sowmi\weather\weather>dir
 Volume in drive C has no label.
 Volume Serial Number is 348A-27B7
 Directory of C:\suji\weather\weather
03/14/2007 02:52 PM <DIR>                .
03/14/2007 02:52 PM <DIR>                ..
03/14/2007 02:55 PM            2,240 forecastPOA.java
03/14/2007 02:55 PM            2,729 _forecastStub.java
03/14/2007 02:55 PM              796 forecastHolder.java
03/14/2007 02:55 PM            1,926 forecastHelper.java
03/14/2007 02:55 PM              330 forecast.java
03/14/2007 02:55 PM              319 forecastOperations.java
03/15/2007 10:42 AM             2,144 forecastPOA.class
03/15/2007 10:42 AM               167 forecastOperations.class
03/15/2007 10:42 AM               207 forecast.class
03/15/2007 10:42 AM             2,724 forecastHelper.class
03/15/2007 10:42 AM             2,403 _forecastStub.class
         11 File(s)      15,985 bytes
          2 Dir(s) 1,726,103,552 bytes free
C:\sowmi\weather\weather>
// Implement the interface
import org.omg.CORBA.*;
import weather.*;
import java.util.*;
public class weatherimpl extends forecastPOA
{
  private ORB orb;
  int r[]=new int[10];
  float s[]=new float[10];
  Random rr=new Random();
  public void setORB(ORB v){orb=v;}
         public float get_min()       {
       for(int i=0;i<10;i++)
       {
          r[i]=Math.abs(rr.nextInt());
          s[i]=Math.round((float)r[i]*0.00000001);
                 }
       float min;
       min=s[0];
       for(int i=1;i<10;i++)       {
         if (min>s[i])
            min =s[i];     }
               float mintemp=Math.abs((float)(min-32)*5/9);

   return mintemp;}
public float get_max()
{
       for(int i=0;i<10;i++)
      {
         r[i]=Math.abs(rr.nextInt());
         s[i]=Math.round((float)r[i]*0.00000001);             }
      float max;
      max=s[0];
   for(int i=1;i<10;i++)
      {
        if (max<s[i])
           max =s[i];      }
      float maxtemp=Math.abs((float)(max-32)*5/9);
  return maxtemp;}
public weatherimpl(){super();}}
  //Server Program
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA.*;
import java.util.Properties;
import weather.*;
public class weatherserver{
  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();
                weatherimpl ss=new weatherimpl();
     ss.setORB(orb);
     org.omg.CORBA.Object ref=rootpoa.servant_to_reference(ss);
     forecast hrf=forecastHelper.narrow(ref);
      org.omg.CORBA.Object orf=orb.resolve_initial_references("NameService");
      NamingContextExt ncrf=NamingContextExtHelper.narrow(orf);
      NameComponent path[]=ncrf.to_name("forecast");
      ncrf.rebind(path,hrf);
    System.out.println("weather server is ready");
orb.run();
}
catch(Exception e){
e.printStackTrace();}}}
     // Client Program
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import weather.*;
import org.omg.CosNaming.NamingContextPackage.*;
import java.util.*;
public class weatherclient
{
  public static void main(String[] args)
  {
  String city[]={"Chennai ","Trichy ","Madurai ","Coimbatore","Salem "};
  Calendar cc=Calendar.getInstance();
  try
  {
        ORB orb=ORB.init(args,null);
     NamingContextExt
ncRef=NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"))
;      forecast fr=forecastHelper.narrow(ncRef.resolve_str("forecast"));
    System.out.println("\t\t\tW E A T H E R F O R E C A S T");
    System.out.println("\t\t\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
    System.out.println();
    System.out.println("\tDATE TIME CITY                 HIGHEST         LOWEST ");
    System.out.println("\t                   TEMPERATURE           TEMPERATURE");
   for(int i=0;i<5;i++) {
System.out.print("\t"+cc.get(Calendar.DATE)+cc.get(Calendar.MONTH)+cc.get(Calend
ar.YEAR)+" "+cc.get(Calendar.HOUR)+" "+city[i]+"              "+" ");
    System.out.print(Math.floor(fr.get_min())+"\t \t"+Math.ceil(fr.get_max()));
    System.out.println(); }}
catch(Exception e){
e.printStackTrace();}}}
     Compile the above files as
  C:\sowmi\weather>javac *.java
C:\sowmi\weather>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost




C:\sowmi\corba>start java weatherserver -ORBInitialPort 1050 -ORBInitialHost
localhost
C:\sowmi\weather>
weather server is ready
C:\sowmi\corba>java weatherclient -ORBInitialPort 1050 -ORBInitialHost localh
ost

C:\sowmi\weather>java weatherclient -ORBInitialPort 1050 -ORBInitialHost
localhost

				
DOCUMENT INFO
Shared By:
Categories:
Stats:
views:8
posted:9/1/2012
language:English
pages:4
Description: web designing notes for all BE/B-tech students