|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--net.vattp.data.ListenThread
Field Summary | |
private VatTPMgr |
myConnMgr
The VatTPMgr to report new Sockets to |
private ServerSocket |
myListenServerSocket
|
private InetAddress |
myOptIP
|
private boolean |
mySuspended
|
private boolean |
myTerminateFlag
|
private UserThread |
myUserThread
|
private Object |
myUserThreadLock
An object to synchronize communication with the user thread |
private Vat |
myVat
A vat for synchronization when calling the VatTPMgr |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
(package private) |
ListenThread(String optLocalAddr,
VatTPMgr connMgr,
Vat vat)
Construct a new object to run in its own thread and listen on a ServerSocket for new incoming connections. |
Method Summary | |
private void |
callMgr(DataCommThunk thunk)
Call a method in the VatTPMgr |
(package private) NetAddr |
listenAddress()
The address on which this thread is listening, or null if there was a problem |
private void |
noticeProblem(Throwable t)
|
void |
run()
The actual body of the listener thread. |
private void |
setupNewConnection(Socket clientSocket)
Create a new connection to handle the new socket. |
(package private) void |
shutdown()
Shutdown the thread. |
(package private) void |
startup()
Start the listener thread. |
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, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private boolean myTerminateFlag
private final UserThread myUserThread
private InetAddress myOptIP
private final ServerSocket myListenServerSocket
private VatTPMgr myConnMgr
private final Vat myVat
private final Object myUserThreadLock
private final boolean mySuspended
Constructor Detail |
ListenThread(String optLocalAddr, VatTPMgr connMgr, Vat vat) throws UnknownHostException, IOException
optLocalAddr
- The local address we will listen on.connMgr
- the VatTPMgr to be notified about
interesting events (new connections and errors) that happen while
listening.Method Detail |
private void callMgr(DataCommThunk thunk)
thunk
- a Thunk that will perform the call. The thunk will
be called after the Vat lock is obtained.private void noticeProblem(Throwable t)
NetAddr listenAddress()
public void run()
Opens a ServerSocket and accepts connections on it. Each connection spawns a new ByteConnection object that is handed off to the innerListener to be dealt with.
Loops until told to stop by somebody calling 'shutdown()' (which sets an internal flag).
run
in interface Runnable
run
in class Thread
java.lang.Thread#start()
,
java.lang.Thread#stop()
,
java.lang.Thread#Thread(java.lang.ThreadGroup,
java.lang.Runnable, java.lang.String)
,
java.lang.Runnable#run()
private void setupNewConnection(Socket clientSocket)
void shutdown()
The listener thread itself will die the next time it returns from 'accept' and notices that the terminate flag is set. What is more likely, however, is that the process will quiesce and we will go gently into the night, taking the daemon listener thread away with us when we go. We kill the listener user thread here so that that can happen.
void startup()
HACK: The listener thread needs to be a daemon thread, because if it were a user thread it would be uninteruptible while it was off waiting on an accept() (this is due to a flaw in Solaris, actually). However, if it's a daemon thread the app can exit even if the thread is still running. However, if we're just sitting there waiting for connections to arrive over the network, we don't want to exit, we want to keep running. Thus we have the net.vattp.data.UserThread, which does NOTHING but wait. Since it's a user thread it keeps the app from exiting (and thus allows the listener thread to keep running waiting for a connection) and since it's not waiting on an accept we can kill it. When we tell the listener thread to shutdown (which we now can do since it's a daemon thread), it sends a notify() to the listener user thread whereupon *it* shuts down too. Hallelujah, amen.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |