|
ComputeEngineImpl Security Policies ComputePi ComputeEngineClient Running the Example
| |
Here's an example, based on the example shown in the Java RMI Tutorial, at http://java.sun.com/docs/books/tutorial/rmi/index.html
.
We'll implement a simple Compute Server, which can accept anything that
implements a Task interface.
Here's the Task interface:
package rmi;
/**
* An Interface describing a task to be performed
*
* @author Bryan Higgs
*/
public interface Task<T>
{
T execute();
}
|
And here is the remote interface, ComputeEngine:
package rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
/**
* An RMI remote interface for a compute engine.
*
* @author Bryan Higgs
*/
public interface ComputeEngine extends Remote
{
/**
* Computes the specified task
* @param task the task to be performed.
*/
<T> T compute(Task<T> task) throws RemoteException;
}
|
Note how general this interface is:
- The ComputeEngine interface contains a
single method, compute().
- The compute() method accepts an argument
of type Task -- that is, any class that
implements that interface.
- The compute() method returns a Task.
|