CONTENT | PREV | NEXT

3 Common Object Request Broker Architecture (CORBA)

3.1 OMG / OMA

Open Management Group

Open Management Architecture

 
Open Management Architecture
 
 
CORBAservices
  • stellen grundlegende Operationen für Modellierung und Speicherung von Objekten
  • system level components
  • Bsp.: Naming, Events, Persistence, Transaction, Security, ...
CORBAfacilities
  • Sammlung von Klassen, die höherwertige Dienste zur Verfügung stellen
  • application level components
  • Bsp.: Druckdienste, Dokumentenmanagement, EMail, ...
CORBAdomains
  • branchenspezifische Klassen (vertikales Segment)
  • Bsp.: Klassen für Finanzwesen, medizinische Anwendungen, ...
Application Objects
  • eigentliche Anwendungsobjekte
 

3.2 Interface Definition Language (IDL)

 
IDL Typen
 

3.2.1 IDL to Java Mapping

 
IDL Construct Java Construct
module package
interface interface, helper class, holder class
constant public static final
boolean boolean
char, wchar char
octet byte
string, wstring java.lang.String
short, unsigned short short
long, unsigned long int
long long, unsigned long long long
float float
double double
enum, struct, union class
sequence, array array
exception class
readonly attribute method for accessing value of attribute (getter)
readwrite attribute methods for accessing and setting value of attribute (getter/setter)
operation method
 

3.2.2 Beispiel

 
module corbabase {  
   
    struct Person {  
   
        string name;  
        string firstName;  
        string eMail;  

    };  

    struct PersonVector {  
   
        sequence <Person> elements;  
   
    };  
   
    interface Server {  
   
        void store(in Person p);  
        void delete(in Person p);  
        PersonVector getAll();  
   
    };  
   
};

corbabase.idl
 

3.2.3 idltojava Compiler

3.3 Object Request Broker (ORB)

 
Object Request Broker
 

3.4 GIOP / IIOP

General Inter-ORB Protocol

Internet Inter-ORB Protocol

 
Interoperability

3.5 Step by step

  1. IDL Beschreibung des Remote Interfaces

  2.  
  3. idltojava Compilierung

  4.  
  5. Implementierung des Remote Objects

  6.  
    public class ServerImpl extends _ServerImplBase {  
       
        private Vector persons; //stores all datasets  
       
        public ServerImpl() {  
        
            super();  
            persons=new Vector();  
        
        }  
       
        public synchronized void store(Person p) {  
        
            //add person p to the database  
            //if p already exists update dataset  
            int pos=persons.indexOf(p);  
            if (pos == -1) {  
                persons.addElement(p);  
            } else {  
                persons.setElementAt(p,pos);  
            }  
        
        }  
        
        public synchronized void delete(Person p) {  
        
            //remove person p from the database  
            //if p does not exist do nothing  
            persons.removeElement(p);  
        
        }  
        
        public synchronized PersonVector getAll() {  
        
            //return a whole copy of the database  
            Person[] pElements=new Person[persons.size()];  
            for (int i=0; i<persons.size(); i++) {  
                pElements[i]=(Person)persons.elementAt(i);  
            }  
            return new PersonVector(pElements);  
        
        }  
       
    }
    corbabase/ServerImpl.java
     
  7. Registrierung des Remote Objects

  8.  
    public static void main(String[] args) {  
              
        try {  

            // create and initialize the ORB  
            ORB orb = ORB.init(args, null);  
       
            // create server and register it with the ORB  
            ServerImpl serverRef = new ServerImpl();  
            orb.connect(serverRef);  
       
            // get the root naming context  
            org.omg.CORBA.Object objRef =   
                orb.resolve_initial_references("NameService");  
            NamingContext ncRef = NamingContextHelper.narrow(objRef);  
       
            // bind the object reference in naming  
            NameComponent nc = new NameComponent("EMailBase", "");  
            NameComponent path[] = {nc};  
            ncRef.rebind(path, serverRef);  
       
            System.out.println("server started");  
                  
            // wait for invocations from clients  
            java.lang.Object sync = new java.lang.Object();  
            synchronized (sync) {  
                sync.wait();  
            }  
       
        } catch (Exception e) {  
            System.err.println(e.getMessage());  
        }    
       
    }

     
  9. Implementierung eines Clients

  10.  
    public class Client {  
       
        private Server serverRef; //remote reference to the server  
       
        public Client(Server serverRef) {  
        
            this.serverRef=serverRef;  
            ...  
        
        }  
       
        void store(String name, String firstName, String eMail) {  
        
            //create new person and store it  
            Person p=new Person(name,firstName,eMail);  
            serverRef.store(p);  

        }  
       
        void delete(String name, String firstName) {  
        
            //create person object for lookup  
            //and delete it  
            Person p=new Person(name,firstName,"");  
            serverRef.delete(p);  

        }  
       
        Vector getAll() {  
        
            //get all persons  
            PersonVector pElements=serverRef.getAll();  
            //transform  
            Vector persons=new Vector(pElements.elements.length);  
            for (int i=0; i<pElements.elements.length; i++) {  
                persons.addElement(pElements.elements[i]);  
            }  
            return persons;  
        
        }  
       
        public static void main(String[] args) {  
        
            try {  

                 // create and initialize the ORB  
                 ORB orb = ORB.init(args, null);  
       
                 // get the root naming context  
                 org.omg.CORBA.Object objRef =   
                     orb.resolve_initial_references("NameService");  
                 NamingContext ncRef = NamingContextHelper.narrow(objRef);  
       
                 // resolve the object reference in naming  
                 NameComponent nc = new NameComponent(args[0], "");  
                 NameComponent path[] = {nc};  
                 Server serverRef = ServerHelper.narrow(ncRef.resolve(path));    

                // start client  
                Client client=new Client(serverRef);  
        
            } catch (Exception e) {  
                System.out.println(e.getMessage());  
            }  
        
        }  
       
    }

    corbabase/Client.java
     
  11. Start des Naming Services (tnameserv)

  12.  
  13. Start des Servers

  14.  
  15. Start des Clients
 
© 1998 sven.buergel@informatik.tu-chemnitz.de
CONTENT | PREV | NEXT