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

Variable Index

 o i
An InputStream from the server.
 o o
An OutputStream to the server.
 o registry
A Queue used to hold outgoing messages.

Constructor Index

 o GenericClient(String, int, String)
Creates a new GenericClient that connects to a GenericServer and attempts to register the chosen client name.

Method Index

 o closedown()
Closes down the server connection.
 o connect(String, int)
Connects to the specified server.
 o demux()
Routes incoming messages from the server to the appropriate tool.
 o deregister(String)
Deregisters the tool associated with a particular label.
 o logon(String)
Attempts to register the specified client name with the server.
 o register(String, Client)
Registers a tool for a particular multiplexing label.
 o run()
Transfers messages from the outbound Queue out to the server, and routes incoming messages from the server to the appropriate tool.

Variables

 o registry
  protected Hashtable registry
A Queue used to hold outgoing messages. . protected Queue q; /** The registry of tools.
 o i
  protected InputStream i
An InputStream from the server.
 o o
  protected OutputStream o
An OutputStream to the server.

Constructors

 o 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

Methods

 o 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.
 o 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.
 o 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
 o 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
 o closedown
  protected void closedown()
Closes down the server connection.

Closes the network connection and then deregisters all tools.

 o 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
 o 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