JCas
v0.3.1

cas
Class ConnectionThread

java.lang.Object
  extended byjava.lang.Thread
      extended bycas.ConnectionThread
All Implemented Interfaces:
EventListener, PropertyChangeListener, Runnable

public class ConnectionThread
extends Thread
implements PropertyChangeListener

Handles a single connection and waits for assignment.

Version:
1.0
Author:
Ralph Schuster

Nested Class Summary
static class ConnectionThread.JCasJaasCallbackHandler
          The callback handler for JAAS authentication.
 
Field Summary
protected  ConnectionThread.JCasJaasCallbackHandler callbackHandler
          The callback handler for JAAS authentication.
protected  JCasConfiguration configuration
          The configuration
protected  long maxRequests
          max requests
protected  long requestCount
          Counts the requests
protected  long requestStart
          Time of request start
protected  boolean runThread
          Indication if the thread should run.
protected  Socket socket
          The socket
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ConnectionThread(JCasConfiguration configuration)
          Creates a new instance of ConnectionThread
 
Method Summary
protected  boolean checkCookie(JCasSchemeTag scheme, JCasRequest request, JCasResponse response)
          Checks the cookie if it was given and validates it.
 boolean checkRequestTime()
          Checks the running time of the current request and aborts it if necessary.
protected  boolean doCustomAuth(JCasSchemeTag scheme, JCasRequest request, JCasResponse response)
          Performs custom authorization.
protected  boolean doExtendedAuth(JCasSchemeTag scheme, JCasRequest request, JCasResponse response)
          Performs extended authorization.
protected  boolean doJaas(JCasSchemeTag scheme, JCasRequest request, JCasResponse response)
          Performs system authorization.
protected  boolean doSystemAuth(JCasSchemeTag scheme, JCasRequest request, JCasResponse response)
          Performs system authorization.
 long getRequestCount()
          Returns the number of handled requests.
protected  JCasResponse handleAdminRequest(JCasAdminRequest request)
          Handles the admin request.
protected  void handleConnection()
          Handles a single connection.
protected  JCasResponse handleRequest(JCasRequest request)
          Handles the request.
 boolean isAvailable()
          Returns true if thread does not handle a connection.
protected  void logRequest(JCasAdminRequest request, JCasResponse response)
          Logs the admin request.
protected  void logRequest(JCasRequest request, JCasResponse response)
          Logs the request.
 void propertyChange(PropertyChangeEvent evt)
           
 void run()
          Runs the thread and handles connections.
protected  void sendResponse(JCasResponse response, PrintWriter out)
          Sends the response.
protected  void setCookieTag(JCasRequest request)
          Sets the cookie tag on the request.
 boolean setSocket(Socket socket, boolean stopThread)
          Sets the connection socket and starts communicating on that socket.
protected  void updateCookie(JCasSchemeTag scheme, JCasRequest request, JCasResponse response)
          Checks the cookie if it was given and validates it.
 
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

configuration

protected JCasConfiguration configuration
The configuration


socket

protected Socket socket
The socket


runThread

protected boolean runThread
Indication if the thread should run.


requestStart

protected long requestStart
Time of request start


requestCount

protected long requestCount
Counts the requests


maxRequests

protected long maxRequests
max requests


callbackHandler

protected ConnectionThread.JCasJaasCallbackHandler callbackHandler
The callback handler for JAAS authentication.

Constructor Detail

ConnectionThread

public ConnectionThread(JCasConfiguration configuration)
Creates a new instance of ConnectionThread

Method Detail

setSocket

public boolean setSocket(Socket socket,
                         boolean stopThread)
Sets the connection socket and starts communicating on that socket. This method controls the status of the thread.
socketstopThreadEffect on threadreturn value
not nulltrue/falseThread should handle connectiontrue if socket was accepted, false if thread is busy of exception if thread already stopped
nulltrueThread should stopAlways true
nullfalseInternal use: Thread closes connection, update statusAlways true


isAvailable

public boolean isAvailable()
Returns true if thread does not handle a connection.


run

public void run()
Runs the thread and handles connections.

Specified by:
run in interface Runnable

handleConnection

protected void handleConnection()
Handles a single connection.


getRequestCount

public long getRequestCount()
Returns the number of handled requests.


handleRequest

protected JCasResponse handleRequest(JCasRequest request)
Handles the request.

Returns:
response object

handleAdminRequest

protected JCasResponse handleAdminRequest(JCasAdminRequest request)
Handles the admin request.

Returns:
response object

sendResponse

protected void sendResponse(JCasResponse response,
                            PrintWriter out)
                     throws IOException
Sends the response.

Throws:
IOException

checkCookie

protected boolean checkCookie(JCasSchemeTag scheme,
                              JCasRequest request,
                              JCasResponse response)
Checks the cookie if it was given and validates it.


updateCookie

protected void updateCookie(JCasSchemeTag scheme,
                            JCasRequest request,
                            JCasResponse response)
Checks the cookie if it was given and validates it.


setCookieTag

protected void setCookieTag(JCasRequest request)
Sets the cookie tag on the request.


doSystemAuth

protected boolean doSystemAuth(JCasSchemeTag scheme,
                               JCasRequest request,
                               JCasResponse response)
Performs system authorization.


doCustomAuth

protected boolean doCustomAuth(JCasSchemeTag scheme,
                               JCasRequest request,
                               JCasResponse response)
Performs custom authorization.


doExtendedAuth

protected boolean doExtendedAuth(JCasSchemeTag scheme,
                                 JCasRequest request,
                                 JCasResponse response)
Performs extended authorization.


doJaas

protected boolean doJaas(JCasSchemeTag scheme,
                         JCasRequest request,
                         JCasResponse response)
Performs system authorization.


logRequest

protected void logRequest(JCasRequest request,
                          JCasResponse response)
Logs the request.


logRequest

protected void logRequest(JCasAdminRequest request,
                          JCasResponse response)
Logs the admin request.


checkRequestTime

public boolean checkRequestTime()
Checks the running time of the current request and aborts it if necessary.

Returns:
true if thread is ok

propertyChange

public void propertyChange(PropertyChangeEvent evt)
Specified by:
propertyChange in interface PropertyChangeListener

JCas
v0.3.1