server
Class RemoteServer

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--server.RemoteServer
All Implemented Interfaces:
java.rmi.Remote, RemoteServerInterface, java.io.Serializable

public class RemoteServer
extends java.rmi.server.UnicastRemoteObject
implements RemoteServerInterface

Class RemoteServer is a simple illustration of a remote server that uses RMI communication. The server provides three typical methods to a client: receiveClientInput, compute, and getServerOutput. These methods are described further in their respective method documentation.

The main method of the server accepts the name of the host on which the server will run. The host name is assumed to be in the domain csc.calpoly.edu. So, for example, running with the command-line argument of "waldorf" will set the server to run on "waldorf.csc.calpoly.edu".

See the example Client class for a description of how a client connects to this server and uses its services.

See Also:
Serialized Form

Field Summary
protected  ClientDataInterface clientData
          Local copy of client input for computing with
protected  int serverOutput
          Value computed by the server
protected static javax.swing.JTextField textField
          The text field that displays the received client data
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
RemoteServer()
          Construct this by calling the parent constructor.
 
Method Summary
 void compute()
          Perform some computation using the client input.
 java.lang.Object getServerOutput()
          Return computation results back to the client, when the client calls for it.
static void main(java.lang.String[] args)
          Get the hostname from command-line argument, exiting if there is none.
 void receiveClientInput(ClientDataInterface clientData)
          Receive some input from the client.
protected static void setupDisplay()
          Set up the display as a JFrame with a labeled text field.
protected static void setupServer(java.lang.String hostname)
          Perform necessary setup for remote execution.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

clientData

protected ClientDataInterface clientData
Local copy of client input for computing with

serverOutput

protected int serverOutput
Value computed by the server

textField

protected static javax.swing.JTextField textField
The text field that displays the received client data
Constructor Detail

RemoteServer

public RemoteServer()
             throws java.rmi.RemoteException
Construct this by calling the parent constructor.
Method Detail

receiveClientInput

public void receiveClientInput(ClientDataInterface clientData)
                        throws java.rmi.RemoteException
Receive some input from the client. Store a local copy for computation use. Also, display the data in the server's display window.
Specified by:
receiveClientInput in interface RemoteServerInterface

compute

public void compute()
             throws java.rmi.RemoteException
Perform some computation using the client input. In this case, we simply add 1 to the numeric input value.
Specified by:
compute in interface RemoteServerInterface

getServerOutput

public java.lang.Object getServerOutput()
                                 throws java.rmi.RemoteException
Return computation results back to the client, when the client calls for it.
Specified by:
getServerOutput in interface RemoteServerInterface

setupDisplay

protected static void setupDisplay()
Set up the display as a JFrame with a labeled text field.

setupServer

protected static void setupServer(java.lang.String hostname)
Perform necessary setup for remote execution. The serverName input is the fully-qualified server name, e.g., "waldorf.csc.calpoly.edu". The sever set up entails the following:
  1. Set up a Java security manager if there isn't one already running on the server machine.
  2. Allocate a remote server instance and bind it in the host's rmi registry. This makes the server available to requesting clients.
  3. Handle any exception that may occur during server binding. The most typical problems include that the server is not running or that the security policy is not met. The easiest way to avoid security policy problems is to use the most liberal policy possible (see the file ./java.policy.liberal).

main

public static void main(java.lang.String[] args)
Get the hostname from command-line argument, exiting if there is none. Then call the display and server setup methods and we're ready to accept client requests.