|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.hebe.mps.Server
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.
Proxy
Inner Class Summary | |
private class |
Server.ConnectionThread
This class implements the body of the thread that is run for each client that connects to an MPS interface server. |
Field Summary | |
private java.net.InetAddress |
address
Address of the interface our server socket is bound to |
private static java.util.Hashtable |
allServers
Map used to associate an MPSIDL interface instance with an instance of class Server. |
private java.lang.String |
boundName
Machine-readable address of this object |
private java.util.Vector |
methodTable
Look-up-table mapping method number to method implementation. |
private boolean |
multiThreaded
Set to true if we are to serve access to our implementation object in a multithreaded way; set to false to serialize all accesses |
private java.lang.String |
objectName
Human-readable name for this object |
private int |
portNumber
TCP Port number we're listening on |
private java.net.ServerSocket |
serverSocket
Server socket that clients connect to us on. |
Constructor Summary | |
Server(java.lang.String objectName)
Create a new server named objectName. |
|
Server(java.lang.String objectName,
java.net.InetAddress address,
int portNumber)
Create a new server named objectName. |
|
Server(java.lang.String objectName,
int portNumber)
Create a new server named objectName. |
Method Summary | |
void |
dispatch(int index,
InputStream in,
OutputStream out)
Dispatches to a method on this MPS interface server. |
java.lang.String |
getBoundName()
Return the canonical name of this server. |
boolean |
getMultiThreaded()
Returns true if this server is running multithreaded. |
void |
registerMethod(int index,
java.lang.String name,
Thunk thunk)
Register a method-handler with the server. |
protected static void |
registerServer(java.lang.Object key,
Server svr)
Registers an instance of Server against the MPSIDL interface object that it is serving. |
void |
run()
The main body of the server thread. |
static Server |
serverFor(java.lang.Object key)
Retrieve the Server associated with a particular MPSIDL interface instance. |
void |
setMultiThreaded(boolean m)
Determines whether multiple threads (one thread per client connection, remember) may access methods on the implementation object simultaneously. |
private void |
setup()
Creates and starts the thread, once all the instance variables have been set up. |
private void |
setup(java.lang.String objectName,
java.net.InetAddress address,
int portNumber)
Performs all the steps needed to get the server started. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static java.util.Hashtable allServers
OutputStream.writeReference(java.lang.Object)
private java.lang.String objectName
private java.lang.String boundName
private java.net.ServerSocket serverSocket
private java.net.InetAddress address
private int portNumber
private boolean multiThreaded
setMultiThreaded(boolean)
private java.util.Vector methodTable
Thunk
,
dispatch(int, org.hebe.mps.InputStream, org.hebe.mps.OutputStream)
Constructor Detail |
public Server(java.lang.String objectName) throws MPSException
objectName
- human-readable name for this serverMPSException
- if anything goes wrong setting up the serverpublic Server(java.lang.String objectName, int portNumber) throws MPSException
objectName
- human-readable name for this serverportNumber
- the port to use to accept connections onMPSException
- if anything goes wrong setting up the serverpublic Server(java.lang.String objectName, java.net.InetAddress address, int portNumber) throws MPSException
objectName
- human-readable name for this serveraddress
- the InetAddress of the interface to bind toportNumber
- the port to use to accept connections onMPSException
- if anything goes wrong setting up the serverMethod Detail |
protected static void registerServer(java.lang.Object key, Server svr)
key
- the MPSIDL interface instance being servedsvr
- the server object we are registeringpublic static Server serverFor(java.lang.Object key)
key
- the MPSIDL interface instance we're interested inpublic java.lang.String getBoundName()
private void setup(java.lang.String objectName, java.net.InetAddress address, int portNumber) throws MPSException
objectName
- human-readable name for this serveraddress
- the InetAddress of the interface to bind to - null for INADDR_ANYportNumber
- the port to use to accept connections on - 0 for any unusedMPSException
- if anything goes wrong setting up the serverprivate void setup() throws MPSException
MPSException
- if the specified local socket address is already takenpublic boolean getMultiThreaded()
public void setMultiThreaded(boolean m)
synchronized
lock.m
- set to true to enable parallel access, or to false to enforce serial accesspublic void dispatch(int index, InputStream in, OutputStream out) throws MPSException
index
- the index of the method to callin
- the inputstream used by the method to read in parametersout
- the outputstream used by the method to return resultsMPSException
- if the method causes it to be raised,
or if the method index is out-of-rangepublic void registerMethod(int index, java.lang.String name, Thunk thunk)
index
- the method-index to use to register undername
- the name of the method - not currently used, but useful for debuggingthunk
- the object to call when the method is invokedpublic void run()
run
in interface java.lang.Runnable
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |