net.sf.colossus.webserver
Class WebServerClientSocketThread

java.lang.Object
  extended by java.lang.Thread
      extended by net.sf.colossus.webserver.WebServerClientSocketThread
All Implemented Interfaces:
java.lang.Runnable

public class WebServerClientSocketThread
extends java.lang.Thread

Thread to handle one user client connection at the WebServer side. Reads always one line from the socket, hands it over to the actual WebServerClient to parse and handle it.

Author:
Clemens Katzer

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
private  boolean connLostWarningLogged
           
private  boolean done
           
private  boolean forcedLogout
           
private static int IDLE_WARNING_INTERVAL_MINUTES
           
private static int IDLE_WARNING_MAXCOUNT
           
private  int idleWarningsSent
           
private  long lastPacketReceived
           
private  boolean lastWasLogin
           
(package private) static java.util.logging.Logger LOGGER
           
private  long MAX_WRITE_BLOCKTIME_MS
           
private static int PING_MAX_TRIES
           
private static long PING_REQUEST_INTERVAL_SECONDS
           
private  int pingCounter
           
private  int pingsTried
           
private  RoundtripTimeBookkeeper rttBookKeeper
           
private  java.net.Socket socket
           
private  java.lang.Thread stopper
           
private  WebServerClient theClient
           
private  boolean toldToTerminate
           
private  QueuedSocketWriter writer
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WebServerClientSocketThread(WebServerClient theClient, java.net.Socket socket)
           
 
Method Summary
 void checkMaxIdleTime(long now)
          Currently this will log out only older clients, because they do not respond to the ping packets.
 void clearIdleWarningsSent()
           
private  void closeAndCleanupSocket()
           
 void createStopper(java.lang.Runnable r)
           
 void flushMessages()
          Waits until writer has written all messages
protected  void forceLogout(WebServerClientSocketThread other)
           
(package private)  java.lang.String getClientInfo()
           
private  void markForcedLogout()
           
 void requestPingIfNeeded(long now)
           
 void requestPingNow()
           
 void run()
          prepare socket to read/write, and then loop as long as lines from client come, and parse them
 void sendToClient(java.lang.String s)
          Send the given string/message over the socket to the client Calculate the time how long it took to write it to the socket, and log a warning if it was blocked in the write for more than MAX_WRITE_BLOCKTIME_MS milliseconds.
 void setLastWasLogin()
           
 void storeEntry(long requestResponseArriveTime, long roundtripTime)
          Simply forward the RTT entry creation to the RTT bookkeeper
 void tellToTerminate()
           
(package private)  boolean wasForcedLogout()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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

LOGGER

static final java.util.logging.Logger LOGGER

PING_REQUEST_INTERVAL_SECONDS

private static final long PING_REQUEST_INTERVAL_SECONDS
See Also:
Constant Field Values

PING_MAX_TRIES

private static final int PING_MAX_TRIES
See Also:
Constant Field Values

IDLE_WARNING_INTERVAL_MINUTES

private static final int IDLE_WARNING_INTERVAL_MINUTES
See Also:
Constant Field Values

IDLE_WARNING_MAXCOUNT

private static final int IDLE_WARNING_MAXCOUNT
See Also:
Constant Field Values

MAX_WRITE_BLOCKTIME_MS

private final long MAX_WRITE_BLOCKTIME_MS
See Also:
Constant Field Values

theClient

private final WebServerClient theClient

rttBookKeeper

private final RoundtripTimeBookkeeper rttBookKeeper

socket

private java.net.Socket socket

writer

private QueuedSocketWriter writer

lastPacketReceived

private long lastPacketReceived

pingsTried

private int pingsTried

pingCounter

private int pingCounter

idleWarningsSent

private int idleWarningsSent

connLostWarningLogged

private boolean connLostWarningLogged

stopper

private java.lang.Thread stopper

forcedLogout

private boolean forcedLogout

done

private boolean done

toldToTerminate

private boolean toldToTerminate

lastWasLogin

private boolean lastWasLogin
Constructor Detail

WebServerClientSocketThread

public WebServerClientSocketThread(WebServerClient theClient,
                                   java.net.Socket socket)
Method Detail

getClientInfo

java.lang.String getClientInfo()

createStopper

public void createStopper(java.lang.Runnable r)

tellToTerminate

public void tellToTerminate()

setLastWasLogin

public void setLastWasLogin()

closeAndCleanupSocket

private void closeAndCleanupSocket()

run

public void run()
prepare socket to read/write, and then loop as long as lines from client come, and parse them

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

sendToClient

public void sendToClient(java.lang.String s)
Send the given string/message over the socket to the client Calculate the time how long it took to write it to the socket, and log a warning if it was blocked in the write for more than MAX_WRITE_BLOCKTIME_MS milliseconds.

Parameters:
s -

flushMessages

public void flushMessages()
Waits until writer has written all messages


storeEntry

public void storeEntry(long requestResponseArriveTime,
                       long roundtripTime)
Simply forward the RTT entry creation to the RTT bookkeeper

Parameters:
requestResponseArriveTime - When response arrived
roundtripTime - Actual roundtrip time

requestPingIfNeeded

public void requestPingIfNeeded(long now)

requestPingNow

public void requestPingNow()

markForcedLogout

private void markForcedLogout()

wasForcedLogout

boolean wasForcedLogout()

forceLogout

protected void forceLogout(WebServerClientSocketThread other)

clearIdleWarningsSent

public void clearIdleWarningsSent()

checkMaxIdleTime

public void checkMaxIdleTime(long now)
Currently this will log out only older clients, because they do not respond to the ping packets. TODO in future, distinct between ping packets and all other activities, and log out user which hasn't done anything and left WebClient standing around idle for very long.

Parameters:
now -