ip1.ex14
Class JFtpThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--ip1.ex14.JFtpThread
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
JFtp, JFtpControl, JFtpData

public class JFtpThread
extends java.lang.Thread

A thread that has a message queue and children. This serves as the base for all of JFtp's threads. It provides mechanisms to push and pop messages to and from its message queue. It also provides support for the thread hierarchy as a JFtpThread has a parent (null for the top thread) and can have children. There is also support for displaying the running threads by assigning the threadTree member of the toplevel thread. Threads signal a change in their queue or their children to the toplevel thread and the thread view is updated recursively.

Version:
$Id: JFtpThread.java,v 1.18 2003/10/17 14:03:39 sharky Exp $
See Also:
JFtp, JFtpControl, JFtpData

Nested Class Summary
(package private)  class JFtpThread.QueueItem
          An item of the action queue.
 
Field Summary
protected  java.util.Vector children
          The thread's children.
protected static int counter
          Instance counter.
protected  int id
          This thread's id.
private  javax.swing.tree.DefaultMutableTreeNode idleNode
           
protected  javax.swing.tree.DefaultMutableTreeNode node
          The thread's node.
protected  JFtpThread parent
          The thread's parent.
protected  java.util.Vector queue
          The message queue.
 int state
          The thread's state.
static int STATE_EXITED
          The thread has exited.
static int STATE_NOTRUNNING
          The thread is not running.
static int STATE_SHUTDOWN
          We are shutting down.
protected  javax.swing.JTree threadTree
          An optional JTree for displaying the thread's queue and children.
protected  boolean threadTreeChanged
          Has the threadTree changed since the last refresh?
protected  java.lang.String type
          Type of thread.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
JFtpThread(JFtpThread parent, java.lang.String type)
          Shorter version of the constructor (not tree).
JFtpThread(JFtpThread parent, java.lang.String type, boolean withThreadTree)
          The constructor.
 
Method Summary
protected  void addChild(JFtpThread theThread)
          Add a child thread.
protected  JFtpThread.QueueItem addQueue(JFtpThread.QueueItem item)
          Queue a command.
protected  void debug(java.lang.String msg)
          Output a debugging message.
protected  void dumpQueue()
           
protected  JFtpThread getChild(int index)
          Return the requested child.
protected  JFtpThread getRoot()
          Return the root thread.
protected  boolean isBusy()
          Is this thread busy (that is are there messages in its queue)?
protected  JFtpThread.QueueItem peekQueue()
          Peek at the next item in the queue.
 void propagateTreeChange()
          Propagate a notice that the tree view needs a refresh.
protected  void queueShutdown()
          Queue a shutdown of the thread.
protected  JFtpThread.QueueItem readQueue()
          Read the next item in the queue.
protected  void refreshNode()
          Refresh the node representing this thread.
protected  void refreshThreadView()
          Update the thread view
protected  void removeChild(JFtpThread theThread)
          Remove a child thread then updates the toplevel thread view.
protected  void reset()
          Clear the thread's queue and kill all its children.
 void run()
          The run function, must be overriden to do anything useful.
protected  void shutdown()
          Perform a shutdown.
 java.lang.String toString()
          Convert to String representation.
protected  void waitShutdown(JFtpThread theThread)
          Wait for a thread to exit.
 
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, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE_NOTRUNNING

public static final int STATE_NOTRUNNING
The thread is not running.

See Also:
Constant Field Values

STATE_SHUTDOWN

public static final int STATE_SHUTDOWN
We are shutting down.

See Also:
Constant Field Values

STATE_EXITED

public static final int STATE_EXITED
The thread has exited.

See Also:
Constant Field Values

queue

protected java.util.Vector queue
The message queue.


children

protected java.util.Vector children
The thread's children.


parent

protected JFtpThread parent
The thread's parent. Set to null for the toplevel thread.


threadTree

protected javax.swing.JTree threadTree
An optional JTree for displaying the thread's queue and children.


threadTreeChanged

protected boolean threadTreeChanged
Has the threadTree changed since the last refresh?


type

protected java.lang.String type
Type of thread.


counter

protected static int counter
Instance counter.


id

protected int id
This thread's id.


state

public int state
The thread's state.


node

protected javax.swing.tree.DefaultMutableTreeNode node
The thread's node.


idleNode

private javax.swing.tree.DefaultMutableTreeNode idleNode
Constructor Detail

JFtpThread

public JFtpThread(JFtpThread parent,
                  java.lang.String type,
                  boolean withThreadTree)
The constructor.

Parameters:
parent - the parent thread, or null
type - type of this thread
withThreadTree - do we want a thread tree associated with this thread?

JFtpThread

public JFtpThread(JFtpThread parent,
                  java.lang.String type)
Shorter version of the constructor (not tree).

Parameters:
parent - the parent thread, or null
type - type of this thread
Method Detail

addChild

protected void addChild(JFtpThread theThread)
Add a child thread.

Parameters:
theThread - the thread to add

addQueue

protected JFtpThread.QueueItem addQueue(JFtpThread.QueueItem item)
Queue a command.

Parameters:
item - the command to queue

debug

protected void debug(java.lang.String msg)
Output a debugging message.

Parameters:
msg - the message to print

dumpQueue

protected void dumpQueue()

getChild

protected JFtpThread getChild(int index)
Return the requested child.


getRoot

protected JFtpThread getRoot()
Return the root thread.


isBusy

protected boolean isBusy()
Is this thread busy (that is are there messages in its queue)?


peekQueue

protected JFtpThread.QueueItem peekQueue()
Peek at the next item in the queue.


propagateTreeChange

public void propagateTreeChange()
Propagate a notice that the tree view needs a refresh.


queueShutdown

protected void queueShutdown()
Queue a shutdown of the thread.


readQueue

protected JFtpThread.QueueItem readQueue()
Read the next item in the queue.


refreshNode

protected void refreshNode()
Refresh the node representing this thread.


refreshThreadView

protected void refreshThreadView()
Update the thread view


removeChild

protected void removeChild(JFtpThread theThread)
Remove a child thread then updates the toplevel thread view.

Parameters:
theThread - the child to remove

reset

protected void reset()
Clear the thread's queue and kill all its children.


run

public void run()
The run function, must be overriden to do anything useful.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

shutdown

protected void shutdown()
Perform a shutdown. We kill all child processes then set the state to STATE_SHUTDOWN.


toString

public java.lang.String toString()
Convert to String representation.

Overrides:
toString in class java.lang.Thread

waitShutdown

protected void waitShutdown(JFtpThread theThread)
Wait for a thread to exit.

Parameters:
theThread - the thread to wait for