SDSU CS 696 Emerging Technologies: Distributed Objects
Spring Semester, 1998
Binding and Finding Objects

To Lecture Notes Index
© 1998, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 21-Apr-98

Contents of Doc 24, Binding and Finding Objects

  1. References
  2. Some Overview
  3. Finding Objects - OrbixWeb Specific
    1. CORBA Object Reference
    2. OrbixWeb Object References
    3. Marker Example
    4. <type>Helper.bind and Finding Objects
      1. String markerServer
      2. Marker example
  4. Connecting Objects to the ORB
    1. OrbixWeb Method
    2. CORBA Method
  5. Accessing Objects via Object Reference Strings

References


OrbixWeb Programmer's Guide, IONA Technologies PLC, November 1997, chapter 8 Making Objects Available in OrbixWeb pp 173-209

OrbixWeb Programmer's Reference, IONA Technologies PLC, November 1997, Documentation on classes:
IE.Iona.OrbixWeb.CORBA.BOA
IE.Iona.OrbixWeb.CORBA.ORB
IE.Iona.OrbixWeb.CORBA.ObjectRef
IE.Iona.OrbixWeb._CORBA
IE.Iona.OrbixWeb._OrbixWeb
org.omg.CORBA.Object
org.omg.CORBA.ORB



Doc 24, Binding and Finding Objects Slide # 2
Steps in Creating a CORBA application
Define interface to object using IDL

Implement the server object using either TIE method or subclassing ImplBase

Writing a server for the objects

Registering the server

Write client
Some General Issues

Connecting to the orb

General interactions with the orb
What operations are available on the orb?
How do we find out about services?
Security issues


Specific issues
How do we connect implementation (server) objects to the orb for client use
How do clients find the objects


Doc 24, Binding and Finding Objects Slide # 3

Some Overview

Connecting Objects to the ORB

There are two methods of connecting implementation objects to the orb in OrbixWeb

Standard CORBA specified method
ORB.connect()
ORB.disconnect()

OrbixWeb specific method
_CORBA.Orbix.impl_is_ready
_CORBA.Orbix is an instance of the class IE.Iona.OrbixWeb.CORBA.BOA

Making Objects Available to Clients

There are three ways for clients to access objects

CORBA Naming Service

OrbixWeb specific Helper.bind()
This is an OrbixWeb specific alternative to the Naming Service

Using an Object Reference String

Doc 24, Binding and Finding Objects Slide # 4
Game plan

1. Cover OrbixWeb methods bind() and impl_is_ready

2. Cover OrbixWeb method bind() and ORB.connect()

3. Object Reference Strings

4. CORBA Naming Service


Doc 24, Binding and Finding Objects Slide # 5

Finding Objects - OrbixWeb Specific

CORBA Object Reference


Each CORBA object has an:
implementation
object reference

An object reference is the information needed to specify an object within an ORB

Both the client and object implementation are insulated from the underlying representation of the object reference

Different ORB implementations may differ in their choice of object reference representations


Doc 24, Binding and Finding Objects Slide # 6

OrbixWeb Object References


An OrbixWeb object reference is fully specified by:

Object Marker
The object marker is just a name or label
Is assigned by the programmer or
given default value by OrbixWeb (all digits)
The marker + an object's interface must be unique in a server
Two object's can have the same marker if they implement different interfaces
The marker cannot contain the character ':'

Server name
CORBA docs sometimes call this an implementation name

Server host machine

IDL interface name of the object

Interface Repository (IFR) server which stores the definition of the object's interface

IFR server host

Doc 24, Binding and Finding Objects Slide # 7

Marker Example

interface Greeter
   {
   string name();
   };
Inherited Implementation
class InheritedGreeter extends _GreeterImplBase  {
   protected String name;
   
   public InheritedGreeter( String name) {
      this.name = name;
   }

   public InheritedGreeter( String name, String marker) {
      super( marker );
      this.name = name;
   }
      
   public String name() { return name; }
}

TIE Implementation
class TieGreeter implements _GreeterOperations {
   protected String name;
   
   public TieGreeter( String name) {
      this.name = name;
   }
      
   public String name()    { return name; }
}

Doc 24, Binding and Finding Objects Slide # 8
The server
import IE.Iona.OrbixWeb._CORBA;
import IE.Iona.OrbixWeb.CORBA.ORB;

public class GreeterServer {
   public static void main (String args[]) {
      org.omg.CORBA.ORB orb =
         org.omg.CORBA.ORB.init();
      
      Greeter upTown = null;
      Greeter mountain = null;
         
      try {
         upTown = 
            new _tie_Greeter( new TieGreeter( "Upton"), "up");

         mountain = new InheritedGreeter( "Mike", "high");

         _CORBA.Orbix.impl_is_ready( "Visitor" );
         System.out.println("Server going Down");
      }
      catch ( org.omg.CORBA.SystemException corbaError) {
         System.out.println("Exception " + corbaError);
      }
   }
}

The server name is Visitor
Two objects in the server are connected,
one with marker up
one with marker high

Register the server with the command
   putit Visitor -java GreeterServer 


Doc 24, Binding and Finding Objects Slide # 9
The Client
import IE.Iona.OrbixWeb._CORBA;
import org.omg.CORBA.ORB;

public class GreeterClient
   {
   public static void main(String args[])
      {
      ORB.init();
      
      String hostname = "eli.sdsu.edu";
      Greeter serverObject;
      
      serverObject = GreeterHelper.bind(  ":Visitor", hostname);
      System.out.println(  ":Visitor\n" + serverObject.name() );
      
      serverObject = GreeterHelper.bind( "up:Visitor", hostname);
      System.out.println( "up:Visitor\n" + serverObject.name() );

      serverObject = GreeterHelper.bind( "high:Visitor", 
                                       hostname);
      System.out.println( "high:Visitor\n" + serverObject.name() );
      
      }
   }
Output
:Visitor
Upton
up:Visitor
Upton
High:Visitor
Mike

Doc 24, Binding and Finding Objects Slide # 10

<type>Helper.bind and Finding Objects


<type>Helper.bind is overloaded
public static final <type>  bind() 
public static final <type>  bind(String markerServer) 
public static final <type>  bind(String markerServer, String host) 
String host

The host string can be either a host name or host IP address

If the host string is not given the default locator will be used to find the host

The OrbixWeb configuration files must be properly set for the default locator to work properly

One can implement one's own locator


Doc 24, Binding and Finding Objects Slide # 11

String markerServer


Format:
marker:server_name

marker is the object marker of the object you are looking for
        GreeterHelper.bind( "up:Visitor", "eli.sdsu.edu");

will bind to the object that implements the Greeter interface with marker up in the server Visitor on host eli.sdsu.edu

If the marker is not give, it defaults to any object in the server which implements the interface, from which the helper class was generated from
        GreeterHelper.bind(  ":Visitor", "eli.sdsu.edu");

will bind to any object in the server Visitor on host eli.sdsu.edu that implements the Greeter interface


If the server_name is not given it defaults to the type of the Helper
        GreeterHelper.bind( "up:", "eli.sdsu.edu");
        GreeterHelper.bind( "up", "eli.sdsu.edu");
will bind to the object that implements the Greeter interface with marker up in the server Greeter on host eli.sdsu.edu


Doc 24, Binding and Finding Objects Slide # 12
String markerServer

If the markerServer is empty, then it defaults to the default server and any object implementing the correct interface
        GreeterHelper.bind( "", "eli.sdsu.edu");

will bind to an object that implements the Greeter interface in the server Greeter on host eli.sdsu.edu



If the markerServer has at least two ':' characters is assumed to be an Object Reference String from the native OrbixWeb protocol, (that is not IIOP)

Such a string must come from the object_to_string() method of the ORB

This will be covered later

Doc 24, Binding and Finding Objects Slide # 13
Assigning Markers and Name Collisions

When you assign a marker to an object, the object's marker + its interface must be unique in the server

If this is not the case, OrbixWeb will assign the object a different marker, a string of digits

You can check the actual name of a marker and change it if you need to


Doc 24, Binding and Finding Objects Slide # 14

Marker example

import IE.Iona.OrbixWeb._CORBA;
import IE.Iona.OrbixWeb.CORBA.ORB;
import IE.Iona.OrbixWeb.CORBA.ObjectRef;
import IE.Iona.OrbixWeb._OrbixWeb;

public class MarkerServer {
   public static void main (String args[]) {
      org.omg.CORBA.ORB orb =
         org.omg.CORBA.ORB.init();
      
      Greeter upTown = null;
      try {
         // no marker given
         upTown = new _tie_Greeter( new TieGreeter( "Upton"));
         
         // Get marker of uptown
         ObjectRef upTownRef = _OrbixWeb.Object( upTown );
         
         String marker = upTownRef._marker();
         System.out.println( "Marker name given by OrbixWeb " + 
               marker);
         
         upTownRef._marker( "up" );
         
         _CORBA.Orbix.impl_is_ready( "Greeter" );
         System.out.println("Server going Down");
      }
      catch ( org.omg.CORBA.SystemException corbaError)
         { System.out.println("Exception " + corbaError); }
   }
}

Output
Marker name given by OrbixWeb 0

Doc 24, Binding and Finding Objects Slide # 15

Connecting Objects to the ORB

OrbixWeb Method


In class IE.Iona.OrbixWeb.CORBA.BOA
public void impl_is_ready( );
public void impl_is_ready( String serverName );
public void impl_is_ready( int timeout);
public void impl_is_ready( String serverName, int timeout );

By default servers must be registered using putit before impl_is_ready() is called on the server

impl_is_ready() blocks until a timeout occurs or an exception occurs while processing an event

The timeout parameter indicates the number of milliseconds to wait between events (interaction with a client) before a timeout occurs

A timeout can occur because it has no clients for the timeout duration or because none of its clients uses it for the timeout duration

Use the setNoHangup() method to make the timeout active only when the server has no current clients

The default timeout is one minute

IE.Iona.OrbixWeb._CORBA.IT_INFINITE_TIMEOUT and
IE.Iona.OrbixWeb._CORBA.IT_DEFAULT_TIMEOUT can be used for timeout values

Doc 24, Binding and Finding Objects Slide # 16
Example
import IE.Iona.OrbixWeb._CORBA;
import IE.Iona.OrbixWeb.CORBA.ORB;
import IE.Iona.OrbixWeb._OrbixWeb;

public class ImplVariationsServer
   {
   public static void main (String args[])
      {
      org.omg.CORBA.ORB orb =
         org.omg.CORBA.ORB.init();
      
      Greeter upTown = null;
      try
         {
         upTown = 
            new _tie_Greeter( new TieGreeter( "Upton"), "up");
         
         _CORBA.Orbix.setNoHangup( true );
         _CORBA.Orbix.impl_is_ready( "Jack", 2000 );
         System.out.println("Server going Down");
         }
      catch ( org.omg.CORBA.SystemException corbaError)
         {
         System.out.println("Exception " + corbaError);
         }
      }
   }

Doc 24, Binding and Finding Objects Slide # 17
Connecting Objects to the ORB

CORBA Method


Call connect( serverObject ) on each object you wish to add to the server

Each call to connect creates a thread to process events on that object


When you determine that it is time to disconnect the server call disconnect( serverObject ) on each object in the server

The server will stop processing events and exit until all objects are disconnected

Clients get exceptions when trying to connect to disconnected objects while others are others are still connected

Nothing good happens when you call disconnect on an object that has an active client


Note: impl_is_ready is basically a wrapper around the connect- disconnect process

Doc 24, Binding and Finding Objects Slide # 18
Example using Connect-Disconnect
import IE.Iona.OrbixWeb._CORBA;
import IE.Iona.OrbixWeb.CORBA.ORB;

public class ImplVariationsServer
   {
   public static void main (String args[])
      {
      org.omg.CORBA.ORB orb =
         org.omg.CORBA.ORB.init();
      
      Greeter upTown = null;
      try
         {
         upTown = 
            new _tie_Greeter( new TieGreeter( "Upton"), "up");
         
         _CORBA.Orbix.setServerName( "Jack" );
         orb.connect( upTown );

         // put code here to determine when to continue
         // -> missing code


         // now disconnect
         orb.disconnect( upTown );
         System.out.println("Server going Down");
         }
      catch ( org.omg.CORBA.SystemException corbaError)
         {
         System.out.println("Exception " + corbaError);
         }
      }
   }


Doc 24, Binding and Finding Objects Slide # 19

Accessing Objects via Object Reference Strings


Each CORBA object has an object reference

The string version of that reference can be used to get an object reference

The string version is implementation dependent

OrbixWeb uses two different formats, one for each protocol supported by OrbixWeb: IIOP and native Orbix protocol

If you use IIOP (default) the object reference string is the interoperable object reference (IOR)

An example of an IOR:
IOR:000000000000001049444c3a477265657465723a312e300000000001000000000000004300100000000000d656c692e736473752e656475000007e1000000273a5c656c692e736473752e6564753a56697369746f723a75703a3a4946523a4772656574657200

In OrbixWeb the IOR is valid only for the life of the actual server object

If you use the native Orbix protocol you get a string of the following format:

:\server_host:server_name:marker:IFR_server:IDL_interface


Doc 24, Binding and Finding Objects Slide # 20
Example of Getting and Using Object reference Strings
import IE.Iona.OrbixWeb._CORBA;
import org.omg.CORBA.ORB;

public class ReferenceStringClient
   {
   public static void main(String args[])
      {
      ORB myOrb = ORB.init();
      
      String hostname = "eli.sdsu.edu";
      Greeter serverObject  = 
         GreeterHelper.bind( ":Visitor", hostname);
      
      String reference = myOrb.object_to_string( serverObject);
      
      org.omg.CORBA.Object fromString =
          myOrb.string_to_object( reference );
      
      // The CORBA way to cast
      Greeter newGreeter = GreeterHelper.narrow( fromString );
      System.out.println( "Narrowed Object: " + newGreeter.name() );
      
      // The following does not work with IIOP, should work with
      // Orbix native protocol
      //Greeter secondGreeter = 
            GreeterHelper.bind( reference, hostName );
      //System.out.println( "From bind: " + secondGreeter.name() );
      
      System.out.println( "The Object Reference:\n" + reference );
      }
   }
Output
Narrowed Object: Upton
The Object Reference:
IOR:000000000000001049444c3a477265657465723a312e300000000001000000000000004300010000000000d656c692e736473752e656475000007e1000000273a5c656c692e736473752e6564753a56697369746f723a75703a3a4946523a4772656574657200



visitors since 26-Mar-98