Oracle9i CORBA Developer's Guide and Reference
Release 1 (9.0.1)

Part Number A90187-01
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback

Go to previous page Go to next page

B
Comparing the Oracle9i and
VisiBroker VBJ ORBs

This appendix, which is for developers who are familiar with the VisiBroker VBJ ORB, summarizes the main differences between that ORB and the current version of the Oracle9i ORB. Each ORB supports multiple styles of usage, but this appendix compares only the most commonly used styles. In particular, it assumes that VBJ clients use the helper bind method to find objects by name, whereas Oracle9i clients use the JNDI lookup method for the same purpose. It also assumes that Oracle9i clients use Oracle's session IIOP to communicate with server objects, although the Oracle9i ORB also supports the standard IIOP used by the VBJ ORB.

The differences in the ORBs are summarized in these sections:

At the end of the appendix, equivalent client and server implementations of the same IDL for the VBJ and Oracle9i ORBs are provided for comparison.

Object References Have Session Lifetimes

The Oracle9i ORB creates object instances in database sessions. When a session disappears, references to objects created in that session become invalid: attempts to use them incur the "object does not exist" exception. A session disappears when the last client connection to the session is closed or the session's timeout value is reached. An object in a session can set the session timeout value with
oracle.aurora.net.Presentation.sessionTimeout()
optionally providing a client interface to this method, which a client can call if it wants an object to persist after client connections to the session are closed.

The life of a typical Oracle9i CORBA object proceeds as follows:

The Database Server Is the Implementation Mainline

An Oracle9i server object implementation consists of a single class. Developers do not write a mainline server, because the database server is the mainline. If the database is running, all implementations published in that database are available to clients. The database server dynamically assigns MTS threads to implementations. An implementation may multithread its own execution with Java threads.

Server Object Implementations Are Deployed by Loading and Publishing

Loading an object implementation into a database with the loadjava tool makes that implementation accessible to the ORB running in that database. Publishing a loaded implementation's name to a database's session name space with the publish tool makes the implementation accessible to clients by name. Every CORBA object implementation must be loaded, but only those whose names will be looked up by clients need to be published.

Implementation by Inheritance Is Nearly Identical

To implement the hypothetical interface Alpha in Oracle9i, write a class called AlphaImpl, which extends AlphaImplBase and defines the Java methods that implement the IDL operations. You may also provide instance initialization code in an _initializeAuroraObject method, which the Oracle ORB will call when it creates a new instance.

Implementation by Delegation Is Different

For an Oracle9i implementation by delegation (tie), the class you write extends a class you have defined and implements two Oracle-defined interfaces. The first interface, whose name is the IDL interface name concatenated with Operations, defines the methods corresponding to the IDL operations. The second interface, called ActivatableObject, defines a single method called _initializeAuroraObject(). To implement this method, create and return an instance. Here is a minimal example:

// IDL
module hello {
  interface Hello {
    wstring helloWorld ();
  };
};

// Oracle9i tie implementation
package helloServer;

import hello.*;
import oracle.aurora.AuroraServices.ActivatableObject;

public class HelloImpl implements HelloOperations, ActivatableObject 
//, extends <YourClass>
{
  public String helloWorld () {
    return "Hello World!";
  }

  public org.omg.CORBA.Object _initializeAuroraObject () {
    // create and initialize an instance and return it, for example ... 
    return new _tie_Hello (this);
  }
}

Clients Look Up Object Names with JNDI

An Oracle9i client can look up a published object by name, with CORBA COSNaming or with the simpler JNDI, which interacts with COSNaming in the client's behalf.

A client creates an initial JNDI context for a particular database with a Java constructor, for example:

Context ic = new InitialContext(env); 

The env parameter specifies user name and password under which the client is logging in. Because object implementations run in database servers, CORBA object users (through their clients) must identify and authenticate themselves to the database as they would for any database operation.

To obtain an instance of a published implementation, the client calls the JNDI context's lookup() method, passing a URL that names the target database and the published name of the desired object implementation. The lookup() call returns a reference to an instance in the target database. A client may pass the reference (perhaps in stringified form) to other clients, and the reference will remain valid as long as the session in which the associated object was created survives. Clients that use copies of the same object reference share the object's database session.

If a client executes lookup() twice in succession with the same parameters, the second object reference is identical to the first, that is, it refers to the instance created by the first lookup() call. However, if a client creates a second session and does the second lookup() in that session, a different instance is created and its reference returned.

No Interface or Implementation Repository

The current version of the Oracle9i ORB does not include an interface repository or an implementation repository.

The Bank Example in Oracle9i and VBJ

The following sections compare implementations of the bank example, widely used in VBJ documentation. Both client and server are shown as they would be implemented in Oracle9i and VBJ. All implementations use inheritance.

The Bank IDL Module

// Bank.idl

module Bank {
  interface Account {
    float balance();
  };
  interface AccountManager {
    Account open(in string name);
  };
};
		  

Oracle9i Client

// Client.java

import bankServer.*;
import Bank.*;

import oracle.aurora.jndi.sess_iiop.ServiceCtx;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;

public class Client
{
  public static void main (String[] args) throws Exception {

    String serviceURL = "sess_iiop://localhost:2222";
    String objectName = "/test/myBank";
    String username = "scott";
    String password = "tiger";
    
    Hashtable env = new Hashtable();
    env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi");
    env.put(Context.SECURITY_PRINCIPAL, username);
    env.put(Context.SECURITY_CREDENTIALS, password);
    env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN);

    Context ic = new InitialContext(env);

    AccountManager manager = 
      (AccountManager) ic.lookup(serviceURL + objectName);

    // use args[0] as the account name, or a default.
    String name = args.length == 1 ? args[0] : "Jack B. Quick";

    // Request the account manager to open a named account.
    Bank.Account account = manager.open(name);

    // Get the balance of the account.
    float balance = account.balance();

    // Print out the balance.
    System.out.println
      ("The balance in " + name + "`s account is $" + balance);
  }
}

VBJ Client

// Client.java

public class Client {

  public static void main(String[] args) {
    // Initialize the ORB.
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
    // Locate an account manager.
    Bank.AccountManager manager = 
      	Bank.AccountManagerHelper.bind(orb, "BankManager");
    // use args[0] as the account name, or a default.
    String name = args.length > 0 ? args[0] : "Jack B. Quick";
    // Request the account manager to open a named account.
    Bank.Account account = manager.open(name);
      // Get the balance of the account.
    float balance = account.balance();
    // Print out the balance.
    System.out.println
      ("The balance in " + name + "`s account is $" + balance);
  }

}

Oracle9i Account Implementation

// AccountImpl.java
package bankServer;

public class AccountImpl extends Bank._AccountImplBase {
  public AccountImpl(float balance) {
    _balance = balance;
  }
  public float balance() {
    return _balance;
  }
  private float _balance;
}

VBJ Account Implementation

// AccountImpl.java

public class AccountImpl extends Bank._AccountImplBase {
  public AccountImpl(float balance) {
    _balance = balance;
  }
  public float balance() {
    return _balance;
  }
  private float _balance;
}


Oracle9i Account Manager Implementation

// AccountManagerImpl.java
package bankServer;

import java.util.*;

public class AccountManagerImpl extends Bank._AccountManagerImplBase {

  public AccountManagerImpl() {
    super();
  }

  public AccountManagerImpl(String name) {
    super(name);
  }

  public synchronized Bank.Account open(String name) {
    // Lookup the account in the account dictionary.
    Bank.Account account = (Bank.Account) _accounts.get(name);
    // If there was no account in the dictionary, create one.
    if(account == null) {

      // Make up the account's balance, between 0 and 1000 dollars.
      float balance = Math.abs(_random.nextInt()) % 100000 / 100f;

      // Create the account implementation, given the balance.
      account = new AccountImpl(balance);

      _orb().connect (account);

      // Print out the new account.
      // This just goes to the system trace file for Oracle9i.
      System.out.println("Created " + name + "`s account: " + account);

      // Save the account in the account dictionary.
      _accounts.put(name, account);
    }
    // Return the account.
    return account;
  }

  private Dictionary _accounts = new Hashtable();
  private Random _random = new Random();

}

VBJ Account Manager Implementation

// AccountManagerImpl.java

import java.util.*;

public class AccountManagerImpl extends Bank._AccountManagerImplBase {
  public AccountManagerImpl(String name) {
    super(name);
  }
  public synchronized Bank.Account open(String name) {
    // Lookup the account in the account dictionary.
    Bank.Account account = (Bank.Account) _accounts.get(name);
    // If there was no account in the dictionary, create one.
    if(account == null) {
      // Make up the account's balance, between 0 and 1000 dollars.
      float balance = Math.abs(_random.nextInt()) % 100000 / 100f;
      // Create the account implementation, given the balance.
      account = new AccountImpl(balance);
      // Make the object available to the ORB.
      _boa().obj_is_ready(account);
      // Print out the new account.
      System.out.println("Created " + name + "`s account: " + account);
      // Save the account in the account dictionary.
      _accounts.put(name, account);
    }
    // Return the account.
    return account;
  }
  private Dictionary _accounts = new Hashtable();
  private Random _random = new Random();
}

VBJ Server Mainline

// Server.java


public class Server {

  public static void main(String[] args) {
    // Initialize the ORB.
    org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
    // Initialize the BOA.
    org.omg.CORBA.BOA boa = orb.BOA_init();
    // Create the account manager object.
    Bank.AccountManager manager = 
      new AccountManagerImpl("BankManager");
    // Export the newly created object.
    boa.obj_is_ready(manager);
    System.out.println(manager + " is ready.");
    // Wait for incoming requests
    boa.impl_is_ready();
  }

}

Go to previous page Go to next page
Oracle
Copyright © 1996-2001, Oracle Corporation.

All Rights Reserved.
Go To Documentation Library
Home
Go To Product List
Book List
Go To Table Of Contents
Contents
Go To Index
Index

Master Index

Feedback