SDSU CS 596 Client-Server Programming
Corba, Patterns, and Stuff

[To Lecture Notes Index]
San Diego State University -- This page last updated May 14, 1996
----------

Contents of Corba, Patterns, and Stuff Lecture

  1. CORBA
  2. OpenDoc
  3. Tools
  4. What about C/C++ and Client-Server?

CORBA


Common Object Request Broker Architecture
"CORBA allows applications to communicate with one another no matter where they are located or who has designed them"


Java Corba "like" Implementations

Black Widow http://www.pomoco.com/
Sun (JOE and RMI) http://splash.javasoft.com/pages/intro.html
HORB http://www.isg.de/OEW/Java/

Object Management Group (OMG)

Responsible for CORBA standard

http://www.omg.org/
Very Simple Bank Example
From Black Widow Web Pageshttp://www.pomoco.com/

Bank
Contains balance which can be accessed

AccountManager
Used to provide access to bank account

Step 1 - IDL for classes

IDL = interface definition language
module Bank {

  interface Account {
    float balance();
  };

  interface AccountManager {
    Account open(in string name);
  };

};


Step 2

IDL to java compiler produces some java classes needed for CORBA


interface Bank.Account extends interface CORBA.Object 
interface Bank.AccountManager extends interface CORBA.Object 
class Bank._sk_Account implements interface Bank.Account 
class Bank._sk_AccountManager implements interface 
	Bank.AccountManager 
class Bank.Account_var 
class Bank.AccountManager_var 





Step 3 - Write Server CodeJava Server-Side Code


import java.util.*;

class Account extends Bank._sk_Account {

  private float _balance;

  Account(float balance) {
    _balance = balance;
  }

  public float balance() throws CORBA.SystemException {
    return _balance;
  }

}




More Server Code

class AccountManager extends Bank._sk_AccountManager {

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

  AccountManager(String name) {
    super(name);
  }

  public Bank.Account open(String name) throws 
										CORBA.SystemException {

    // Lookup the account in the account dictionary.
    Bank.Account account = ( Bank.Account ) _accounts.get( name );

    if(account == null) {

      // Create a new account with between 0 and 1000 dollars.
      float balance = Math.abs(_random.nextInt()) % 100000 / 100f;
      account = new Account(balance);
      System.out.println("Created " + name + "'s account: " + account);

      // Export the new object reference.
      CORBA.ORB.init().BOA_init().obj_is_ready(account);

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


The Server
public class Server {

  public static void main(String[] args) {

    try {
      // Initialize some CORBA Stuff
      CORBA.ORB orb = CORBA.ORB.init();
      CORBA.BOA boa = orb.BOA_init();

      // Create the account manager object.
      AccountManager manager = 
        new AccountManager("Post-Modern Bank");

      // Export the newly create object.
      boa.obj_is_ready(manager);
      System.out.println(manager + " is ready.");

      // Wait for incoming requests
      boa.impl_is_ready();
    }
    catch(CORBA.SystemException e) {
      System.err.println(e);
    }
  }
}

Step 4 - Write the Client


public class Client {

  public static void main(String args[]) {
    try {
      // Initialize the ORB.
      CORBA.ORB orb = CORBA.ORB.init();

      // Locate an account manager.
      Bank.AccountManager manager = 
        Bank.AccountManager_var.bind("Post-Modern Bank");

      // 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);
    }
    catch(CORBA.SystemException e) {
      System.err.println(e);
    }
  }
}


Step 5 Run Server and Client
prompt> java Client
The balance in Jack B. Quick's account is $71.62

prompt> java Client
The balance in Jack B. Quick's account is $71.62

prompt> java Client "Jack Sprat"
The balance in Jack Sprat's account is $322.38

prompt> java Client "Jack Sprat"
The balance in Jack Sprat's account is $322.38

prompt> java Client
The balance in Jack B. Quick's account is $71.62


OpenDoc


The end of applications?

Tools

Patterns in Client-Server

From New Clients with Old Servers: A Pattern Language for Client/Server Frameworks by Wolf and Liu in Pattern Languages of Program Design ed. by Coplien, Schmidt 1995, Addison-Welsey
Exception
Built-in to Java

Singleton
How to insure just one instance of a class

Objects From Records
Translate between flat relational rows of database to objects
Request
Request object encapsulates network interface: TCP/IP, remote procedure calls, etc.

Materialization
Move objects between server and client

Finalization
Need to some action when object dies
Identity Management
Program is likely to materialize multiple copes of same object
Mega-Scrolling (virtual lists)
List of items which is too large to transport to client at one time
Dependency ( Model-View, Observer )
Keep interface code (view) separate from rest of program (Model)
Factory
How to create a Client handler in Server class without changing the server class
How to create interface and keep interface information from model
Window-Keeping
Complex windows can take too long to create
Cache windows and reuse them
Client/Server Framework

What about C/C++ and Client-Server?


See previous two slides

----------