public class Worker extends java.lang.Thread implements StatusCodes, EORCodes
This thread is launched and it will be waiting for a task. Tasks are passed
to this worker through a
This thread is always running or waiting for a task. Therefore, it only can
be finished if the
Usage example:TaskQueue
queue (the
Scheduler
puts the task into the queue and the
Worker
get them).
is set to
finish
true
.
construct
setParameters
run
....
finish
Modifier and Type | Field and Description |
---|---|
private boolean |
busy
Indicates if the thread is carrying out a task.
|
private java.lang.String |
cachePath
Is the path directory that will be used to save the temporary files
used to cache client data.
|
private static java.lang.String |
channelFieldPath |
private java.lang.String |
cid
Definition in
ChannelField.cid . |
private int |
deliveringMode
Further information, see
ServerParser.serverArguments . |
private int |
deliveringSubtype
Indicates a subtype of the
deliveringMode attribute. |
private boolean |
finish
Indicates whether the thread has to finish when it is working with a
request with the keep-alive mode set.
|
private HTTPRequest |
httpRequest
Definition in
HTTPRequest . |
private HTTPResponse |
httpResponse |
private HTTPResponseSender |
httpResponseSender |
private boolean |
independentMessageHeaders
Definition in
CADI.Server.Network.JPIPMessageEncoder#independentForm . |
private long |
initStageTime
Used for verbose information (time for stage).
|
private long |
initTime
Used for verbose information (total time).
|
private boolean |
isStatelessRequest
Indicates whether the actual request is a stateles request or a request
with a session.
|
private ServerJPIPChannel |
jpipChannel |
private JPIPRequestFields |
jpipRequestFields
Definition in
JPIPRequestFields . |
private JPIPResponseFields |
jpipResponseFields |
private int |
keepAliveTimeout
Definition in
Scheduler.keepAliveTimeout . |
private ServerClientSessions |
listOfClientSessions
Definition in
Scheduler.clientSessions . |
private CADILog |
log
Definition in
Scheduler.log . |
private JP2KServerLogicalTarget |
logicalTarget
Contains a pointer to the parameters of the logical target which is being
requested.
|
private ServerLogicalTargetList |
logicalTargetList
Definition in
Scheduler.logicalTargetList . |
private long |
maxTxRate
Definition in
Scheduler.maxTxRate . |
private java.io.OutputStream |
os
Is an output stream that will be used to send the server response to the client.
|
private boolean |
predictiveModel
Definition in
Scheduler.predictiveModel . |
private boolean |
sendLogicalTargetData |
private ServerCacheModel |
serverCache |
private ServerClientSession |
session
Contains the session object where data about the actual session is
saved.
|
private java.net.Socket |
socket
Contains the client socket of which request is being processed.
|
private java.lang.String |
targetsPath
Is the path directory where the logical targets are stored.
|
private TasksQueue |
tasksQueue
Definition in
Scheduler.tasksQueue |
private int |
trafficShaping
Definition in
Scheduler.maxTxRate . |
private java.lang.String |
version |
ACCEPTED, BAD_REQUEST, NOT_FOUND, NOT_IMPLEMENTED, OK, SERVICE_UNAVAILABLE, UNSUPPORTED_MEDIA_TYPE
BYTE_LIMIT_REACHED, IMAGE_CHANGE, IMAGE_DONE, NON_ESPECIFIED_REASON, QUALITY_LIMIT_REACHED, RESPONSE_LIMIT_REACHED, SESSION_LIMIT_REACHED, WINDOW_DONE
Constructor and Description |
---|
Worker(java.lang.String threadName,
TasksQueue tasksQueue,
ServerLogicalTargetList logicalTargetList,
ServerClientSessions clientSessions,
CADILog log)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private java.lang.String[] |
availableReturnTypes()
Gets the available image return types.
|
private void |
checkJPIPParameters()
This method tests several JPIP restrictions of the parameters
|
private void |
closeChannels(java.lang.String cid,
java.util.ArrayList<java.lang.String> cclose)
This method is used to close session channels.
|
private void |
encodeJPIPResponseFields()
JPIP HEADERS (See ISO/IEC 15444-9 Annex D)
|
void |
finish()
This method is used to indicate that the thread has to finish.
|
java.lang.Thread.State |
getState() |
boolean |
isBusy()
This method is used to indicate if the thread is or no busy processing a
task.
|
private void |
listenNewRequest()
This method will be used to read a HTTP client request.
|
private void |
logicalTargetsManager(java.lang.String target,
java.lang.String tid)
This method is used to manage the list of loaded targets.
|
private void |
processRequest()
This method performs the core to process the client requests.
|
private void |
resetTime()
Set the time attributes to 0.
|
void |
run()
This method implements the control of the thread.
|
private void |
sendHTTPResponseError(int statusCode,
java.lang.String reasonPhrase)
This method will be used to send an HTTP error response to the client.
|
private void |
sendHTTPResponseHeader(HTTPResponse httpResponse) |
void |
sessionsManager()
This method is used to manage the client sessions.
|
void |
setCachePath(java.lang.String cachePath)
Sets the
cachePath attribute. |
void |
setDeliveringMode(int deliveringMode,
int deliveringSubtype)
Sets the mode used to deliver precinct data to the client.
|
void |
setIndependentMessageHeaders(boolean independentMessageHeaders)
Sets the
#independentMesssageHeaders attribute. |
void |
setKeepAliveTimeout(int keepAliveTimeout)
Sets the
keepAliveTimeout attribute. |
void |
setMaxTxRate(long maxTxRate)
Sets the
maxTxRate attribute. |
void |
setPredictiveModel(boolean predictiveModel)
Sets the
predictiveModel attribute. |
void |
setTargetsPath(java.lang.String targetsPath)
Sets the
targetsPath attribute. |
void |
setTrafficShaping(int trafficShaping)
Sets the
trafficShaping attribute. |
private java.lang.String |
showTimeMemory(java.lang.String stage)
Show some time and memory usage statisticals.
|
private void |
updateCache(java.util.ArrayList<JPIPMessageHeader> jpipMessageData)
This method is used to update the cache with the data that has been sent
to the client.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, 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
private TasksQueue tasksQueue
Scheduler.tasksQueue
private ServerLogicalTargetList logicalTargetList
Scheduler.logicalTargetList
.private ServerClientSessions listOfClientSessions
Scheduler.clientSessions
.private CADILog log
Scheduler.log
.private java.lang.String targetsPath
private java.lang.String cachePath
private int deliveringMode
ServerParser.serverArguments
.private int deliveringSubtype
deliveringMode
attribute. Thus, its
value will depend on the value taken by deliveringMode
.
Further information, see ServerParser.serverArguments
.
{
value.
private int keepAliveTimeout
Scheduler.keepAliveTimeout
.private long maxTxRate
Scheduler.maxTxRate
.private int trafficShaping
Scheduler.maxTxRate
.private boolean independentMessageHeaders
CADI.Server.Network.JPIPMessageEncoder#independentForm
.private boolean predictiveModel
Scheduler.predictiveModel
.private java.net.Socket socket
private HTTPRequest httpRequest
HTTPRequest
.private JPIPRequestFields jpipRequestFields
JPIPRequestFields
.private boolean finish
finish()
private boolean busy
busy
attribute is
false
.private java.io.OutputStream os
private HTTPResponseSender httpResponseSender
private HTTPResponse httpResponse
private JPIPResponseFields jpipResponseFields
private JP2KServerLogicalTarget logicalTarget
private ServerCacheModel serverCache
private ServerJPIPChannel jpipChannel
private boolean isStatelessRequest
private ServerClientSession session
private java.lang.String cid
ChannelField.cid
.private boolean sendLogicalTargetData
private static java.lang.String channelFieldPath
private long initStageTime
0 is initial time.
private long initTime
0 is initial time.
private java.lang.String version
public Worker(java.lang.String threadName, TasksQueue tasksQueue, ServerLogicalTargetList logicalTargetList, ServerClientSessions clientSessions, CADILog log)
threadName
- is a string with the name of the thread.tasksQueue
- definition in tasksQueue
.logicalTargetList
- definition in logicalTargetList
.clientSessions
- definition in listOfClientSessions
.log
- definition in log
.public void setTargetsPath(java.lang.String targetsPath)
targetsPath
attribute.targetsPath
- definition in targetsPath
.public void setCachePath(java.lang.String cachePath)
cachePath
attribute.cachePath
- definition in cachePath
.public void setDeliveringMode(int deliveringMode, int deliveringSubtype)
deliveringMode
- definition in deliveringMode
.deliveringSubtype
- definition in deliveringSubtype
.public void setKeepAliveTimeout(int keepAliveTimeout)
keepAliveTimeout
attribute.keepAliveTimeout
- definition in keepAliveTimeout
.public void setMaxTxRate(long maxTxRate)
maxTxRate
attribute.maxTxRate
- definition in maxTxRate
attribute.public void setTrafficShaping(int trafficShaping)
trafficShaping
attribute.maxTxRate
- definition in trafficShaping
attribute.public void setIndependentMessageHeaders(boolean independentMessageHeaders)
#independentMesssageHeaders
attribute.independentMesssageHeaders
- definition in #independentMesssageHeaders
attribute.public void setPredictiveModel(boolean predictiveModel)
predictiveModel
attribute.predictiveModel
- definition in predictiveModel
.public void run()
When the
Scheduler
assigns a task, it will be awake. The
task may be:
The thread will be running until the
finish
attribute is
false
.
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void finish()
public boolean isBusy()
true
if the thread is processing a task. Otherwise,
it returns
false
.public java.lang.Thread.State getState()
getState
in class java.lang.Thread
private void processRequest() throws WarningException
WarningException
public void sessionsManager() throws WarningException
Tests if it is a stateless request, if it is a request which belongs to
a previous session, or it is a request for a new session. When a
stateless request is used, a temporary session is created and it must be
removed when the request process finishes. When the request is for a new
session, a new entry in the
listOfClientSessions
is created
with the client preferences and capabilities. And if the request belongs
to a previous session, then, client data (logical target, image return
type, cache, preferences, capabilites, etc. ) are read from the
listOfClientSessions
.
When an error in the request is found (p.e. session identifier does not
exist or are wrong, logical target does not exist, etc.), an error
message is sent to the client and a
WarningException
is
thrown.
WarningException
- when something anomalous (p.e. session identifier
does not exist or are wrong, logical target does not exist, etc.) this
exception will be thrown.private void logicalTargetsManager(java.lang.String target, java.lang.String tid) throws WarningException
target
field, the jpip
tid
field, or both.
If the requested target has been loaded in a previous request, it will be in the list of loaded targets. So, its parameters will be recovered from that list.
Otherwise, target will be searched in disk. And if it is in disk, it will be loaded to the list.
target
- definition in TargetField.target
tid
- definition in TargetField.tid
WarningException
private void listenNewRequest() throws WarningException, ErrorException
httpRequestFields
(seeWarningException
- when anErrorException
- when the client has closed the socket, the
socket reaches its timeout, or an I/O error has occured while client
request was being received.private void sendHTTPResponseHeader(HTTPResponse httpResponse) throws WarningException
httpResponse
- WarningException
private void sendHTTPResponseError(int statusCode, java.lang.String reasonPhrase)
statusCode
- definition in StatusCodes
.reasonPhrase
- a reason phrase related with the status code.private void encodeJPIPResponseFields()
private void checkJPIPParameters() throws WarningException
WarningException
private void closeChannels(java.lang.String cid, java.util.ArrayList<java.lang.String> cclose)
cid
- definition in ChannelField.cid
cclose
- definition in ChannelField.cclose
private void updateCache(java.util.ArrayList<JPIPMessageHeader> jpipMessageData)
jpipMessageData
- an array list with the data that has been sent.private java.lang.String[] availableReturnTypes()
private void resetTime()
private java.lang.String showTimeMemory(java.lang.String stage)
stage
- string that will be displayed
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)