gumbo.net.msg
Class MessageThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--gumbo.net.NetThread
              |
              +--gumbo.net.msg.MessageThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ClientThread, ServerThread

public abstract class MessageThread
extends NetThread

Abstract base class for network threads intended for messaging using Gumbo's message protocol (see Message). Includes a default message router with a ping responder.

Version:
$Revision: 1.1 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Field Summary
 
Fields inherited from class gumbo.net.NetThread
DEFAULT_PROXY_HOST, DEFAULT_PROXY_PORT, DEFAULT_SERVER_HOST, DEFAULT_SERVER_PORT
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
MessageThread(java.lang.String appName)
           
 
Method Summary
protected  void closeMessageReader()
          Closes the thread's dynamic message reader.
protected  void closeMessageWriter()
          Closes the thread's dynamic message writer.
 MessageReader getMessageReader()
          Gets the thread's dynamic message reader, which is set and updated at run time.
 MessageRouter getMessageRouter()
          Gets the thread's static message router, which is set at init time.
 MessageWriter getMessageWriter()
          Gets the thread's dynamic message writer, which is set and updated at run time.
protected  void implPleaseStop()
          Called by pleaseStop() after setting the stop flag true.
protected  MessageReader newMessageReader()
          Returns a new message reader for this thread's current client connection.
protected  MessageWriter newMessageWriter()
          Returns a new message writer for this thread's current client connection.
protected  void setMessageReader(MessageReader reader)
          Sets the thread's dynamic message reader.
protected  void setMessageWriter(MessageWriter writer)
          Sets the thread's message writer.
 void showPingStatus(java.awt.Component parent, MsgPingStatus msg)
          Shows a dialog with ping status information.
 
Methods inherited from class gumbo.net.NetThread
addNetThreadListener, autoRetryDelay, closeClientSocket, closeServerSocket, connectionReport, fireSocketConnect, fireSocketDisconnect, fireSocketFailure, fireThreadDone, fireThreadReady, getAppName, getAutoRetryDelay, getClientSocket, getDialogParent, getServerSocket, isServerThread, isStopping, pleaseStop, removeNetThreadListener, requestManualRetry, setAutoRetryDelay, setClientSocket, setDialogParent, setServerSocket, showRetryConnection, showRetryServer, socketReader, socketWriter, toHost, toHostport, toHostport, toHostport, toLocalHostport, toPort, toRemoteHostport, toServerHostport
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessageThread

public MessageThread(java.lang.String appName)
Parameters:
appName - Name of the app associated with this thread (for status messages). If null, a default is used.
Method Detail

getMessageRouter

public final MessageRouter getMessageRouter()
Gets the thread's static message router, which is set at init time. Never null.


getMessageReader

public final MessageReader getMessageReader()
Gets the thread's dynamic message reader, which is set and updated at run time. Null if none.


setMessageReader

protected final void setMessageReader(MessageReader reader)
Sets the thread's dynamic message reader. Null if none. Any old message reader will be closed.


closeMessageReader

protected final void closeMessageReader()
Closes the thread's dynamic message reader. If null or closed does nothing.


getMessageWriter

public final MessageWriter getMessageWriter()
Gets the thread's dynamic message writer, which is set and updated at run time. Null if none.


setMessageWriter

protected final void setMessageWriter(MessageWriter writer)
Sets the thread's message writer. Null if none. Any old message writer will be closed.


closeMessageWriter

protected final void closeMessageWriter()
Closes the thread's dynamic message writer. If null or closed does nothing.


showPingStatus

public void showPingStatus(java.awt.Component parent,
                           MsgPingStatus msg)
Shows a dialog with ping status information.

Parameters:
parent - Dialog parent component. Null if none.
msg - The ping status message. Never null.

newMessageReader

protected MessageReader newMessageReader()
                                  throws java.io.IOException
Returns a new message reader for this thread's current client connection. Never null. Called each time a new connection is made. The default is an object reader. Override to return an ASCII reader or for special handling, such as wrapping the reader in a filter or tee.

Note that on some systems the ObjectMessageWriter must be created for the socket before the ObjectMessageReader, otherwise the thread will hang. Also, a DataInputStream is used to wrap the socket to assure machine-independence.

java.io.IOException

newMessageWriter

protected MessageWriter newMessageWriter()
                                  throws java.io.IOException
Returns a new message writer for this thread's current client connection. Never null. Called each time a new connection is made. The default is an object writer. Override to return an ASCII writer or for special handling, such as wrapping the writer in a filter or tee.

Note that on some systems the ObjectMessageWriter must be created for the socket before the ObjectMessageReader, otherwise the thread will hang. Also, a DataOutputStream is used to wrap the socket to assure machine-independence.

java.io.IOException

implPleaseStop

protected void implPleaseStop()
Description copied from class: NetThread
Called by pleaseStop() after setting the stop flag true. Since the thread may be blocking on a read, subclasses should use this opportunity to close any open readers.

Specified by:
implPleaseStop in class NetThread