1 / 16

OOT Seminar H-97 CORBA

OOT Seminar H-97 CORBA. Praktisk del. Valg av ORB implementasjon. Har valgt å bruke Visigenic sin ORB implementsjon ORB’en er 100% Java kodet Bygger på OMG sin ”IDL to Java language mapping” fra Jun 97 Gratis prøveversjon i 1 mnd. ”Counter” eksempel.

Download Presentation

OOT Seminar H-97 CORBA

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OOT Seminar H-97 CORBA Praktisk del

  2. Valg av ORB implementasjon • Har valgt å bruke Visigenic sin ORB implementsjon • ORB’en er 100% Java kodet • Bygger på OMG sin ”IDL to Java language mapping” fra Jun 97 • Gratis prøveversjon i 1 mnd.

  3. ”Counter” eksempel • FormålBeregne gjennomsnittstiden det tar for en klient å utføre en metode på et serverobjekt.Eksempel hentet fra Client/Server Programming with Java and CORBARobert Orfali, Dan Harkey

  4. Ide / Tidlig klassediagram <<IDL Interface>> Count CountServer public int increment() { sum++; return sum; } // Increment 1000 times for (int i = 0 ; i < 1000 ; i++ ) { counter.increment(); } CountClient

  5. Interface Defenition Language • Count Interfacet nedfelt i IDL module Counter { interface Count { attribute long sum; long increment(); };}; <<IDL Interface>> Count sum : long increment( ) : long

  6. IDL til Java • Prekompilering idl2java count.idl • Produktet blir en ”Java Package” med navn Counter (navnet på modulen)

  7. Hva generer idl2java kompilatoren • Count.java • _sk_Count.java<->CountImplBase.java • CountHelper.java • CountHolder.java (leverer container obj) • _st_Count.java • _tie_Count.java • CountOperations.java

  8. Count.java • Interface til Count objekt package Counter; public interface Count extends org.omg.CORBA.Object { public void sum(int sum); public int sum(); public int increment(); } Count.java module Counter { interface Count { attribute long sum; long increment(); };}; Count.idl

  9. _st_Count.java • Java klasse for ”stub” kode • implementerer interface Count på klient siden • blir også kalt ”clientproxy” • denne klassen blir ikke direkte brukt av programmerere

  10. Klassediagram <<Interface>> Count CountImpl _sk_Count CountServer main( ) Server 1 1 Client 1..* 1..* CountClient main( )

  11. Implementasjon CountImpl class CountImpl extends Counter._sk_Count implements Counter.Count { private int sum; // Constructor CountImpl(String name) { super(name); System.out.println("Count Object Created"); sum = 0; } // get sum public int sum() throws org.omg.CORBA.SystemException { return sum; } // set sum public void sum(int val) throws org.omg.CORBA.SystemException { sum = val; } // increment method public int increment() throws org.omg.CORBA.SystemException { sum++; return sum; } }

  12. Imlementasjon CountServer // CountServer.java: The Count Server main program class CountServer { static public void main(String[] args) { try { // Initialize the ORB. org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(); // Initialize the BOA. org.omg.CORBA.BOA boa = orb.BOA_init(); // Create the Count object. CountImpl count = new CountImpl("My Count"); // Export to the ORB newly created object. boa.obj_is_ready(count); // Ready to service requests. boa.impl_is_ready(); } catch(org.omg.CORBA.SystemException e) { System.err.println(e); } } }

  13. Implementajson av CountClient // CountClient.java Static Client, VisiBroker for Java class CountClient { public static void main(String args[]) { try { // Initialize the ORB System.out.println("Initializing the ORB"); org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(); // Bind to the Count Object System.out.println("Binding to Count Object"); Counter.Count counter = Counter.CountHelper.bind(orb,"My Count");

  14. // Set sum to initial value of 0 System.out.println("Setting sum to 0"); counter.sum((int)0); // Calculate Start time long startTime = System.currentTimeMillis(); // Increment 1000 times System.out.println("Incrementing"); for (int i = 0 ; i < 1000 ; i++ ) { counter.increment(); } // Calculate stop time; print out statistics long stopTime = System.currentTimeMillis(); System.out.println("Avg Ping = " + ((stopTime - startTime)/1000f) + " msecs"); System.out.println("Sum = " + counter.sum()); } catch(org.omg.CORBA.SystemException e) { System.err.println("System Exception"); System.err.println(e); } } }

  15. Kjøring av eksempelet • Set CLASSPATH • Kompiler alle Java-klassene • Start: osagent (er en name service) • Start: java CountServer • Start: java CountClient

  16. Resultat av kjøringen > java CountServer Count Object Created > java CountClient Initializing the ORB Binding to Count Object Setting sum to 0 Incrementing Avg Ping = 5.28 msecs Sum = 1000

More Related