the cast to istockmarket forces the microsoft jvm to call the dcom server object's queryinterface() function to request a pointer to istockmarket. if the interface is not supported, a classcastexception is thrown. reference counting is handled automatically in java/com and the microsoft jvm takes up the responsibility of calling iunknown::addref() and java's garbage collector automatically calls iunknown::release(). once the client acquires a valid pointer to the dcom server object, it calls into its methods as though it were a local object running in the client's address space.
corba client - the corba client will first have to initialize the corba orb by making a call to orb.init(). it then instantiates a corba server object by binding to a server object's remote reference. though both inprise's visibroker and iona's orbix have a bind() method to bind and obtain a server object reference like,
stockmarket market = stockmarkethelper.bind( orb ); // this is visibroker or orbix specific
we will use the corba naming service to do the same thing so that we are compatible with any orb. we first look up a nameservice and obtain a corba object reference. we use the returned corba.object to narrow down to a naming context.
namingcontext root = namingcontexthelper.narrow( orb.resolve_initial_references("nameservice") );
we now create a namecomponent and narrow down to the server object reference by resolving the name in the naming context that was returned to us by the cosnaming (corba object services - naming) helper classes.
namecomponent[] name = new namecomponent[1] ;
name[0] = new namecomponent("nasdaq","");
stockmarket market = stockmarkethelper.narrow(root.resolve(name));
once the client has acquired a valid remote object reference to the corba server object, it can call into the server object's methods as if the server object resided in the client's address space.
| dcom - client implementation | corba - client implementation | java/rmi - client implementation |
| // // // stockmarketclient // // import simplestocks.*; public class stockmarketclient { public static void main(string[] args) { try { istockmarket market = (istockmarket)new simplestocks.stockmarket(); system.out.println( "the price of my company is " + market.get_price("my_company") ); } catch (com.ms.com.comfailexception e) { system.out.println( "com exception:" ); system.out.println( e.gethresult() ); system.out.println( e.getmessage() ); } } } |
// // // stockmarketclient // // import org.omg.corba.*; import org.omg.cosnaming.*; import simplestocks.*; public class stockmarketclient { public static void main(string[] args) { try { orb orb = orb.init(); namingcontext root = namingcontexthelper.narrow( orb.resolve_initial_references("nameservice") ); namecomponent[] name = new namecomponent[1] ; name[0] = new namecomponent("nasdaq",""); stockmarket market = stockmarkethelper.narrow(root.resolve(name)); system.out.println("price of my company is " + market.get_price("my_company")); } catch( systemexception e ) { system.err.println( e ); } } } |
// // // stockmarketclient // // import java.rmi.*; import java.rmi.registry.*; import simplestocks.*; public class stockmarketclient { public static void main(string[] args)throws exception { if(system.getsecuritymanager() == null) { system.setsecuritymanager(new rmisecuritymanager()); } stockmarket market = (stockmarket)naming.lookup("rmi://localhost/nasdaq"); system.out.println( "the price of my company is " + market.get_price("my_company") ); } } |
| file : stockmarketclient.java | file : stockmarketclient.java | file : stockmarketclient.java |