SDSU CS 696 Emerging Technologies: Distributed Objects
Spring Semester, 1998
Some RMI Patterns

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 18, Some RMI Patterns


References slide # 1
Client-Dispatcher-Server slide # 2
...Context slide # 2
...Structure slide # 3
...Dynamics slide # 4
...Variants slide # 5
...Consequences slide # 7
...Know Uses slide # 8
Proxy slide # 9
...Structure slide # 9
...Dynamics slide # 10
...Reasons for Object Proxies slide # 11

References


Pattern-Oriented Software: A System of Patterns, Buschman, Meunier, Rohnert, Sommerlad, Stal, 1996, pp 323-338 (Client-Dispacther-Server), pp 263-275 (Proxy)

Design Patterns: Elements of Reusable Object-Oriented Software, Gamma, Helm, Johnson, Vlissides, 1995, pp 207-218



Doc 18, Some RMI Patterns Slide # 2

Client-Dispatcher-Server

Context


A software system integrating a client with a set of distributed servers, with the servers running locally or distributed over a network

Problem
How to find the servers?

A client should be able to use a service independent of the location of the service provider (server)

The code implementing the functional core of a client should be separate from the code use to establish a connection with the server

Solution
Provide a dispatcher components to act as an intermediate layer between clients and servers


Doc 18, Some RMI Patterns Slide # 3

Structure


Client-Dispatcher-Server Structure


Doc 18, Some RMI Patterns Slide # 4

Dynamics

client-dispacther-server dynamics

Doc 18, Some RMI Patterns Slide # 5

Variants

Distributed Dispatchers

Each machine has its own dispatcher

When a client needs to connection to a server on a remote machine:

The client connections to its local dispatcher

The local dispatcher connects to the remote dispatcher

The remote dispatcher returns the server communication channel to the local dispatcher

The local dispatcher returns to server communication channel to the client

The client now uses the communication channel to interact with the remote server

Communication Managed by clients

The dispatcher returns the physical server location to the client

The client manages all the communication with the server including opening the communication channel


Doc 18, Some RMI Patterns Slide # 6
Variants Continued
Heterogeneous Communication

Different servers use different communication mechanisms

Sockets
Pipes

When a server registers itself with the dispatcher it specifies the communication mechanism it supports


Client-Dispatcher-Service

Clients request a service from the dispatcher

The dispatcher looks up all servers that provide that service and opens a communication channel to one of those servers


Doc 18, Some RMI Patterns Slide # 7

Consequences

Benefits

Servers can be added or modified without modifications to the dispatcher or clients

Servers can be dynamically migrated to other machines as long as a client is not connected to the server

Decisions about where and which servers are part of the system can be decided have start-up time or later

A new server can be activated on a different machine when there is a network or server failure

Liabilities

Sun's implementation of remote procedure calls (RPC)

Java's RMI

OMG Corba


Doc 18, Some RMI Patterns Slide # 9

Proxy


proxy n. pl prox-ies The agency for a person who acts as a substitute for another person, authority to act for another

Structure

Proxy Structure

The Pattern

The proxy has the same interface as the original object

Use common interface (or abstract class) for both the proxy and original object

Proxy contains a reference to original object, so proxy can forward requests to the original object



Doc 18, Some RMI Patterns Slide # 10

Dynamics


Proxy Dynamics

Doc 18, Some RMI Patterns Slide # 11

Reasons for Object Proxies


Remote Proxy
The actual object is on a remote machine (remote address space)

Hide real details of accessing the object

Used in CORBA, Java RMI

RMI Proxy

public class HelloClient  {
     public static void main(String args[]) {
          try {
               String server = getHelloHostAddress( args);
               Hello proxy = (Hello) Naming.lookup( server );
               String message = proxy.sayHello();
               System.out.println( message );
          } 
          catch ( Exception error) 
               {  error.printStackTrace(); }
     }

Doc 18, Some RMI Patterns Slide # 12
Reasons for Object Proxies Continued

Virtual Proxy

Creates/accesses expensive objects on demand

You may wish to delay creating an expensive object until it is really accessed

It may be too expensive to keep entire state of the object in memory at one time
Protection Proxy
Provides different objects different level of access to original object

Cache Proxy (Server Proxy)
Multiple local clients can share results from expensive operations: remote accesses or long computations

Firewall Proxy

Protect local clients from outside world

Doc 18, Some RMI Patterns Slide # 13
Synchronization Proxy
Synchronize multiple accesses to real subject
public class Table {     
     public Object elementAt( int row, int column )
          { blah     }

     public void setElementAt(Object element, int row, int column )
          { blah}
}
     
public class RowLockTable {
     Table realTable;
     Integer[] locks;
     
     public RowLockTable( Table toLock) {
          realTable = toLock;
          locks = new String[ toLock.numberOfRows() ];
          for (int row = 0; row< toLock.numberOfRows(); row++ )
               locks[row] = new Integer(row);
          }
     
     public Object elementAt( int row, int column ) {
          synchronized ( locks[row] ) {
               return realTable.elementAt( row, column);
          }
     }

     public void setElementAt(Object element, int row,
                                              int column ){
          synchronized ( locks[row] )     {
               return realTable.setElementAt(element, row,
                                                   column);
          }
     }
}


Doc 18, Some RMI Patterns Slide # 14
Counting Proxy

Delete original object when there are no references to it

Prevent accidental deletion of real subject

Collect usage statistics

Sample use is making C++ pointer safe


visitors since 11-Mar-98