CADI.Server.Request
Class RequestListener

java.lang.Object
  extended by java.lang.Thread
      extended by CADI.Server.Request.RequestListener
All Implemented Interfaces:
java.lang.Runnable

public class RequestListener
extends java.lang.Thread

This class listens to the client requests and enqueues them.

None prioritization criterion is performed. Request are enqueued in the same order they are received.

Usage example:
  construct
  run

Version:
1.0.2 2009/08/16
Author:
Group on Interactive Coding of Images (GICI)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
(package private)  boolean finish
          Indicates if the thread must be finished.
private  HTTPRequestReader httpRequestReader
          A object that reads the HTTP request from a input stream.
private  CADILog log
          Definition in Scheduler.log.
private  int port
          Port where the server is listening to.
private  RequestQueue requestQueue
          It is a queue where the client request are stored.
private  java.net.ServerSocket serverSocket
          Server socket where server is listening to client requests.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
RequestListener(java.lang.String threadName, int port, RequestQueue requestQueue, CADILog log)
          Constructor.
 
Method Summary
 void finish()
          This method is used to indicate that the thread has to finish.
 void list(java.io.PrintStream out)
          Prints this Request listener out to the specified output stream.
 void run()
          Listens to in a port and receives the client requests.
private  void sendHTTPResponseError(java.net.Socket socket, int statusCode, java.lang.String reasonPhrase)
          This method will be used to send an HTTP error response to the client.
private  void showSocket(java.net.Socket socket)
          For debugging purposes.
 java.lang.String toString()
           
 
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, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

port

private int port
Port where the server is listening to. Definition in Scheduler.ports.


requestQueue

private RequestQueue requestQueue
It is a queue where the client request are stored. This queue is shared memory between the daemon which stored the client requests and the RequestDispatcher which gets them to process.

Definition in Scheduler.requestQueue.


log

private CADILog log
Definition in Scheduler.log.


finish

volatile boolean finish
Indicates if the thread must be finished.


serverSocket

private java.net.ServerSocket serverSocket
Server socket where server is listening to client requests.


httpRequestReader

private HTTPRequestReader httpRequestReader
A object that reads the HTTP request from a input stream.

Constructor Detail

RequestListener

public RequestListener(java.lang.String threadName,
                       int port,
                       RequestQueue requestQueue,
                       CADILog log)
                throws ErrorException
Constructor.

Parameters:
threadName - is the name of the thread.
port - it is the port where the server will listen to the client requests
requestQueue - it is the queue where the received client request will be saved.
log -
Throws:
ErrorException - if the socket server can not be opened.
Method Detail

run

public void run()
Listens to in a port and receives the client requests. All recieved request are stored in a shared queue.

The method will be running meanwhile the finish attribute is true.

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

finish

public void finish()
This method is used to indicate that the thread has to finish.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Thread

list

public void list(java.io.PrintStream out)
Prints this Request listener out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

showSocket

private void showSocket(java.net.Socket socket)
                 throws java.io.IOException
For debugging purposes. It shows all socket information.

Parameters:
socket - the socket whose information will be shown.
Throws:
java.io.IOException - this exception will be thrown if an error has occurred.

sendHTTPResponseError

private void sendHTTPResponseError(java.net.Socket socket,
                                   int statusCode,
                                   java.lang.String reasonPhrase)
This method will be used to send an HTTP error response to the client.

Parameters:
statusCode - definition in StatusCodes.
reasonPhrase - a reason phrase related with the status code.


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)