Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members  

Server Class Reference

Implements all the code needed to get an implementation of an MPS interface running as an MPS server. More...

Inheritance diagram for Server:

Inheritance graph
[legend]
Collaboration diagram for Server:

Collaboration graph
[legend]
List of all members.

Private Methods

public Server (String objectName) throws MPSException
public Server (String objectName, int portNumber) throws MPSException
public Server (String objectName, InetAddress address, int portNumber) throws MPSException
public String getBoundName ()
private void setup (String objectName, InetAddress address, int portNumber) throws MPSException
private void setup () throws MPSException
public boolean getMultiThreaded ()
public void setMultiThreaded (boolean m)
public void dispatch (int index, InputStream in, OutputStream out) throws MPSException
public void registerMethod (int index, String name, Thunk thunk)
public void run ()

Private Attributes

private String objectName
private String boundName
private ServerSocket serverSocket
private InetAddress address
private int portNumber
private boolean multiThreaded = true
private Vector methodTable = new Vector()

Static Private Methods

protected void registerServer (Object key, Server svr)
public Server serverFor (Object key)

Static Private Attributes

private Hashtable allServers = new Hashtable()

Detailed Description

Implements all the code needed to get an implementation of an MPS interface running as an MPS server.

Pass in your desired objectName and an implementation of the correct interface to the automatically-generated subclasses of this class. It will spawn a thread that listens for connections to the server object.

Note that the implementation object is managed by subclasses of this class, and that this class knows nothing about the implementation of the MPS interface at all.

Author(s):
Tony Garnock-Jones <tonyg@kcbbs.gen.nz>
See also:
org.hebe.mps.Proxy

Definition at line 58 of file Server.java.


Constructor & Destructor Documentation

public Server::Server ( String objectName ) [inline, private]
 

Create a new server named objectName.

Bind to INADDR_ANY, on any unused port number.

Parameters:
objectName   human-readable name for this server
Exceptions:
MPSException   if anything goes wrong setting up the server

Definition at line 126 of file Server.java.

public Server::Server ( String objectName,
int portNumber ) [inline, private]
 

Create a new server named objectName.

Bind to INADDR_ANY, on the passed-in port number.

Parameters:
objectName   human-readable name for this server
portNumber   the port to use to accept connections on
Exceptions:
MPSException   if anything goes wrong setting up the server

Definition at line 138 of file Server.java.

public Server::Server ( String objectName,
InetAddress address,
int portNumber ) [inline, private]
 

Create a new server named objectName.

Bind to a specific interface, on the passed-in port number.

Parameters:
objectName   human-readable name for this server
address   the InetAddress of the interface to bind to
portNumber   the port to use to accept connections on
Exceptions:
MPSException   if anything goes wrong setting up the server

Definition at line 153 of file Server.java.


Member Function Documentation

public void Server::dispatch ( int index,
InputStream in,
OutputStream out ) [inline, private]
 

Dispatches to a method on this MPS interface server.

Parameters:
index   the index of the method to call
in   the inputstream used by the method to read in parameters
out   the outputstream used by the method to return results
Exceptions:
MPSException   if the method causes it to be raised, or if the method index is out-of-range

Definition at line 243 of file Server.java.

Referenced by Server::Runnable::run().

public String Server::getBoundName ( ) [inline, private]
 

Return the canonical name of this server.

Returns:
the string representation of the canonical name

Definition at line 164 of file Server.java.

Referenced by OutputStream::writeReference().

public boolean Server::getMultiThreaded ( ) [inline, private]
 

Returns true if this server is running multithreaded.

Returns:
the current multithreadedness of this server

Definition at line 217 of file Server.java.

Referenced by Server::Runnable::run().

public void Server::registerMethod ( int index,
String name,
Thunk thunk ) [inline, private]
 

Register a method-handler with the server.

Parameters:
index   the method-index to use to register under
name   the name of the method - not currently used, but useful for debugging
thunk   the object to call when the method is invoked

Definition at line 262 of file Server.java.

protected void Server::registerServer ( Object key,
Server svr ) [inline, static, private]
 

Registers an instance of Server against the MPSIDL interface object that it is serving.

The MPSIDL compiler emits calls to this method when compiling MPSIDL specifications down to java skeletons.

Parameters:
key   the MPSIDL interface instance being served
svr   the server object we are registering

Definition at line 76 of file Server.java.

public void Server::run ( ) [inline, private]
 

The main body of the server thread.

Definition at line 271 of file Server.java.

public Server Server::serverFor ( Object key ) [inline, static, private]
 

Retrieve the Server associated with a particular MPSIDL interface instance.

Parameters:
key   the MPSIDL interface instance we're interested in
Returns:
an instance of Server, or null if key is not being served

Definition at line 87 of file Server.java.

public void Server::setMultiThreaded ( boolean m ) [inline, private]
 

Determines whether multiple threads (one thread per client connection, remember) may access methods on the implementation object simultaneously.

If not, all dispatches to the implementation object go through a synchronized lock.

Parameters:
m   set to true to enable parallel access, or to false to enforce serial access

Definition at line 230 of file Server.java.

private void Server::setup ( ) [inline, private]
 

Creates and starts the thread, once all the instance variables have been set up.

Exceptions:
MPSException   if the specified local socket address is already taken

Definition at line 191 of file Server.java.

private void Server::setup ( String objectName,
InetAddress address,
int portNumber ) [inline, private]
 

Performs all the steps needed to get the server started.

Parameters:
objectName   human-readable name for this server
address   the InetAddress of the interface to bind to - null for INADDR_ANY
portNumber   the port to use to accept connections on - 0 for any unused
Exceptions:
MPSException   if anything goes wrong setting up the server

Definition at line 176 of file Server.java.


Member Data Documentation

private InetAddress Server::address [private]
 

Address of the interface our server socket is bound to.

Definition at line 101 of file Server.java.

private Hashtable Server::allServers = new Hashtable() [static, private]
 

Map used to associate an MPSIDL interface instance with an instance of class Server.

See also:
org.hebe.mps.OutputStreamwriteReference

Definition at line 65 of file Server.java.

private String Server::boundName [private]
 

Machine-readable address of this object.

Definition at line 96 of file Server.java.

private Vector Server::methodTable = new Vector() [private]
 

Look-up-table mapping method number to method implementation.

See also:
org.hebe.mps.Thunk , org.hebe.mps.Serverdispatch

Definition at line 118 of file Server.java.

private boolean Server::multiThreaded = true [private]
 

Set to true if we are to serve access to our implementation object in a multithreaded way; set to false to serialize all accesses.

See also:
org.hebe.mps.ServersetMultiThreaded

Definition at line 111 of file Server.java.

private String Server::objectName [private]
 

Human-readable name for this object.

Definition at line 94 of file Server.java.

private int Server::portNumber [private]
 

TCP Port number we're listening on.

Definition at line 103 of file Server.java.

private ServerSocket Server::serverSocket [private]
 

Server socket that clients connect to us on.

Definition at line 99 of file Server.java.


The documentation for this class was generated from the following file:
Generated at Wed Aug 15 01:05:35 2001 for mps-java by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001