Pascal's Weblog
The Grid...



Archives
« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today
Click me to subscribe
Search

Links
 

Today's Page Hits: 8

« SC'06 | Main | A Thread issue... »
Wednesday Dec 06, 2006
Remote and Serializable interfaces
Two interfaces are of utter importance to distributed programming in Java:

The Remote interface specifies that an object implementing this interface is an object in a different process (but of course it is technically possible to be in the same process), most likely on a different machine.
For example:
public interface ComputeServer extends Remote {
  public double integrate(String function, double min, double max) throws RemoteException;
}

Remote objects must implements this interface and extends the UnicastRemoteObject class:
public class ComputeServerImpl extends UnicastRemoteObject implements ComputeServer {
  public double integrate(String function, double min, double max) throws RemoteException {
    ...
  }
}

All methods in a class implementing the Remote interface must throw the RemoteException (This exception will occurs if the network is down).
Notice the signature of the above method:
  public double integrate(String function, double min, double max) throws RemoteException {

Suppose now that you want to group the parameters to the function to integrate in an object:
class FunctionToIntegrate {
  String function;
  int min;
  int max;
}

and pass an object of this class such as:
  public double integrate(FunctionToIntegrate function);

to identicate and marshall the object over the wire (e.g, IP) it is necessary to have the object implement the Serializable interface:
class FunctionToIntegrate extends Serializable {
  ...
}

So, while you will typically pass a Serializable object in a remote call, is this possible to pass a Remote object? Yes! This is typically used when the server needs to call back the client such as:
public class ComputeServerImpl extends UnicastRemoteObject implements ComputeServer {
  public void integrate(String function, Remote callback) throws RemoteException {
    ...
  }
}

Suppose the computation takes a while. The above method returns right away, but calls back the client when the result is ready.

Posted at 12:01PM Dec 06, 2006 by Pascal Ledru in Java  |  Comments[0]

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed