SEARCH A NUMBER IN AN ARRAY USING CORBA


Idl file   inter.idl
module searchapp
{
typedef long a[20];
interface inter
{
long search(in long a,in a a1 ,in long item);
};
};

Implementation file    searchimp.java
import searchapp.*;
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA.*;
class searchimp extends interPOA
{
private ORB orb;
public searchimp()
{
}
public int search(int s,int r[],int n)
{
int i,f = 0;
for(i=0;i<n;i++)
{
if(r[i] == s)
{
f=1;
break;
}
}
if(f == 1)
{
i=i;
System.out.println("Element is found"+r[i]);
i=i+1;
System.out.println("The Position is"+i);
}
else
{
System.out.println("Element not found");
}
return(i);
}
public void setORB(ORB orb_val)
{
orb=orb_val;
}
}

Server file  searchserver.java

import searchapp.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
public class searchserver
{
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();
searchimp noteref = new searchimp();
noteref.setORB(orb);
org.omg.CORBA.Object ref =rootpoa.servant_to_reference(noteref);
inter href=interHelper.narrow(ref);
org.omg.CORBA.Object obref=orb.resolve_initial_references("NameService");
NamingContext ncref = NamingContextHelper.narrow(obref);
NameComponent nc=new NameComponent("inter","");
NameComponent path[] = {nc};
ncref.rebind(path,href);
java.lang.Object sync=new java.lang.Object();
synchronized(sync)
{
sync.wait();
}
}
catch(Exception e)
{
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
}
}

Client file  searchclient.java

import searchapp.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
import java.io.*;
public class searchclient
{
public static void main(String args[])
{
int r[],i;
r=new int[20];
try
{
ORB orb = ORB.init(args,null);
org.omg.CORBA.Object obref = orb.resolve_initial_references("NameService");
NamingContext ncref = NamingContextHelper.narrow(obref);
NameComponent nc=new NameComponent("inter","");
NameComponent path[] = {nc};
inter href = interHelper.narrow(ncref.resolve(path));
java.io.DataInputStream dts=new java.io.DataInputStream(System.in);
System.out.println("Enter size of Array:");
int n= Integer.parseInt(dts.readLine());
System.out.println("Enter elements of array:");
for(i=0;i<n;i++)
{
r[i]=Integer.parseInt(dts.readLine());
}
System.out.println("Enter element you want to search:");
int a=Integer.parseInt(dts.readLine());
href.search(a,r,n);
}
catch (Exception e)
{
System.out.println("ERROR : " + e) ;
e.printStackTrace(System.out);
                   }
                }
            }








Compilation



D:\kar\New Folder\search>set path=C:\java\jdk1.6.0\bin;

D:\kar\New Folder\search>idlj -fall inter.idl


D:\kar\New Folder\search>cd searchapp


D:\kar\New Folder\search\searchapp>path.bat

D:\kar\New Folder\search\searchapp>set path=C:\java\jdk1.6.0\bin;

D:\kar\New Folder\search\searchapp>javac *.java
Note: interPOA.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

D:\kar\New Folder\search\searchapp>cd..

D:\kar\New Folder\search>javac *.java
Note: searchclient.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

D:\kar\New Folder\search>

D:\kar\New Folder\search>tnameserv
Initial Naming Context:
IOR:000000000000002b49444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e67436f
6e746578744578743a312e30000000000001000000000000009a000102000000000e3139322e3136
382e312e32303200038400000045afabcb0000000020000f42400000000100000000000000020000
0008526f6f74504f41000000000d544e616d65536572766963650000000000000008000000010000
00011400000000000002000000010000002000000000000100010000000205010001000100200001
0109000000010001010000000026000000020002
TransientNameServer: setting port for initial object references to: 900
Ready.

open new window

D:\kar\New Folder\search>java searchserver

open new window

D:\kar\New Folder\search>java searchclient
Enter size of Array:
5
Enter elements of array:
11
22
33
44
55
Enter element you want to search:
44

output on server window


D:\kar\New Folder\search>java searchserver
Element is found44
The Position is4


0 Response to "SEARCH A NUMBER IN AN ARRAY USING CORBA"

Post a Comment



Your IP Address is:

Browser: