Contenu connexe
Similaire à CORBA/IDL: Enabling Distributed Object Communication
Similaire à CORBA/IDL: Enabling Distributed Object Communication (20)
CORBA/IDL: Enabling Distributed Object Communication
- 2. CORBA
• CORBA (Common Object Request Broker Architecture) is a set
of standards for middleware defined by the Object
Management Group (OMG), a consortium of over 500
companies, including IBM, Sun, Hewlett-Packard, Oracle,
Ford, Boeing and Xerox
• CORBA specifies standards for
- describing the interface that an application presents to the network
- mapping that interface into C++, Java, Visual Basic and many other languages
- using that network interface to communicate between programs
• There many implementations of the CORBA standard available
• The 3F6 laboratory experiment uses omniORB, a freely-
available version for C++ and Python. It supports over 15
different platforms, including Microsoft Windows, Mac OS X,
Linux, and most other forms of UniX
© 2012 Elena Punskaya
2
Cambridge University Engineering Department
2
- 3. 8 Object Request Broker
Engineering Part IIA: 3F6 - Software Engineering and Design
• The Object Request Broker (ORB)
Object Request Broker
- Enables communication between clients and objects
- Provides location transparency
- Provides accessObject Request Broker (ORB)
The to a set of built-in object services
eg 3F6 Lab PostIt Server eg NHS Medical Records
Application Domain
Interfaces
Interfaces
Object Request Broker (ORB)
Object
eg Name Server −→ Services
• There are two classes of interfaces
• enables communication between clients and objects
- Domain interfaces - standards agreed by collaborating organisations and registered
• provides location transparency
with the OMG
• provides developed for specific applications, interfaces are specific to
- Application interfaces - access to a set of built-in object services
each application
There are two classes of interfaces © 2012 Elena Punskaya
3
Cambridge University Engineering Department
3
- 4. Proxies in CORBA
Proxies in CORBA
Object-oriented programs consist of linked objects calling meth-
• Object-oriented programs consist of linked objects calling
ods on each other. For example, here object A is connected to
methods on B, and calling the For example, results in the method
object each other. method read on A here object A is
connected to object B, B:
open being called on
and calling the method read on A
results in the method open being called on B:
b
B* b; A B
// ...
+read() +open()
b-open();
• In a distributed application, we might want these objects to
live on different computers. This would make calling B::open
In a distributed application, we might want these objects to live
rather complex.
on different computers. This would make calling B::open rather
• CORBA provides a remote proxy mechanism which provides
complex.
the necessary location transparency.
CORBA provides a remote proxy mechanism which provides the
• It also makes programming simple by hiding the proxy class
necessary location transparency.
from the programmer. In C++, instead of using standard
pointer It also makes programming simple by hiding the proxy class from These
references, CORBA provides smart pointers.
hide the proxy class and provide built-in reference counting
the programmer. In C++, instead of using standard pointer
so that the remote objects can be automatically deallocated
references, CORBA provides smart pointers. These hide the
when no longer required.
proxy class and provide built-in reference counting so that the
© 2012 Elena Punskaya
remote objects can be automatically deallocated when no longer
Cambridge University Engineering Department
4
required. 4
- 5. Proxies in CORBA
• Using this design pattern, A
10 Engineering Part IIA: 3F6 - Software Engineering and Design
references B using a smart
Special version of B *b; pointer b (of type B_var)
the real thing • Method calls via b- are then
directed to the proxy for B
A B
When A calls open on the
B_var b;
// ...
•
b-open();
+read() +open()
B_Proxy object, this contacts
b
stub the local ORB, which
determines where the real B
Use my ORB B_Proxy
to contact object lives. The ORB then
the remote +open() makes a network connection
ORB to contact
the real B to the ORB on B’s computer
object and passes the request on to
ORB ORB it. The remote ORB then
Network
contacts the real B object,
which services the request.
Using this design pattern, A references B using a smart pointer b The results (any return
(of type B_var). values) are passed back to A
via the same mechanism
© 2012 Elena Punskaya
Method calls via b- are then directed to the proxy for B. Cambridge University Engineering Department
5
5
- 6. The Interface Definition Language
• CORBA provides a language independent mechanism for
specifying an object’s interface called the Interface Definition
Language (IDL)
• The basic structure of an IDL interface definition is as follows:
module ModName {
// define constants
const type ConstName = constant_expression;
// define types
typedef type Typename;
// define interfaces
interface ObjectName {
// define local consts and types
...
// define methods
returntype functionName(mode Typename arg, ...);
...
};
};
• mode (in, out, inout) is used to allow efficient transfer of
parameters over netwok, otherwise the IDL is very similar to C++
© 2012 Elena Punskaya
6
Cambridge University Engineering Department
6
- 7. IDL Type Specification
• IDL defines basic types such as short, float, char, string etc.
- the types have to be precisely defined to ensure compatibility with mixed programming
language environments
• Enumerations, fixed-size arrays and structures are supported
exactly as in C++
enum Colour {red, green, blue};
typedef short RGB[3];
struct Pixel {
RGB rgb;
short x; short y;
};
• The IDL does not support pointers. Instead it provides se-
quences which can be used to define variable length arrays
and recursive data structures
struct TreeNode {
string nodeContents;
sequenceTreeNode children;
};
© 2012 Elena Punskaya
7
Cambridge University Engineering Department
7
- 8. Interface Inheritance
• IDL interfaces also support inheritance
module People {
interface Person {
void init(in string name, in short age);
short getAge();
string getName();
};
// extending the Person interface
interface Child : Person {
void init(in string name, in short age,in string guardian);
string getGuardian();
};
};
• The derived interface Child redefines the init operation and adds a
new operation getGuardian while inheriting operations getAge and
getName
© 2012 Elena Punskaya
8
Cambridge University Engineering Department
8
- 9. Factories in CORBA
• Practically, a scalable system with multiple users needs to
have multiple instances of the objects providing the services
• A CORBA server typically follows the Factory design pattern to
create multiple objects
// define constants
module factory {
// define constants
interface Hello {
wstring helloWorld ();
};
// define constants
interface HelloFactory {
Hello create (in wstring message);
};
};
• HelloFactory is used to create new Hello objects. The Hello object
is just the simple object that returns a greeting String to the client.
In this example, the factory creates the object with a specified string
content http://docs.oracle.com/cd/F49540_01/DOC/java.815/a64683/appcorb1.htm
© 2012 Elena Punskaya
9
Cambridge University Engineering Department
9