principles of object-oriented software development hello (corba) universe

Post on 20-Dec-2015

226 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Principles of Object-Oriented Software Development

Hello (CORBA) Universe

Hello (CORBA) Universe

Introduction Interface The broker abstraction C++ Realization Java Realization Prolog Realization Configuration Conclusions

Hello (CORBA) Universe

• platform-independent

• language-independent

• server -- C++, Java, Prolog, ...

• client -- C++, Java, Prolog, ...

• 9 combinations -- test.sh

The Interface - IDL

module universe { universe.idl

interface world { world

void hello(); void ask(in string x); string tell(); oneway void halt(); };};

C++ Realization

• broker -- access to ORB and BOA

• client -- needs ORB only

• server -- needs access to BOA

• implementation -- world-srv.h world-srv.c

C++ broker -- class

class broker { broker.h public: broker(); void init(int& argc, char**& argv, int fl=0); 1 = client

int operator()(); to run the server char* ref(corba::object* x); object_to_string corba::object* ref(const char* s); string_to object corba::object* object(const char* file); get object IOR file void refout(const char* f, corba::object* x); IOR to file };

C++ broker -- implementation

broker::broker() { } broker.c

void broker::init(int& argc, char**& argv, int fl=0) { _orb = CORBA_ORB_init(argc, argv); if (!fl) _boa = _orb -> BOA_init(argc, argv); } } int broker::operator()() { _boa -> impl_is_ready(CORBA_ImplementationDef::_nil()); }

int main(int argc, char* argv[], char*[]) { client.c broker* _broker = new broker(); get yourself a broker try { _broker->init(argc,argv); initialize broker

corba::object* obj = _broker->object("world.ref"); universe_world_var world = universe_world::_narrow(obj); { some object invocations world -> hello(); world -> ask("How are Clinton's affairs?"); cout << "client:" << world->tell() << endl; } } catch(corba::exception ex) { ... } }

int main(int argc, char* argv[], char*[]) server.c { broker* _broker = new broker(); get yourself a broker try { _broker->init(argc,argv); initialize orb and boa

universe_world_var p = new universe_world_srv; _broker->refout("world.ref", p); write identity

_broker->operator()(); run the the world

} catch(corba::exception& ex) { ... } }

void universe_world_srv::hello() { world_srv.c cout << "Hello World!" << endl; } void universe_world_srv::ask(const char* s) { cout << "Asking: " << s << endl; } char* universe_world_srv::tell() { char result[] = "ok"; CORBA_String_var s = (const char*) result; return s._retn(); } void universe_world_srv::halt() { exit(0); }

Java Realization

• broker -- contact ORB and BOA

• client -- connect to server

• server -- announce server object

• implementation -- world_srv.java

import org.omg.CORBA.*; broker.java

import java.io.*; public class broker { boolean _fl = false; java.applet.Applet _applet = null; public broker() { } public broker(boolean fl) { _fl = fl; } public broker(java.applet.Applet x) { _applet = x; init(null); }

public void init(String[] args) { if (_applet == null) { _orb = ORB.init(args,new java.util.Properties()); if (!_fl) _boa = _orb.BOA_init(args,new java.util.Properties()); } else _orb = ORB.init(_applet, null); } public int operator() { run -- server-only

if (!_fl) _boa.impl_is_ready(null); return 0; // OK } .... }; Java -- broker

package universe; import org.omg.CORBA.*; client.java import java.io.*; import hush.broker; see broker.java

public class client { public static void main(String args[]) { broker _broker = new broker(true); // true means client only try { _broker.init(args); init orb org.omg.CORBA.Object obj = _broker.object("world.ref"); world world = worldHelper.narrow(obj); if (world == null) throw new RuntimeException(); System.out.println("Enter 'h' for hello or 'x' for exit:"); ... // do some requests to the world } catch(...) { ... } } };

package universe; server.java import org.omg.CORBA.*; import java.io.*; import hush.broker; // see broker.java public class server { public static void main(String args[]) { broker _broker = new broker(); try { _broker.init(args); create orb en boa; world_srv p = new world_srv(); create impl object _broker.refout("world.ref",p); write ref

// create world.htm _broker.html("world.htm",p, " code=universe/applet.class " + "width=500 height=300"); _broker.operator(); // run == boa.impl_is_ready(null); } catch(SystemException ex) { _broker.print(ex); System.exit(1); } System.exit(0); } }

Java -- server

package universe; world_srv.java import org.omg.CORBA.*; public class world_srv extends _worldImplBase { public void hello() { System.out.println("Hello World!"); } public void ask(String msg) { System.out.println(msg); } public String tell() { String s = new String("ok"); return s; } public void halt() { System.exit(0); }

Prolog Realization

• broker -- mediating service

• client -- get object reference

• server -- provide implementation

• implementation -- universe.pl

broker(client(M:F)) :- broker.pl

... corba_initialize_orb([], _), factory(F). gives a handle to the server object

broker(server(M:I)) :- ... corba_initialize_server([server,server(test), timeout(infinite)],Server), ... create server object

G =.. [_Create,_Server,Self], call(G), corba_object_to_string(Self,IOR), open(IORFile,write,Fd), write reference to file format(Fd,'string',[IOR]), close(Fd), corba_main_loop(Server). enter main loop

Prolog -- broker

client.pl

:- use_module(universe). see universe.pl

:- [broker]. include broker

main :- broker(client(universe:F)), initialize the broker assert(client(factory(F))), run. run :- h, ask('What is the state of Clinton s affairs?'), write('Type h to say hallo, x to quit.'),nl.

ask(X) :- client(factory(F)), write(client(ask(X))),nl, world_ask(F,X), world_tell(F,R), write(client(ans(R))),nl. h :- client(factory(F)), world_hello(F). q :- client(factory(F)), world_halt(F), halt. x :- halt.

Prolog -- client

:- [broker]. server.pl

main :- broker(server(universe:world)).

Prolog -- server

:- module('universe',[]). universe.pl

world_hello(_Self) :- write('Hello World'),nl. world_ask(_Self, X) :- write(asking(X)), nl. world_tell(_Self,Y) :- Y = 'logically, ok', write(telling(Y)),nl. world_halt(_Self) :- halt.

Prolog -- implementation

Configure, make and test

• Makefile

• corba.cfg

• test.sh

Conclusions

• CORBA is ripe to be exploited in OO -- the practicum

• the broker is a useful abstraction

• forget about the wiring - concentrate on application logic

Idioms and Patterns

Introduction

Polymorphism Idioms in hush A catalogue of design patterns Event-driven computation

Summary Q/A Literature

Summary

Questions1.How would you characterize OOP and what, in your opinion, is the motivation underlying the introduction of OOP? 2.Characterize the most important features of OOP. 3.Explain the meaning of the phrase "object orientation reduces the complexity of programming." 4.How would you characterize contracts? Why are contracts important? 5.How is OOP related to programming languages? 6.What classes of languages support OOP features? Explain. 7.What influence is an object-oriented approach said to have on the software life-cycle? What is your own opinion? Discuss the problem of maintenance. 8.How would you characterize software quality? 9.Mention a number of object-oriented programming languages, and give a brief characterization. 10.What do you see as the major challenges for research in object-orientation?

Further reading

Nowadays there are many books that may serve as a starting point for reading about OO. Dependent on your interest, you may look at [Surviving], which treats issues of OO project management, [Meyer97], which gives an extensive introduction to design by contract and programming in Eiffel, or [Fowler97], which gives a succinct introduction to UML. Alternatively, you may take one of the introductory programming books for Java, from which you will almost certainly learn something about OO as well.

top related