SDSU CS 696 Emerging Technologies: Java Distributed Computing
Spring Semester, 1999
Distributed Object Basics
Previous    Lecture Notes Index    Next    
© 1999, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 02-Feb-99

Contents of Doc 5, Distributed Object Basics


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 (Proxy)

Doc 5, Distributed Object Basics Slide # 2

Basics in Distributed Object Programming


In classic client-server the server program listens on a fixed port. The client program connects to that port, and can then send messages (strings) to the server program. In distributed objects, the client object will send a method to the server object. The programmer does not deal with opening sockets and connecting to remote machines.

public class Foo {
   public String hello() { return "Hi there"; }
}
In client code:
We would like to interact with the remote object as if it were a local object. So we would like to do something like the following:

Foo remote = getRemoteObject();
String message = remote.hello();


Doc 5, Distributed Object Basics Slide # 3
Some Issues
How does the client find the server?
Network connections must be made but to where and by who?

How does the client object interact with the server object?
How can we send a method request across the network?

Parameter Issues

public class Foo {
   public String hello() { return "Hi there"; }
   public Vector sample( Vector input, int data ) {
      Integer remoteInt = new Integer( data );
      input.addElement( remoteInt );
      return input;
   }
}
When a method on a remote object has parameters, how are the parameters treated?

Solution 1. Send a copy of the parameters to the remote machine and remote object

How does one send a Vector across the network?

Solution 2. Don’t move the parameters, just send them messages remotely.


Doc 5, Distributed Object Basics Slide # 4
Garbage Collection issues

If a remote object creates an object for a client, how will the remote JVM know when it can garbage collect the object?

Network Issues

What happens when there is a problem with the network?

Doc 5, Distributed Object Basics Slide # 5

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 5, Distributed Object Basics Slide # 6

Structure





Doc 5, Distributed Object Basics Slide # 7

Dynamics



Doc 5, Distributed Object Basics Slide # 8

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 5, Distributed Object Basics Slide # 9
Variants ContinuedHeterogeneous 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 5, Distributed Object Basics Slide # 10

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




Doc 5, Distributed Object Basics Slide # 11

Know Uses


Sun’s implementation of remote procedure calls (RPC)

Java’s RMI

OMG Corba

Doc 5, Distributed Object Basics Slide # 12

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



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 5, Distributed Object Basics Slide # 13

Dynamics




Doc 5, Distributed Object Basics Slide # 14

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



public class Foo {
   public String hello() { return "Hi there"; }
}

Doc 5, Distributed Object Basics Slide # 15
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 5, Distributed Object Basics Slide # 16
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 5, Distributed Object Basics Slide # 17
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


Copyright ©, All rights reserved.
1999 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

Previous    visitors since 02-Feb-99    Next