CS 696 Emerging Technologies: Java Distributed Computing Spring Semester, 1999 Distributed Object Basics |
||
---|---|---|
© 1999, All Rights Reserved, SDSU & Roger Whitney San Diego State University -- This page last updated 02-Feb-99 |
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();
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.
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?
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
Structure
Dynamics
Variants
Distributed Dispatchers
Each machine has its own dispatcher
When a client needs to connection to a server on a remote machine:
Variants ContinuedHeterogeneous Communication
Different servers use different communication mechanisms
Consequences
Benefits
Know Uses
Sun’s implementation of remote procedure calls (RPC)
Java’s RMI
OMG Corba
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
Dynamics
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"; } }
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
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); } } }
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