CORBA & JAVA

Download Report

Transcript CORBA & JAVA

CORBA & JAVA
A Good Partnership
For Distributed Computing
Agenda
•
•
•
•
•
•
•
•
•
CORBA Basics
IDL Features
IDL Example
Java’s IDL mapping
The ORB
Standard IIOP
Java Using CORBA
RMI IIOP
CORBA and EJB
CORBA Basics
-------------------Common Object Request Broker Architecture
It is a specification from the Object Management Group
that describes the infrastructure and architecture that
heterogeneous applications can use to communicate with
each other over networks.
Features:
1) Open Standard
2) Vendor Independent
Architecture Foundation:
1) IDL, Interface Definition Language (also OMG Spec)
2) ORB, Object Request Broker
3) Standard IIOP Protocol
CORBA Basics Continued
Transparency is a key notion to CORBA
1) Location - ability to invoke an object’s operations
without worrying about where that object is on the network
2) Program Language - the freedom to implement the
defined interface in the most appropriate language
Client
Stub Code
O
Object Implementation
R
B
Skeleton Code
IDL
Interface Definition Language
• Implementation independent
• Used to define the public interface for remote
capable objects
• Great for managing software component life
cycles
• Can provide access to multiple implementations
fulfilling the same interface.
• These interfaces can be extended by inheritance
• Is compiled into the Stub and Skeleton code that
provides the ORB communication code for client
and servant implementations
IDL Example
module katytrail {
module weather {
struct WeatherData {
float temp;
string wind_direction_and_speed;
float rain_expected;
float humidity;
};
typedef sequence<WeatherData> WeatherDataSeq
interface WeatherInfo {
WeatherData get_weather(
in string site
);
WeatherDataSeq find_by_temp(
in float temperature
);
};
IDL Example Cont.
interface WeatherCenter {
register_weather_for_site (
in string site,
in WeatherData site_data
);
};
};
};
Both interfaces will have Object Implementations.
A different type of Client will talk to each of the
interfaces.
The Object Implementations can be done in one
of two ways. Through Inheritance or through
a Tie.
IDL/Java Mapping
•
•
•
•
•
•
module
interface
struct
operation
basic types
sequence
•
•
•
•
•
•
package
interface
public final class
method
primitives
[] (array of)
The idl2java compiler will map the types on the left to the Java
types on the right. It also creates the directory structure based
on the packages created.
The Stub Code (used by Client Code) and the Skeleton Code
(used by the Object implementation Code) is also generated by the
idl2java compiler.
package katytrail.weather
package katytrail.weather
public interface WeatherInfo {
public final class WeatherData {
float temp;
public WeatherData get_weather(String site):
string wind_direction_and_speed;
float rain_expected;
public WeatherData[] find_by_temp(float temp);
float humidity;
}
};
package katytrail.weather
public interface WeatherCenter {
register_weather_for_site(String site, WeatherData data);
}
The ORB
• Is defined through IDL.
• It is the mechanism that handles all the
communication between remote objects and
their clients.
• Any object residing on a machine that wants
to make a CORBA call, must have an ORB
instance running on that machine.
Object Adapters
• The component that an object implementation uses
to make itself available for remote calls.
• The ORB uses the adapter to manage the run-time
environment of the object.
• Create and translate object references
• Activate and deactivate object implementations.
• Basic Object Adapter (BOA)
• Portable Object Adapter (POA)
Object Adapters Contined
BOA Example
Properties props = System.getProperties();
ORB orb = ORB.init(args,null);
BOA boa = orb.BOA_init();
MyObjectImpl myObj = new MyObjectImpl();
boa.obj_is_ready(myObj);
The BOA is very vague in its specification, therefore
it lends itself to very vendor specific implementations
Object Adapters Contined
BOA Client Example
Properties props = System.getProperties();
ORB orb = ORB.init(args,props);
org.omg.CORBA.Object obj =
orb.string_to_object(args[0]);
try {
WeatherInfo wInfo = WeatherInfoHelper.narrow(obj);
} catch (org.omg.CORBA.BAD_PARAM bp) {
}
WeatherData data = wInfo.get_weather(“Dutzow”);
System.out.println(“The weather in Dutzow is:”);
System.out.println(“Temperature: “+data.temp);
System.out.println(“Wind:“+
data.wind_direction_and_speed);
System.out.println(“Humidity: “+data.humidity);
Object Adapters Contined
POA Example
byte[] idForObj = {0, 0, 0, 1};
Properties props = System.getProperties();
ORB orb = ORB.init(args,props);
org.omg.PortableServer.POA poa=POAHelper.narrow(
orb.resolve_initial_references("RootPOA"));
objServant = new objPOATie(new ObjServant());
poa.activate_object_with_id(idForObj, objServant);
The POA provides a much more stringent specification,
therefore making implementations portable.
Object Adapters Contined
POA Example
WeatherData wData = new WeatherData();
wData.temp = 91.4;
wData.wind = “10SW”;
wData.humidity = 0.80;
wData.rain_expected = 0.01;
try {
Trader trader = TraderHelper.narrow (
orb.resolve_initial_references (“Trader_Blah”) );
OffersHolder offers = new OffersHolder();
trader.lookup(” WeatherCenter", "/prod", ”CEP",
LookUpPolicy.lookup_random.offers );
WeatherCenter wc = WeatherCenter.narrow(
(offers.value[0]).offer_ref);
wc.register_weather_for_site(“Dutzow”, wData);
} catch (Exception exc) {
}
Holder and Helper Classes
• These classes are generated by the IDL compiler
• Holder classes are used for out or in/out parameters in remote
interfaces.
– Marshals the object contents to the server
– Unmarshals the results, use the “value” attribute to get the data
• Helper classes allow a client to cast an object reference from the ORB
to one of the correct interface type.
– Read and write objects of the interface type to I/O streams
– Insert/Extract objects of this interface from/to an Any
IIOP
• Internet Inter-ORB Protocol
• An object oriented protocol that allows remote
applications to communicate via the Internet
• It is a mapping of GIOP, and uses the Internet’s
transport layer, Transmission Control Protocol
(TCP) to send requests and receive replies.
• Internet Protocol (IP) is used to create
Interoperable Object References (IORs)
RMI IIOP
• Integrates the top features of RMI with CORBA
• Java programmer is not forced to learn another
language (IDL)
• Any serializable object can be passed between
components (pass by value)
• IIOP is the communication protocol
• Can communicate with other language
implementations of components