Obtaining the CORBA IOR and connecting to the ZonePortal
It's all very well to talk to these CORBA objects floating around the network but how do you get your first one; how do you get into the system? The Quantel Broadcast System uses an Interoperable Object Reference (IOR) in a well known location. The IOR is nothing more, than just a series of characters making up a locator string. In the example below I've wrapped the lines but in real life this is just one line:
IOR:000000000000002349444C3A515F5175656E74696E2F515F496E7465726E616 C506F7274616C3A312E30000000000001000000000000006C000102000000000D31 302E3136322E35352E313400004E84000000143633383336313433392F0517230C1 F483E234623000000020000000000000008000000004A4143000000000100000020 0000000000010001000000010501000100010109000000020501000100010100
The IOR "string" is a formally serialised object that can be converted back to a real CORBA object. We can see the data contained in the IOR string by using the dior
command (decode IOR) from the JacORB bin folder we looked at in the Compiling the Quantel’s quentin.idl article:
cd D:\blog\jacorb-3.0rc1\bin dior -i IOR:00000000000...
Gives the output:
TypeId : IDL:Q_Quentin/Q_InternalPortal:1.0 TAG_INTERNET_IOP Profiles: Profile Id: 0 IIOP Version: 1.2 Host: 10.162.55.14 Port: 20100 Object key (URL): 638361439/%05%17%23%0C%1FH%3E%23F%23 Object key (hex): 0x36 33 38 33 36 31 34 33 39 2F 05 17 23 0C 1F 48 3E 23 46 23 -- Found 2 Tagged Components-- #0: TAG_ORB_TYPE Type: 1245790976 (JacORB) #1: TAG_CODE_SETS ForChar native code set Id: ISO8859_1 Char Conversion Code Sets: UTF8 ForWChar native code set Id: UTF16 WChar Conversion Code Sets: UTF8, UCS2
As you can see the IOR string contains all the information needed to talk to a particular object in the CORBA system. It includes everything from IP address and port number to protocol version and text encoding type.
Quantel has made it easy to obtain the IOR from the ISA Manager by delivering it through the built-in web server. The ISA Manager is a critical component to the Quantel Broadcast System. As a consequence there is an ISA Manager and an ISA Slave for fail-over and redundancy. Each ISA delivers the IOR of the manager so you don't have to worry about tracking which one of the ISAs is in control of the system.
For the largest part we don't really care what's is in IOR we just get it, convert it and make calls on it. So let's continue with that in mind and start with a simple client to read the IOR string from http://isa-manager/ZonePortal.ior
URL loc = new URL("http://10.162.55.14/ZoneManager.ior");
InputStream is = loc.openStream();
BufferedReader br = new BufferedReader (new InputStreamReader(is));
String ior = br.readLine();
br.close();
From the output of the dior
program (above) we can see the that underlying type of the IOR object is Q_Quentin/Q_InternalPortal:1.0
. However this is a bit useless because we don't have the interface definitions for that. We, as users, must be told that we can cast a Q_Quentin/Q_InternalPortal:1.0
into a Quentin/ZonePortal:1.0
.
Casting is a computer language term which means to take the same bit of memory where an object lives and treat it as a different type. It only works if the 2 types are related. In CORBA terms 2 classes might share the same interface but may be totally different classes. In this case CORBA coins the term narrowing to convert one type into another. It almost always requires a bit of extra knowledge that says that 2 items are related on an interface level: this is where the Object Request Broker (ORB) comes in.
The ORB knows about the relationships between the CORBA interfaces and will allow you to convert between them. Your local ORB will ask the remote ORB to do the narrowing for us because we might not have the full interface definitions, i.e. we have no way to find out what a Q_Quentin/Q_InternalPortal:1.0
is or how to convert it into a Quentin/ZonePortal:1.0
.
This part is somewhat CORBA implementation specific. In this example I'm using Java and JacORB but it would look similar if you were using a different implementation.
Setting up the CORBA sub-system is a bit like creating Sockets for network communications in that there are lots of options and documentation about those options but after going through all of it, you inevitably end up with the same couple of lines of code!
The CORBA interfaces are built into the Java Standard libraries so all we need to do is tell Java to use the JacORB implementation, which is simply a case of telling it which class to use. The args
and props
variables give you the opportunity to add extra configuration options from the command line and configuration files respectively.
Properties props = new java.util.Properties ();
props.setProperty ("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
props.setProperty ("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init (args, props);
Once the ORB is set up we can use it to narrow the IOR into a ZonePortal.
org.omg.CORBA.Object rawo = orb.string_to_object (ior);
ZonePortal portal = ZonePortalHelper.narrow (rawo);
Now that we have our very own ZonePortal we can test it with a simple get version call:
String x = portal.getProperty (PropertiesOperations.softwareVersion);
System.out.println ("This ISA Manager is version " + x);
So let's put it all together.
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Properties;
import com.quantel.quentin.PropertiesOperations;
import com.quantel.quentin.ZonePortal;
import com.quantel.quentin.ZonePortalHelper;
class OrbExample
{
static org.omg.CORBA.ORB orb;
static org.omg.PortableServer.POA poa;
public static void main (String[] args) throws Exception
{
// read ior
URL loc = new URL ("http://isa-manager/ZoneManager.ior");
InputStream is = loc.openStream ();
BufferedReader br = new BufferedReader (new InputStreamReader (is));
String ior = br.readLine ();
br.close ();
// Initialisation properties
Properties props = new java.util.Properties ();
props.setProperty ("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
props.setProperty ("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
// create orb
orb = org.omg.CORBA.ORB.init (args, props);
org.omg.CORBA.Object rawo = orb.string_to_object (ior);
ZonePortal portal = ZonePortalHelper.narrow (rawo);
String x = portal.getProperty (PropertiesOperations.softwareVersion);
System.out.println ("This ISA Manager is version " + x);
orb.shutdown(false);
}
}
No feedback yet
Form is loading...