Class prominence.msg.GenericClient
All Packages Class Hierarchy This Package Previous Next Index
Class prominence.msg.GenericClient
java.lang.Object
|
+----java.lang.Thread
|
+----prominence.msg.GenericClient
- public class GenericClient
- extends Thread
A generic message streams-based client. Connects to a GenericServer
with a chosen client name, and supports dynamic registration of tools that
implement the Client interface. Tools communicate among each other
in a peer-to-peer manner through multiplexed streams.
- See Also:
- GenericServer, Client
-
i
- An InputStream from the server.
-
o
- An OutputStream to the server.
-
registry
- A Queue used to hold outgoing messages.
-
GenericClient(String, int, String)
- Creates a new GenericClient that connects to a
GenericServer and attempts to register the chosen
client name.
-
closedown()
- Closes down the server connection.
-
connect(String, int)
- Connects to the specified server.
-
demux()
- Routes incoming messages from the server to the appropriate tool.
-
deregister(String)
- Deregisters the tool associated with a particular label.
-
logon(String)
- Attempts to register the specified client name with the server.
-
register(String, Client)
- Registers a tool for a particular multiplexing label.
-
run()
- Transfers messages from the outbound Queue out to the server,
and routes incoming messages from the server to the appropriate tool.
registry
protected Hashtable registry
- A Queue used to hold outgoing messages.
.
protected Queue q;
/**
The registry of tools.
i
protected InputStream i
- An InputStream from the server.
o
protected OutputStream o
- An OutputStream to the server.
GenericClient
public GenericClient(String hostName,
int hostPort,
String name) throws IOException
- Creates a new GenericClient that connects to a
GenericServer and attempts to register the chosen
client name.
- Parameters:
- hostName - The name of the GenericServer host
- hostPort - The GenericServer port
- name - The client name
- Throws: IOException
- Occurs if the GenericServer could
not be contacted, or the client name is already in use.
- See Also:
- connect, logon
connect
protected void connect(String hostName,
int hostPort) throws IOException
- Connects to the specified server.
- Parameters:
- hostName - The server hostname
- hostPort - the server port
- Throws: IOException
- Occurs if the server could not be contacted.
logon
protected void logon(String name) throws IOException
- Attempts to register the specified client name with the server.
- Parameters:
- name - The client name
- Throws: IOException
- Occurs if there was a problem registering
or if the client name is already in use.
run
public void run()
- Transfers messages from the outbound Queue out to the server,
and routes incoming messages from the server to the appropriate tool.
This method is called when the superclass start() method
is called.
- Overrides:
- run in class Thread
- See Also:
- demux, start
demux
protected void demux() throws IOException
- Routes incoming messages from the server to the appropriate tool.
Strips the multiplexing header from each message, and routes the message
body to the appropriate tool currently registered in registry.
- Throws: IOException
- Occurs if there is a problem reading messages
from the server.
- See Also:
- Client
closedown
protected void closedown()
- Closes down the server connection.
Closes the network connection and then deregisters all tools.
register
public void register(String mx,
Client c)
- Registers a tool for a particular multiplexing label. Deregisters
any tool currently registered for the label.
Assigns the tool an appropriate MultiplexOutputStream
that is attached to messageO, so supports the targeted
send() methods and writes mesages to a message queue
pending delivery to the network.
- Parameters:
- mx - The multiplexing label
- c - The destination tool
deregister
public void deregister(String mx)
- Deregisters the tool associated with a particular label. Calls
the tool's disconnected() method and removes it from
registry.
- Parameters:
- mx - The multiplexing label that is to be deregistered
All Packages Class Hierarchy This Package Previous Next Index