|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.rmi.server.RemoteObject
java.rmi.server.RemoteServer
java.rmi.server.UnicastRemoteObject
server.Server
public class Server
Class Server 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 two command-line arguments. The first argument is the name of the host computer on which the server runs. The hostname may be suffixed with a colon-delimited port number. If the port number is not present, the rmiregistry on the host is assumed to be running on the well-known port 1099. So, e.g., a legal hostname could be "waldorf.csc.calpoly.edu" or "waldorf.csc.calpoly.edu:1098", the latter selecting alternate registry port 1098.
The second command-line argument is an optional flag indicating if the server's GUI should be displayed when it runs. If the argument is missing, the default behavior is to display the GUI. If the second argument is "-nd", then no GUI display is shown. Using the "-nd" argument is useful when the server is run in a context where there is no support for a Java GUI display, for example, running the server on a UNIX machine like waldorf when logged into waldorf via telnet from a Windows PC.
See the example Client class for a description of how a client connects to this server and uses its services.
It is noteworthy in this example that all method calls are initiated from
the client. I.e., the computation is 100% client-driven. The server calls
This client-driven computation could be replaced with a server-driven form, where the server calls client's methods. Or there could be some combined form, e.g., the client performs a push of its input data, and the server responds with a push its output. Whether to use a client- or sever-driven form of computation depends on a number of factors, including where the end-user fits into the computation, which side should perform input data validity checking, and what security concerns there are. Details of these issues are beyond the scope of this example.
Field Summary | |
---|---|
protected ClientDataInterface |
clientData
Local copy of client input for computing with |
protected static boolean |
displayOn
True if the display is on, i.e., the 2nd command-line arg != "-nd" |
protected int |
serverOutput
Value computed by the server |
protected static javax.swing.JTextField |
textField
The text field that displays the received client data; received client data are printed to stdout instead of this text field if the GUI display is not active |
Fields inherited from class java.rmi.server.RemoteObject |
---|
ref |
Constructor Summary | |
---|---|
Server()
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 the command-line argument, exiting if there is none. |
void |
receiveClientInput(ClientDataInterface clientData)
Receive some input from the client. |
protected static void |
setupDisplay(java.lang.String hostname)
Set up the display as a JFrame with a labeled text field. |
protected static void |
setupServer(java.lang.String hostname)
Perform the 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 |
---|
protected ClientDataInterface clientData
protected int serverOutput
protected static javax.swing.JTextField textField
protected static boolean displayOn
Constructor Detail |
---|
public Server() throws java.rmi.RemoteException
java.rmi.RemoteException
Method Detail |
---|
public void receiveClientInput(ClientDataInterface clientData) throws java.rmi.RemoteException
receiveClientInput
in interface ServerInterface
java.rmi.RemoteException
public void compute() throws java.rmi.RemoteException
compute
in interface ServerInterface
java.rmi.RemoteException
public java.lang.Object getServerOutput() throws java.rmi.RemoteException
getServerOutput
in interface ServerInterface
java.rmi.RemoteException
protected static void setupDisplay(java.lang.String hostname)
protected static void setupServer(java.lang.String hostname)
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |