Você está na página 1de 15

Objects

• Object has
– Attributes (data or state)
– Methods

• Interface: Collection of methods to manipulate


state(s) of an object
– An object can have multiple interfaces
• DirectShow’s IMediaSeeking: for specify the location to play
back a video
• DirectShow’s IMediaControl: for play, pause, stop a video

– One interface definition can be implemented by


several objects

Tools/Environments for Supporting


Distributed Objects
• Commercial
– Java Remote Method Invocation (RMI) by Sun
– DCE by Open Source Foundation
– Common Object Request Broker Architecture (CORBA) by Object
Management Group (OMG)
• Open-source ORBs (e.g., TAO, JacORB, omniORB, MICO)
• BEA Tuxedo
• IONA Orbix
• Borland VisiBroker
• OIS ORB Express
– Distributed Component Object Model (DCOM) by Microsoft
– .NET Framework
– Java Enterprise Edition
• Academia
– Global Object-Based Environment (GLOBE) by Vrije et al. Universiteit
Amsterdam

1
Why Supporting Distributed
Objects?
• Object oriented paradigm
• Hide implementation details under object
interface (heterogeneity)
• Wrap procedures accessing legacy
systems as an object

Separation of interfaces and


objects is crucial
• Interface on one machine (client)
• Actual objects are on a different machine
(server)
– Object on the server has a similar interface as the
client
– In most systems, state of the object is not
distributed, but the methods are distributed in the
form of proxy
• Use object reference to refer to an object

2
+HOORLGO
LQWHUIDFH+HOOR^

VWULQJVD\+HOOR 

`

Object hides
implementation
From: http://java.sun.com/docs/books/tutorial/idl/hello/index.html
details, providing
transparency

2EMHFWFDQEHPRYHG

DURXQGRQGLIIHUHQW

VHUYHUVRQGLIIHUHQW

SODWIRUPV

From: http://www.molecular.com/news/recent_articles/051904_javaworld.aspx

• Proxy is equivalent to client stub in RPC; it provides


the same object interface as the server object
• Proxy marshalls method invocations into messages
and unmarshall the reply messages
• Skeleton is like a server stub in RPC

3
Method Call on Client Side
• Client application needs to get an object
reference first (say via naming service)
• Bind the object (load the proxy of the object in
the client’s address space)
• After binding, the method call can be invoked

• In general, distributed objects-based systems


provide systemwide object references so that
they can be passed on different machines

Object Server
• Object server manages objects
• Object server provides a means to invoke
local objects based on requests from
remote clients and to route the request to
objects
• Object server is as a place for objects to
live

4
Persistent and Transient
Objects
• Persistent Object: Object that is continued to
exist outside the server process’s address space
State of the object is stored on secondary storage
after the server manages the object exits

• Transient Object: The object exists as long as


the server that manages it exists
State of the object is not stored in the secondary
storage

Object Invocation at the Server


• One or more activation policy
– Policy for transient objects
• Create transient object when it is invoked for
the first time and destroy it when no clients
bound to it
• Or create all transient objects in the beginning

– Policy for objects’ code sharing


• Each object has memory segment of its own or share
code segment among objects of the same class

5
Object adaptor for implementing a
specific activation policy
• An object adaptor may be
responsible for one or more
objects

• Object adaptor is not aware


of interfaces implemented on
the object it controls

• Object skeleton provides


invoke() function for the
adaptor to call and pass the
message the adaptor
receives

• Skeleton does marshall and


unmarshall

Common Object Request Broker


Architecture (CORBA)
• Industry defined specifications for distributed
programming
• Drawn up by Object Management Group (OMG)
• CORBA supports distributed objects using a
remote-object model
– Implementation of objects resides in the server’s
address space
• Support interoperability

6
Overview of CORBA Architecture

• Each vender has its own extensions on the


implementation
• ORB—run time system that enables
communication between objects and their clients
while hiding issues related to distribution and
heterogeneity

CORBA Vertical Facilities


• CORBA Med: Specification for health care
industry
• CORBA Finance: Financial and
Accounting Services

7
CORBA Services
Service Description
Collection Facilities for grouping objects into lists, queue, sets, etc.
Query Facilities for querying collections of objects in a declarative manner
Concurrency Facilities to allow concurrent access to shared objects
Transaction Flat and nested transactions on method calls over multiple objects
Event Facilities for asynchronous communication through events
Notification Advanced facilities for event-based asynchronous communication
Externalization Facilities for marshaling and unmarshaling of objects
Life cycle Facilities for creation, deletion, copying, and moving of objects
Licensing Facilities for attaching a license to an object
Naming Facilities for systemwide name of objects
Property Facilities for associating (attribute, value) pairs with objects
Trading Facilities to publish and find the services on object has to offer
Persistence Facilities for persistently storing objects
Relationship Facilities for expressing relationships between objects
Security Mechanisms for secure channels, authorization, and auditing
Time Provides the current time within specified error margins

CORBA Interface Example

From: http://java.sun.com/docs/books/tutorial/idl/hello/index.html

Hello.idl

LQWHUIDFH+HOOR^

VWULQJVD\+HOOR 

`

From: http://www.molecular.com/news/recent_articles/051904_javaworld.aspx

8
Programming in CORBA
1. Create IDL using OMG IDL (CORBA IDL)
2. Use a language specific compiler to generate
IDL specific language code and other related
files
3. Develop the client program
4. Develop the server program

• Note: If writing a program using an existing CORBA


service, or a server for an existing client, you would get
the IDL interfaces from the implementer--such as a
service provider or vendor.

OMG IDL
• OMG IDL is purely declarative
– Provide syntax of interfaces

• Need a converter program that maps from


OMG IDL to one the languages (C, C++,
Smalltalk, COBOL, Ada, and Java)
– Ex: idltojava compiler maps OMG IDL to java
classes

9
Development Process for BEA
Tuxedo CORBA Applications

http://e-docs.bea.com/tuxedo/tux80/getstart/build.htm#1024964

CORBA client stub file (simple_c.cpp)


CORBA client stub header file (simple_c.h)
Skeleton file (simple_s.cpp)
Simple.idl Skeleton header file (simple_s.h)
Implementation file (simple_i.cpp)
// Simple object: Convert the case of string Implementation header file (simple_i.h)
interface Simple {
//Convert a string to lower case (return a new string) idl
string to_lower(in string val);
//Convert a string to upper case (in place)
void to_upper(inout string val);
};
idltojava
// create object reference to the Simple object
interface SimpleFactory {
Simple find_simple(); Base interface class file (interface.java )
}; CORBA client stub file (_interfaceStub.java)
Holder class file (interfaceHolder.java)
Java.Helper class file (interfaceHelper.java)

Factory object is a special object used to create other objects

10
Writing Server Application
• Write the methods that // Implementation of the Simple_i::to_lower method which converts
implement the operations // a string to lower case.
char* Simple_i::to_lower(const char* value)
for each interface {
CORBA::String_var var_lower = CORBA::string_dup(value);
• Create the CORBA object for (char* ptr = var_lower; ptr && *ptr; ptr++) {
*ptr = tolower(*ptr);
server }
return var_lower._retn();
• Define object activation }
policies // Implementation of the SimpleFactory_i::find_simple method which
• Create and register a // creates an object reference to a Simple object.

factory Simple_ptr SimpleFactory_i::find_simple()


{
• Release the CORBA CORBA::Object_var var_simple_oref =
TP::create_object_reference(
server application for _tc_Simple->id(),
"simple",
graceful shutdown CORBA::NVList::_nil()
);
}

Writing CORBA Client Application


int main(int argc, char* argv[])
{
try {
// Initialize the ORB
CORBA::ORB_var var_orb = CORBA::ORB_init(argc, argv, "");
1. Initialize ORB object // Create the Bootstrap object
Tobj_Bootstrap bootstrap(var_orb.in(), "");
2. Find SimpleFactory // Use the Bootstrap object to find the FactoryFinder
CORBA::Object_var var_factory_finder_oref =
interface bootstrap.resolve_initial_references("FactoryFinder");
// …
// Use the factory finder to find the Simple factory
3. Get reference to Simple CORBA::Object_var var_simple_factory_oref =
var_factory_finder_reference->find_one_factory_by_id(
_tc_SimpleFactory->id()
object );
// …
4. Invoke methods on the // Find the Simple object
Simple_var var_simple =
Simple object var_simple_factory_reference->find_simple();
// Get a string from the user
cout << "String?";
char mixed[256];
cin >> mixed;
// Convert the string to upper case :
CORBA::String_var var_upper = CORBA::string_dup(mixed);
var_simple->to_upper(var_upper.inout());
cout << var_upper.in() << endl;
// Convert the string to lower case
CORBA::String_var var_lower = var_simple->to_lower(mixed);
cout << var_lower.in() << endl;
return 0;
}
}

11
Object Model
• ORB provides few services through ORB interface
• Operations to marshall and unmarshall object references
• Getting object reference to an object implementing a specific
CORBA service

The general organization of a CORBA system.

Interoperability
Message type Originator Description
Request Client Contains an invocation request
Reply Server Contains the response to an invocation
LocateRequest Client Contains a request for the exact location of an object
LocateReply Server Contains location information on an object
CancelRequest Client Indicates client no longer expects a reply
CloseConnection Both Indication that connection will be closed
MessageError Both Contains information on an error
Fragment Both Part (fragment) of a larger message

Message types in GIOP

• General Inter-ORB Protocol (GIOP) assumes a transport protocol that is


reliable, connection oriented and support byte stream notion
• Internet Inter-ORB Protocol (IIOP) is GIOP built on TCP

12
GIOP Messages
• Request message contains a complete
marshaled invocation request (object reference,
name of the method, input parameters)
– Each request has request ID

• Reply message contains a marshaled return


values and output parameters
– Reply message has a corresponding request ID of the
request message

Portable Object Adaptor (1)


POA: Making server side code appears as
objects to clients
Servant: Part of an object that implements the
object method
•A wrapper of C functions operation on a
data structure
•An instance of a C++ class

CORBA POA provides a function to make this


class a CORBA object

13
Portable Object Adaptor (2)

My_servant *my_object; // Declare a reference to a C++ object


CORBA::Objectid_var oid; // Declare a CORBA identifier
my_object = new MyServant; // Create a new C++ object
oid = poa ->activate_object (my_object);
// Register C++ object as CORBA OBJECT

• Changing a C++ object into a CORBA object.

Different Approaches for POA

Mapping of CORBA object identifiers to servants of the same class


a) The POA supports multiple servants.
b) The POA supports a single servant.

14
Object References (1)
• The organization of an IOR with specific
information for IIOP

Security
information

IOR allows different ORB to pass object references

More with CORBA


• Naming Service
• Dynamic Object Invocation
• Real-time CORBA
• Reliable CORBA

• References:
– Tanenbaum V. Steen Distributed Systems Priciples and
Paradigms, Prentice Hall
– http://www.cs.wustl.edu/~schmidt/TAO.html

15

Você também pode gostar