0% found this document useful (0 votes)
275 views13 pages

CORBA Example: Hello Service

The documents describe a CORBA program that uses IDL interfaces to build a client-server application for retrieving bank balance information. The BankServer implements the Bank interface and stores balance data in a database. It registers the object reference with the naming service. The BankClient resolves this reference and invokes the bal() method, passing an account number to retrieve the corresponding balance.

Uploaded by

Sobhan Dasari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
275 views13 pages

CORBA Example: Hello Service

The documents describe a CORBA program that uses IDL interfaces to build a client-server application for retrieving bank balance information. The BankServer implements the Bank interface and stores balance data in a database. It registers the object reference with the naming service. The BankClient resolves this reference and invokes the bal() method, passing an account number to retrieve the corresponding balance.

Uploaded by

Sobhan Dasari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

22. Hello Service using Corba Hello.

idl module HelloApp { interface Hello { string sayHello(); oneway void shutdown(); }; }; [Link] import HelloApp.*; import [Link].*; import [Link].*; import [Link].*; import [Link].*; import [Link]; import [Link]; class HelloImpl extends HelloPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } public String sayHello() { return "\nHello world !!\n"; } public void shutdown() { [Link](false); } } public class HelloServer { public static void main(String args[]) { try{ ORB orb = [Link](args, null); POA rootpoa =[Link](orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); HelloImpl helloImpl = new HelloImpl(); [Link](orb); [Link] ref =rootpoa.servant_to_reference(helloImpl); Hello href = [Link](ref); [Link] objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = [Link](objRef);

String name = "Hello"; NameComponent path[] = ncRef.to_name( name ); [Link](path, href); [Link]("HelloServer ready and waiting ..."); [Link](); } catch (Exception e) { [Link]("ERROR: " + e); [Link]([Link]); } [Link]("HelloServer Exiting ..."); } } [Link] import HelloApp.*; import [Link].*; import [Link].*; import [Link].*; public class HelloClient { static Hello helloImpl; public static void main(String args[]) { try{ ORB orb = [Link](args, null); [Link] objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = [Link](objRef); String name = "Hello"; helloImpl = [Link](ncRef.resolve_str(name)); [Link]("Obtained a handle on server object: " + helloImpl); [Link]([Link]()); [Link](); } catch (Exception e) { [Link]("ERROR : " + e) ; [Link]([Link]); } } }

Output: C:\Documents and Settings\User\Desktop\HelloCorba>idlj -fall [Link] C:\Documents and Settings\User\Desktop\HelloCorba>javac [Link] HelloApp/*.java C:\Documents and Settings\User\Desktop\HelloCorba>javac [Link] HelloApp/*.java C:\Documents and Settings\User\Desktop\HelloCorba>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\HelloCorba>start java HelloServer -ORBInitialPort 1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\HelloCorba> java HelloClient -ORBInitialPort 1050 -ORBInitialHost localhost Obtained a handle on server object: IOR:000000000000001749444c3a48656c6c6f417070 2f48656c6c6f3a312e300000000000010000000000000082000102000000000a3132372e302e302 3100041f00000031afabcb000000002098bbac2000000001000000000000000100000008526f6f7 504f41000000000800000001000000001400000000000002000000010000002000000000000100 00000002050100010001002000010109000000010001010000000026000000020002 Hello world !! C:\Documents and Settings\User\Desktop\HelloCorba>

23. Corba program to add 2 numbers [Link] module AddApp { interface Add { long Add2(in long a,in long b); }; }; [Link] import AddApp.*; import [Link].*; import [Link].*; import [Link].*; import [Link].*; import [Link]; import [Link]; class AddImpl extends AddPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } public int Add2(int a,int b) { return a+b; } } public class AddServer { public static void main(String args[]) { try{ ORB orb = [Link](args, null); POA rootpoa =[Link](orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); AddImpl addImpl = new AddImpl();

[Link](orb); [Link] ref =rootpoa.servant_to_reference(addImpl); Add href = [Link](ref); [Link] objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = [Link](objRef); String name = "Add"; NameComponent path[] = ncRef.to_name( name ); [Link](path, href); [Link]("AddServer ready and waiting ..."); [Link](); } catch (Exception e) { [Link]("ERROR: " + e); [Link]([Link]); } [Link]("AddServer Exiting ..."); } } [Link] import AddApp.*; import [Link].*; import [Link].*; import [Link].*; public class AddClient { static Add addImpl; public static void main(String args[]) { try{ ORB orb = [Link](args, null); [Link] objRef = orb.resolve_initial_references("NameService"); . NamingContextExt ncRef = [Link](objRef); String name = "Add"; addImpl = [Link](ncRef.resolve_str(name)); [Link]("Obtained a handle on server object: " + addImpl); [Link]("sum is:"+addImpl.Add2(3,5)); } catch (Exception e) { [Link]("ERROR : " + e) ; [Link]([Link]);

} } }

Output: C:\Documents and Settings\User\Desktop>cd Add C:\Documents and Settings\User\Desktop\Add>idlj -fall [Link] C:\Documents and Settings\User\Desktop\Add>javac [Link] AddApp/*.java C:\Documents and Settings\User\Desktop\Add>javac [Link] AddApp/*.java C:\Documents and Settings\User\Desktop\Add>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\Add>start java AddServer -ORBInitialPort1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\Add> java AddClient -ORBInitialPort 1050ORBInitialHost localhost Obtained a handle on server object: IOR:000000000000001349444c3a4164644170702f4164643a312e300000000000010000000000 000082000102000000000a3132372e302e302e3100043800000031afabcb000000002098d002e90 0000001000000000000000100000008526f6f74504f41000000000800000001000000001400000 00000000200000001000000200000000000010001000000020501000100010020000101090000 00010001010000000026000000020002 sum is:8

24. Corba program for stock market details retrieval [Link] module StockApp { interface Stock { long show(in string a); }; }; [Link] import StockApp.*; import [Link].*; import [Link].*; import [Link].*; import [Link].*; import [Link]; import [Link].*; import [Link]; class StockImpl extends StockPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } public int show(String a)

{ Connection con; PreparedStatement pt; ResultSet rs; String name = a; int var1=0; try { [Link]("[Link]"); con=[Link]("Jdbc:Odbc:stock"); pt = [Link]("select qty from stockDB where prod=?"); [Link](1, name); rs = [Link](); while ([Link]()) { var1 = [Link]("qty"); } } catch(ClassNotFoundException e){} catch(SQLException p){} return var1; } } public class StockServer { public static void main(String args[]) { try{ ORB orb = [Link](args, null); POA rootpoa =[Link](orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); StockImpl stockImpl = new StockImpl(); [Link](orb); [Link] ref =rootpoa.servant_to_reference(stockImpl); Stock href = [Link](ref); [Link] objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = [Link](objRef); String name = "Stock"; NameComponent path[] = ncRef.to_name( name ); [Link](path, href); [Link]("StockServer ready and waiting ..."); [Link](); } catch (Exception e) { [Link]("ERROR: " + e);

[Link]([Link]); } [Link]("StockServer Exiting ..."); } } [Link] import StockApp.*; import [Link].*; import [Link].*; import [Link].*; public class StockClient { static Stock stockImpl; public static void main(String args[]) { try{ ORB orb = [Link](args, null); [Link] objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = [Link](objRef); String name = "Stock"; stockImpl = [Link](ncRef.resolve_str(name)); [Link]("Obtained a handle on server object: " + stockImpl); String prod="abc"; [Link]("value is: "+[Link](prod)); } catch (Exception e) { [Link]("ERROR : " + e) ; [Link]([Link]); } } } Output: C:\Documents and Settings\User\Desktop>cd stock C:\Documents and Settings\User\Desktop\stock>idlj -fall [Link] C:\Documents and Settings\User\Desktop\stock>javac [Link] StockApp/*.java C:\Documents and Settings\User\Desktop\stock>javac [Link] StockApp/*.java

C:\Documents and Settings\User\Desktop\stock>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\stock>start java StockServer -ORBInitialPort 1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\stock> java StockClient -ORBInitialPort 1050 -ORBInitialHost localhost Obtained a handle on server object: IOR:000000000000001749444c3a53746f636b4170702f53746f636b3a312e30000000000001000 0000000000082000102000000000a3132372e302e302e3100044500000031afabcb000000002098 d59eb400000001000000000000000100000008526f6f74504f41000000000800000001000000001 40000000000000200000001000000200000000000010001000000020501000100010020000101 09000000010001010000000026000000020002 value is: 5000 C:\Documents and Settings\User\Desktop\stock>

25. Corba program for bank balance retrieval [Link] module BankApp { interface Bank { long bal(in long a); }; }; [Link] import BankApp.*; import [Link].*; import [Link].*; import [Link].*; import [Link].*;

import [Link]; import [Link].*; import [Link]; class BankImpl extends BankPOA { private ORB orb; public void setORB(ORB orb_val) { orb = orb_val; } public int bal(int a) { Connection con; PreparedStatement pt; ResultSet rs; int acc = a; int var1=0; try { [Link]("[Link]"); con=[Link]("Jdbc:Odbc:bank"); pt = [Link]("select bal from bankDB where acc=?"); [Link](1, acc); rs = [Link](); while ([Link]()) { var1 = [Link]("bal"); } } catch(ClassNotFoundException e){} catch(SQLException p){} return var1; } } public class BankServer { public static void main(String args[]) { try{ ORB orb = [Link](args, null); POA rootpoa =[Link](orb.resolve_initial_references("RootPOA")); rootpoa.the_POAManager().activate(); BankImpl bankImpl = new BankImpl(); [Link](orb); [Link] ref =rootpoa.servant_to_reference(bankImpl); Bank href = [Link](ref); [Link] objRef = orb.resolve_initial_references("NameService");

NamingContextExt ncRef = [Link](objRef); String name = "Bank"; NameComponent path[] = ncRef.to_name( name ); [Link](path, href); [Link]("BankServer ready and waiting ..."); [Link](); } catch (Exception e) { [Link]("ERROR: " + e); [Link]([Link]); } [Link]("BankServer Exiting ..."); } } [Link] import BankApp.*; import [Link].*; import [Link].*; import [Link].*; public class BankClient { static Bank bankImpl; public static void main(String args[]) { try{ ORB orb = [Link](args, null); [Link] objRef = orb.resolve_initial_references("NameService"); NamingContextExt ncRef = [Link](objRef); String name = "Bank"; bankImpl = [Link](ncRef.resolve_str(name)); [Link]("Obtained a handle on server object: " + bankImpl); int acc=123; [Link]("balance is: "+[Link](acc)); } catch (Exception e) { [Link]("ERROR : " + e) ; [Link]([Link]); } } }

Output: C:\Documents and Settings\User\Desktop\Bank>idlj -fall [Link] C:\Documents and Settings\User\Desktop\Bank>javac [Link] BankApp/*.java C:\Documents and Settings\User\Desktop\Bank>javac [Link] BankApp/*.java C:\Documents and Settings\User\Desktop\Bank>start orbd -ORBInitialPort 1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\Bank>start java BankServer -ORBInitialPort 1050 -ORBInitialHost localhost C:\Documents and Settings\User\Desktop\Bank> java BankClient -ORBInitialPort 1050 -ORBInitialHost localhost Obtained a handle on server object: IOR:000000000000001549444c3a42616e6b4170702f 42616e6b3a312e3000000000000000010000000000000082000102000000000a3132372e302e30 3100045700000031afabcb000000002098dabfb100000001000000000000000100000008526f6f7 504f41000000000800000001000000001400000000000002000000010000002000000000000100 00000002050100010001002000010109000000010001010000000026000000020002 balance is: 100000

You might also like