Class prominence.msg.GenericHandler
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class prominence.msg.GenericHandler

java.lang.Object
   |
   +----java.lang.Thread
           |
           +----prominence.msg.GenericHandler

public class GenericHandler
extends Thread
The client handler for a generic message streams-based server.

Accepts the client name from the GenericClient and attempts to register in the server routing table. If successful, then routes messages to other clients in the routing table.

See Also:
GenericServer

Variable Index

 o i
The InputStream from the client.
 o myself
Reference to a MessageOutput for this client.
 o name
The client name.
 o o
The OutputStream to the client.
 o routes
The server routing table.

Constructor Index

 o GenericHandler(Hashtable, InputStream, OutputStream)
Creates a new GenericHandler with a specified routing table and communication channel to the client.

Method Index

 o accept(String)
Attempts to register the client in the server routing table and informs the client of success.
 o broadcast(byte[])
Broadcasts a message body to all clients in the server routing table except the sender.
 o execute(Queue)
Starts a GenericMessageCopier that transfers messages from the client's outbound queue to the client, and then proceeds to route incoming messages from the client.
 o multicast(String[], byte[])
Multicasts a message body to the specified list of clients.
 o route()
Routes incoming messages from the client.
 o run()
Reads the client name, attempts to register in the server routing table, and if successful, proceeds to route messages to and from the client.
 o send(byte[], MessageOutput)
Sends a message body to a specified MessageOutput.

Variables

 o routes
  protected Hashtable routes
The server routing table.
 o i
  protected InputStream i
The InputStream from the client.
 o o
  protected OutputStream o
The OutputStream to the client.
 o name
  protected String name
The client name.
 o myself
  protected MessageOutput myself
Reference to a MessageOutput for this client.

Constructors

 o GenericHandler
  public GenericHandler(Hashtable routes,
                        InputStream i,
                        OutputStream o)
Creates a new GenericHandler with a specified routing table and communication channel to the client.
Parameters:
routes - The server routing table
i - An InputStream from the client
o - An OutputStream to the client

Methods

 o run
  public void run()
Reads the client name, attempts to register in the server routing table, and if successful, proceeds to route messages to and from the client.

This method is called by a new method when the superclass start() method is called.

Overrides:
run in class Thread
See Also:
accept, start
 o accept
  protected void accept(String name) throws IOException
Attempts to register the client in the server routing table and informs the client of success. If registered, proceeds to route messages to and from the client.

Registers a QueueOutputStream in the routing table that writes messages for the client into the client's outbound message queue.

Parameters:
name - The client name
Throws: IOException
Occurs if a problem is encountered communicating with the client.
See Also:
execute
 o execute
  protected void execute(Queue q) throws IOException
Starts a GenericMessageCopier that transfers messages from the client's outbound queue to the client, and then proceeds to route incoming messages from the client.
Parameters:
q - The client's outbound message queue
Throws: IOException
Occurs if a problem is encountered communicating with the client.
See Also:
GenericMessageCopier, route
 o route
  protected void route() throws IOException
Routes incoming messages from the client.

Removes the routing header attached by the sender from each message, and routes the message body into the appropriate outbound message queues.

Throws: IOException
Occurs if a problem is encountered reading from the client.
See Also:
broadcast, GenericHandler@multicast
 o broadcast
  protected void broadcast(byte buffer[]) throws IOException
Broadcasts a message body to all clients in the server routing table except the sender.
Parameters:
buffer - The message body to be broadcast
Throws: IOException
Should not occur.
See Also:
send
 o multicast
  protected void multicast(String dst[],
                           byte buffer[]) throws IOException
Multicasts a message body to the specified list of clients.
Parameters:
dst - An array of target client names
buffer - The message body to be multicast
Throws: IOException
Should not occur.
See Also:
send
 o send
  protected void send(byte buffer[],
                      MessageOutput o) throws IOException
Sends a message body to a specified MessageOutput. Does not send a message back to the sender or to null.
Throws: IOException
Should not occur; we are writing to a Queue.

All Packages  Class Hierarchy  This Package  Previous  Next  Index