CADI.Server.Core
Class Scheduler

java.lang.Object
  extended by java.lang.Thread
      extended by CADI.Server.Core.Scheduler
All Implemented Interfaces:
java.lang.Runnable

public class Scheduler
extends java.lang.Thread

This class performs the control of the listener/s and workers threads.

The listener/s are the thread/s where the client request are received, and workers are a thread pool that process the requests and send the response to the client.

Usage example:
  construct
  setParameters
  run

Version:
1.1.1 2009/08/15
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
private  java.lang.String cachePath
          Is the path directory that will be used to save the temporary files used to cache client data.
private  ClientSessions clientSessions
          It is a list that contains information about the clients that are being served.
private  int deliveryProgressionOrder
          Definition in Worker.deliveryProgressionOrder.
private  boolean finish
          Indicates when the scheduler has to finish
private  boolean independentMessageHeaders
          Definition in JPIPMessageEncoder.independentForm.
private  int keepAliveTimeout
          It is the timeout (in milliseconds) that will be used to wait for a new client request when the HTTP keep-alive mode is set.
private  CADILog log
          It is an object that will be used to log the server process
private  boolean logEnabled
          Indicates whether the log is enabled or disabled.
private  java.lang.String logFile
          It is the file name where the server logs are stored.
private  LogicalTargetList logicalTargetList
          It is a list that contais information about the logical targets (typically an image) that are being served.
private  float maxTxRate
          Is the maximum rate (bytes per second) which will be used to delivery data from the server to the client. 0 value means unlimited.
private  int numOfWorkers
          Indicates the number of threads of the Worker that will be running.
private  int[] ports
          Ports where the server is listening to the client requests.
private  int rateDistortionMethod
          Indicates the rate distortion method that will be used with JPEG2000 logical targets.
private  int RDSubType
          Indicates a type within the rate distortion method.
private  RequestListener[] requestListenersPool
          This thread pool will listen to in a port to receive client requests.
private  RequestQueue requestQueue
          It is a queue where the client request are stored.
private  java.lang.String targetsPath
          Is the path directory where the logical targets are stored.
private  TasksQueue[] tasksQueue
          Is an array of queues to storage the tasks for each Worker thread.
private  Worker[] workersPool
          This thread pool will process the client requests and will send the server responses to the client.
private  boolean XMLLogFormat
          Indicates whether the log information is stored in XML format or simple text format.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Scheduler(int[] ports, int numOfWorkers, boolean logEnabled, int logLevel, java.lang.String logFile, boolean XMLLogFormat)
          Constructor.
 
Method Summary
 void finish()
          This method is used to indicate that the thread has to finish.
private  void launchListeners()
           
private  void launchWorkers()
           
 void list(java.io.PrintStream out)
          Prints this Scheduler's fields to the specified output stream.
 void run()
          This method manages the RequestListener pool and the Worker pool.
 void setCachePath(java.lang.String cachePath)
          Sets the cachePath attribute.
 void setDeliveryProgressionOrder(int deliveryProgressionOrder)
          Sets the deliveryProgressionOrder attribute.
 void setIndependentMessageHeaders(boolean independentMessageHeaders)
          Sets the #independentMesssageHeaders attribute.
 void setKeepAliveTimeout(int keepAliveTimeout)
          Sets the keepAliveTimeout attribute.
 void setMaxTxRate(float maxTxRate)
          Sets the maxTxRate attribute.
 void setRateDistortionMethod(int rateDistortionMethod, int RDSubType)
          Sets the rate-distortion method and the subrate-distortion method.
 void setTargetsPath(java.lang.String targetsPath)
          Sets the targetsPath attribute.
 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

ports

private int[] ports
Ports where the server is listening to the client requests.


numOfWorkers

private int numOfWorkers
Indicates the number of threads of the Worker that will be running.


logFile

private java.lang.String logFile
It is the file name where the server logs are stored.


XMLLogFormat

private boolean XMLLogFormat
Indicates whether the log information is stored in XML format or simple text format.


logEnabled

private boolean logEnabled
Indicates whether the log is enabled or disabled.


keepAliveTimeout

private int keepAliveTimeout
It is the timeout (in milliseconds) that will be used to wait for a new client request when the HTTP keep-alive mode is set.


maxTxRate

private float maxTxRate
Is the maximum rate (bytes per second) which will be used to delivery data from the server to the client. 0 value means unlimited.

Only positive values are allowed.


independentMessageHeaders

private boolean independentMessageHeaders
Definition in JPIPMessageEncoder.independentForm.


targetsPath

private java.lang.String targetsPath
Is the path directory where the logical targets are stored.


cachePath

private java.lang.String cachePath
Is the path directory that will be used to save the temporary files used to cache client data.


rateDistortionMethod

private int rateDistortionMethod
Indicates the rate distortion method that will be used with JPEG2000 logical targets.


RDSubType

private int RDSubType
Indicates a type within the rate distortion method.


deliveryProgressionOrder

private int deliveryProgressionOrder
Definition in Worker.deliveryProgressionOrder.


requestListenersPool

private RequestListener[] requestListenersPool
This thread pool will listen to in a port to receive client requests.


workersPool

private Worker[] workersPool
This thread pool will process the client requests and will send the server responses to the client.


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.


logicalTargetList

private LogicalTargetList logicalTargetList
It is a list that contais information about the logical targets (typically an image) that are being served.


clientSessions

private ClientSessions clientSessions
It is a list that contains information about the clients that are being served.


tasksQueue

private TasksQueue[] tasksQueue
Is an array of queues to storage the tasks for each Worker thread. Therefore, each queue of the array belongs to a Workder.


log

private CADILog log
It is an object that will be used to log the server process


finish

private boolean finish
Indicates when the scheduler has to finish

Constructor Detail

Scheduler

public Scheduler(int[] ports,
                 int numOfWorkers,
                 boolean logEnabled,
                 int logLevel,
                 java.lang.String logFile,
                 boolean XMLLogFormat)
Constructor.

Parameters:
ports - they are the ports where the server will listen to the client request.
numOfWorkers - they are the number of workers that will be launched to process the client request.
logEnabled - definition in logEnabled
logLevel - definition in CADILog.logLevel
logFile - definition in logFile.
XMLLogFormat - definition in XMLLogFormat.
Throws:
ErrorException - when the server can not be launched because the server socket can not be opened it will be thrown.
Method Detail

setTargetsPath

public void setTargetsPath(java.lang.String targetsPath)
Sets the targetsPath attribute.

Parameters:
targetsPath - definition in targetsPath.

setCachePath

public void setCachePath(java.lang.String cachePath)
Sets the cachePath attribute.

Parameters:
cachePath - definition in cachePath.

setRateDistortionMethod

public void setRateDistortionMethod(int rateDistortionMethod,
                                    int RDSubType)
Sets the rate-distortion method and the subrate-distortion method.

Parameters:
rateDistortionMethod - definition in rateDistortionMethod.
RDSubType - definition in RDSubType.

setDeliveryProgressionOrder

public void setDeliveryProgressionOrder(int deliveryProgressionOrder)
Sets the deliveryProgressionOrder attribute.

Parameters:
deliveryProgressionOrder - definition in deliveryProgressionOrder.

setKeepAliveTimeout

public void setKeepAliveTimeout(int keepAliveTimeout)
Sets the keepAliveTimeout attribute.

Parameters:
keepAliveTimeout - definition in keepAliveTimeout.

setMaxTxRate

public void setMaxTxRate(float maxTxRate)
Sets the maxTxRate attribute.

Parameters:
maxTxRate - definition in maxTxRate attribute.

setIndependentMessageHeaders

public void setIndependentMessageHeaders(boolean independentMessageHeaders)
Sets the #independentMesssageHeaders attribute.

Parameters:
independentMesssageHeaders - definition in #independentMesssageHeaders attribute.

run

public void run()
This method manages the RequestListener pool and the Worker pool. It gets the client request (received by the RequestListener) and assigns the tasks to the Worker .

The method will be running until the finish attibute is set to false.

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 Scheduler's fields to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

launchListeners

private void launchListeners()
                      throws ErrorException
Throws:
ErrorException

launchWorkers

private void launchWorkers()


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)