|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--gumbo.net.NetThread
Abstract base class for network application threads (for clients, servers, and the client and server sides of proxy servers). Networking is via a socket with two-way asynchronous communication. Network resources (sockets, readers, writers) are dynamic, meaning that they are set and updated at run time. As such, clients should not hold references to them; instead, the client should reference the thread and get the a resource each time it is needed.
Except for dialogs, contains no GUI or Gumbo message dependencies. All status reporting is via event listeners.
Field Summary | |
static java.lang.String |
DEFAULT_PROXY_HOST
|
static int |
DEFAULT_PROXY_PORT
|
static java.lang.String |
DEFAULT_SERVER_HOST
|
static int |
DEFAULT_SERVER_PORT
|
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
NetThread(java.lang.String appName)
|
Method Summary | |
void |
addNetThreadListener(NetThreadListener listener)
Adds a net thread event listener. |
protected boolean |
autoRetryDelay()
Called by subclasses to implement auto retry delay. |
protected void |
closeClientSocket()
Closes this thread's dynamic client socket. |
protected void |
closeServerSocket()
Closes this thread's dynamic server socket, after first closing any client socket. |
static java.lang.String |
connectionReport(java.lang.String local,
java.lang.String remote,
java.net.Socket sock)
Utility for generating a connection report of the form " |
protected void |
fireSocketConnect(java.lang.String msg)
|
protected void |
fireSocketDisconnect(java.lang.String msg)
|
protected void |
fireSocketFailure(java.lang.String msg)
|
protected void |
fireThreadDone(java.lang.String msg)
|
protected void |
fireThreadReady(java.lang.String msg)
|
java.lang.String |
getAppName()
Gets the thread's application name (for status messages). |
long |
getAutoRetryDelay()
Gets the automatic retry delay, as set by setAutoRetry(). |
java.net.Socket |
getClientSocket()
Gets this thread's dynamic client socket, which is set and updated at run time. |
java.awt.Component |
getDialogParent()
Returns the parent GUI component for dialogs. |
java.net.ServerSocket |
getServerSocket()
Gets this thread's dynamic server socket, which is set and updated at run time. |
protected abstract void |
implPleaseStop()
Called by pleaseStop() after setting the stop flag true. |
abstract boolean |
isServerThread()
Returns true if this thread is a server. |
boolean |
isStopping()
Returns true if pleaseStop() has been called. |
void |
pleaseStop()
Gracefully stops this thread from running by setting a stop flag (see isStopping()). |
void |
removeNetThreadListener(NetThreadListener listener)
Removes a net thread event listener. |
protected void |
requestManualRetry()
Called by subclasses to force a manual retry next time autoRetryDelay() is called regardless of the auto delay setting. |
void |
setAutoRetryDelay(long delay)
Sets (and enables) automatic retry of the server socket or client connection after a specified delay. |
protected void |
setClientSocket(java.net.Socket clientSocket)
Sets this thread's dynamic client socket after closing any old one. |
void |
setDialogParent(java.awt.Component parent)
Sets the parent GUI component for dialogs. |
protected void |
setServerSocket(java.net.ServerSocket serverSocket)
Sets this thread's dynamic server socket after closing any old one. |
protected java.lang.String |
showRetryConnection(java.awt.Component parent,
java.lang.String msg,
java.lang.String hostport)
Called by subclasses to show a dialog warning the user that the server connection failed, and asking if the connection should be retried. |
protected int |
showRetryServer(java.awt.Component parent,
java.lang.String msg,
int port)
Called by subclasses to show a dialog warning the user that the server failed, and asking if the server should be retried. |
static java.io.Reader |
socketReader(java.net.Socket socket)
Wraps a buffered reader around a socket. |
static java.io.Writer |
socketWriter(java.net.Socket socket)
Wraps a buffered writer around a socket. |
static java.lang.String |
toHost(java.lang.String hostport)
Utility for getting the host from a hostport string. |
static java.lang.String |
toHostport(java.lang.String hostport)
Utility for translating a hostport string into the readable form "(none)" if it is null or empty. |
static java.lang.String |
toHostport(java.lang.String host,
int port)
Utility for converting a host name and port number into a hostport string. |
static java.lang.String |
toHostport(java.lang.String host,
java.lang.String portString)
Utility for converting a host name and port number into a hostport string. |
static java.lang.String |
toLocalHostport(java.net.Socket sock)
Utility for obtaining the local hostport from a socket. |
static int |
toPort(java.lang.String hostport)
Utility for getting the port from a hostport string. |
static java.lang.String |
toRemoteHostport(java.net.Socket sock)
Utility for obtaining the remote hostport from a socket. |
static java.lang.String |
toServerHostport(java.net.ServerSocket sock)
Utility for obtaining the server hostport from a server socket. |
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 |
Field Detail |
public static final java.lang.String DEFAULT_SERVER_HOST
public static final int DEFAULT_SERVER_PORT
public static final java.lang.String DEFAULT_PROXY_HOST
public static final int DEFAULT_PROXY_PORT
Constructor Detail |
public NetThread(java.lang.String appName)
appName
- Name of the app associated with this thread (for status
messages). If null, a default is used.Method Detail |
public void setDialogParent(java.awt.Component parent)
public java.awt.Component getDialogParent()
public final void setAutoRetryDelay(long delay)
delay
- The time delay between automatic retries, in milliseconds.
If negative, automatic retry is disabled and manual retry is enabled.public final long getAutoRetryDelay()
protected boolean autoRetryDelay()
protected void requestManualRetry()
public java.lang.String getAppName()
public abstract boolean isServerThread()
protected final void setServerSocket(java.net.ServerSocket serverSocket)
public final java.net.ServerSocket getServerSocket()
protected final void closeServerSocket()
protected final void setClientSocket(java.net.Socket clientSocket)
public final java.net.Socket getClientSocket()
protected final void closeClientSocket()
public final void pleaseStop()
protected abstract void implPleaseStop()
public final boolean isStopping()
public final void addNetThreadListener(NetThreadListener listener)
public final void removeNetThreadListener(NetThreadListener listener)
protected final void fireSocketConnect(java.lang.String msg)
protected final void fireSocketDisconnect(java.lang.String msg)
protected final void fireSocketFailure(java.lang.String msg)
protected final void fireThreadReady(java.lang.String msg)
protected final void fireThreadDone(java.lang.String msg)
protected java.lang.String showRetryConnection(java.awt.Component parent, java.lang.String msg, java.lang.String hostport)
parent
- Dialog parent component. Null if none.msg
- Explanatory message. If null, default message used.hostport
- Old "host:port". Ignored if null.
protected int showRetryServer(java.awt.Component parent, java.lang.String msg, int port)
parent
- Dialog parent component. Null if none.msg
- Explanatory message. If null, default message used.port
- Old server port number.
public static java.lang.String toHostport(java.lang.String host, int port)
host
- Host name. Empty if null.port
- Port number. Empty if negative.
public static java.lang.String toHostport(java.lang.String host, java.lang.String portString)
host
- Host name. Empty if null.portString
- Port number. Empty if null, empty, ill-formed, or
negative.
public static java.lang.String toHostport(java.lang.String hostport)
hostport
- Hostport string of the form "[host][:port]". Empty if null.
public static java.lang.String toServerHostport(java.net.ServerSocket sock)
public static java.lang.String toLocalHostport(java.net.Socket sock)
public static java.lang.String toRemoteHostport(java.net.Socket sock)
public static java.lang.String toHost(java.lang.String hostport)
hostport
- Hostport string of the form "[host][:port]". Empty if null.
public static int toPort(java.lang.String hostport)
hostport
- Hostport string of the form "[host][:port]". Empty if null.
public static java.lang.String connectionReport(java.lang.String local, java.lang.String remote, java.net.Socket sock)
local
- Local name (e.g. "client"). If null, defaults to "local".remote
- Remote name (e.g. "server"). If null, defaults to "remote".
public static java.io.Reader socketReader(java.net.Socket socket) throws java.io.IOException
socket
- Open socket. Never null.
java.io.IOException
public static java.io.Writer socketWriter(java.net.Socket socket) throws java.io.IOException
socket
- Open socket. Never null.
java.io.IOException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |