CADI.Client
Class Client

java.lang.Object
  extended by CADI.Client.Client
All Implemented Interfaces:
java.lang.Runnable

public class Client
extends java.lang.Object
implements java.lang.Runnable

This class implements a JPIP Client.

NOTE: It implements the Runnable interface but it is not working like a thread. It will be done in the next version.

Usage example:
  constructor
  setClientProperties
  setServerAndTarget
  getTarget | getThumbnail
  get methods

Version:
1.1.3 2009/05/02
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
static int ABORT
           
private  int action
           
private  int auxport
           
private  long bytesJPIPMessageBody
          Is used to save the amount of received bytes in the JPIP message body.
private  long bytesJPIPMessageHeader
          Is used to save the amount of received bytes in the JPIP message header.
private  java.lang.String[] cclose
           
private  java.lang.String cid
           
private  ClientCacheManagement clientCache
          Contains the client cache.
private  java.lang.String clientHostName
          Contains the local host name.
private  ClientProperties clientProperties
          Contains the client preferences.
private  int[] cnew
           
static int DECOMPRESSING
           
private  long[] downloadedBytes
          An one-dimmensional array which contains a log of the last amount of downloaded data.
private  long[] downloadsTimes
          An one-dimmensional array which contains the time when the saved data at downloadedBytes were downloaded.
private  boolean error
          Indicates whether an error has been occurred.
private  java.lang.String errorMessage
          It is an error message which has a short description of the error.
static int FINISH
           
private  java.lang.String host
           
private  HTTPClient httpClient
          An object to send the request and receive the server response.
private  ImageData imageData
          Contains the last requested image.
private  int imageDataType
          Is the image type that will be used to delivery the decompressed image.
private  long initStageTime
          Used for verbose information (time for stage).
private  long initTime
          Used for verbose information (total time).
private  JPIPMessageDecoder jpipMessageDecoder
          Object used to decode the JPIP response messages.
private  JPIPRequestEncoder jpipRequestEncoder
          Object to encode the JPIP request parameters.
private  JPIPResponseFields jpipResponseFields
          This object contains the JPIP response parameters.
private  boolean keepAlive
          Indicates whether the HTTP connection to remote server are persistents.
private  int len
           
private  CADILog log
          Is used to log the client messages.
private  ClientLogicalTarget logicalTarget
           
protected  int managementPolicy
          Definition in CADI.Client.Cache.ClientCache#managementPolicy.
private  long maxCacheSize
          Is the maximum size (in bytes) allowed for the saved data in the cache.
private  long maxTargetLength
          Is the maximum length of the compressed target to be decompresed.
private  java.lang.String path
           
private  int port
           
static int PROCESSING_REQUEST
           
private  int proxyPort
           
private  java.lang.String proxyServer
          Is the proxy server used to connect to the server.
private  int qid
           
private  int quality
           
private  ViewWindowField requestViewWindow
          Contains the view window requested by the client application.
private  ViewWindowField responseViewWindow
          Contains the request view window which has been modified by the remote server if any of the parameters has been modified.
private  boolean reuseCache
          Indicates whether the cache is used between two consecutive requests.
static int RUN
           
private  java.lang.String server
          Is the server name where logical targets are located.
private  int state
          Indicates the actual state of the thread process.
static int STOPPED
           
private  StopWatch stopWatch
           
private  int[] subtarget
           
private  java.lang.String target
          Documentar: variables que mantienen el estado del cliente jpip.
private  ImageData thumbnailData
          Is a thumbnail of the image.
private  java.lang.String tid
           
private  long totalDownloadedBytes
          Contains the downloaded total bytes for the actual logical target.
private  int transport
           
private  int type
          Indicates the image return type which it is being used.
 boolean useHTTPSession
          Indicates if HTTP session is allowed.
 boolean useHTTPTCPSession
          Indicates if HTTP TCP session is allowed.
private  java.lang.String userAgent
          Contains the value of the HTTP user-agent feature.
private  boolean useSession
          Indicates whether stateless request or session request will be used.
static int WAITING_SERVER_RESPONSE
           
 
Constructor Summary
Client(ImageData imageData)
          Constructor.
 
Method Summary
static float calculateAverageWeighted(long[] bytes, long[] times)
          Calculates the average of bytes per second.
 void closeLogicalTarget()
          Release all data about the current logical target.
 boolean closeSession()
          Closes the session with the server.
private  int[][] componentsToRangeOfComponents(int[] comps)
          This method moves the number of components from an array structure to an array of ranges.
 long getBytesJPIPMessageBody()
          Returns the bytesJPIPMessageBody attribute.
 long getBytesJPIPMessageHeader()
          Returns the bytesJPIPMessageHeader attribute.
 long getDownloadedBytes()
          Returns the downloaded total bytes for the actual logical target.
 java.lang.String getErrorMessage()
          Not available yet.
 int getJPIPStreamType()
          Returns the JPIP-stream media type with is beind used.
 java.lang.String getLogFileName()
          Definition in CADILog.getFileName().
 int getLogLevel()
          Definition in CADILog.getLogLevel().
private  void getMainHeader()
          Gets the main header of the logical target.
 int getManagementPolicy()
          Definition in CADI.Client.Cache.ClientCache#getManagementPolicy()
 long getMaxCacheSize()
          Definition in CADI.Client.Cache.ClientCache#getMaxCacheSize()
 int getPort()
          Return the port number of the server.
private  void getRequest(java.lang.String requestURI)
          Get the target which is identified by the URI requestURI
 java.lang.String getServer()
          Return the sever name of the latest connection.
 float getSpeed()
          Returns the download's speed average.
 int getState()
          Not available yet.
 void getTarget()
          This method fetchs a logical target.
 void getTarget(int[][] comps, int[] fsiz, int[] roff, int[] rsiz, int layers, int quality, int round)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[][] comps, int[] fsiz, int[] roff, int[] rsiz, int layers, int quality, int round, long maxTargetLength)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[][] comps, int resolutionLevel, int[] roff, int[] rsiz, int layers, int quality)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[][] comps, int resolutionLevel, int[] roff, int[] rsiz, int layers, int quality, long maxTargetLength)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[] components, int[] fsiz, int[] roff, int[] rsiz, int layers, int quality, int round)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[] components, int[] fsiz, int[] roff, int[] rsiz, int layers, int quality, int round, long maxTargetLength)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[] components, int[] fsiz, int[] roff, int[] rsiz, long maxTargetLength)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[] components, int resolutionLevel, int[] roff, int[] rsiz, int layers, int quality)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[] components, int resolutionLevel, int[] roff, int[] rsiz, int layers, int quality, long maxTargetLength)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(int[] components, long maxTargetLength)
          This method fetchs a logical target defined by the method input parameters.
 void getTarget(long maxTargetLength)
          This method fetchs a logical target at a fixed length.
 void getTarget(long maxTargetLength, int layers, int quality)
          This method fetchs a logical target at a fixed length.
 void getTarget(java.lang.String requestURI)
          Get the target which is identified by the URI requestURI
 java.lang.String getTargetDescription()
          This method returns a detailed description of the last decoded logical target.
 java.lang.String getTargetName()
          Return the latest requested target name.
 ImageData getThumbnail(int thumbnailWidth, int thumbnailHeight, int imageDataType)
          Gets a thumbnail image of the actual logical target.
 java.lang.String getURI()
          Returns the last requested URI.
private  void getWindow(ViewWindowField viewWindow)
          Get the target target window of interest.
 boolean isError()
          Not available yet.
 boolean isKeepAlive()
          Returns the keepAlive attribute.
 boolean isLogEnabled()
          Definition in CADILog.isEnabled().
 boolean isUseHTTPSession()
          Returns the useHTTPSession attribute.
 boolean isUseHTTPTCPSession()
          Returns the useHTTPTCPSession attribute
 boolean isUseSession()
          Returns the useSession attribute.
 void list(java.io.PrintStream out)
          Prints this Client fields out to the specified output stream.
 void loadCache(java.lang.String fileName)
           
 void resetBytesJPIPMessages()
          Sets the JPIP message counter to 0.
 void reuseCache(boolean reuseCache)
          Sets if the client cache must be used.
 void run()
           
 void saveCache(java.lang.String fileName)
           
 void setCacheType(int cacheType, int cacheSubtype)
           
 void setClientProperties(ClientProperties clientProperties)
          Sets the JPIP client properties.
 void setKeepAlive(boolean keepAlive)
          Sets the keepAlive attribute.
 void setLogEnabled(boolean enabled)
          Sets the log enabled or disabled.
 void setLogFile(java.lang.String logFileName)
          Sets the file name where the log will be done.
 void setLogFile(java.lang.String logFileName, boolean useXMLFormat)
          Sets the file name where the log will be done.
 void setLogLevel(int logLevel)
          Sets the log level.
 void setManagementPolicy(int managementPolicy)
          Definition in CADI.Client.Cache.ClientCache#setManagementPolicy(int).
 void setMaxCacheSize(long maxCacheSize)
          Definition in CADI.Client.Cache.ClientCache#setMaxCacheSize(long).
 void setServerAndTarget(java.lang.String server, int port, java.lang.String target)
          Sets the server name and port where the logical targets are located.
 void setServerAndTarget(java.lang.String server, int port, java.lang.String target, long maxTargetLength)
          Sets the server name and port where the logical targets are located.
 void setServerAndTarget(java.lang.String server, int port, java.lang.String target, java.lang.String proxyServer, int proxyPort)
          Sets the server name and port where the logical targets are located, as well as the proxy and port that will be used.
 void setServerAndTarget(java.lang.String server, int port, java.lang.String target, java.lang.String proxyServer, int proxyPort, long maxTargetLength)
           
 void setUseHTTPSession(boolean useHTTPSession)
          Sets the useHTTPSession attribute.
 void setUseHTTPTCPSession(boolean useHTTPTCPSession)
          Sets the useHTTPTCPSession attribute
 void setUserAgent(java.lang.String userAgent)
          This method sets the HTTP's user agent header.
 void setUseSession(boolean useSession)
          Indicates whether sessions will be used in the JPIP connections.
private  void showTimeMemory(java.lang.String stage)
          Show some time and memory usage statisticals.
 void start()
          Not available yet.
 void stop()
          Not available yet.
 java.lang.String toString()
           
private  void updateReceivedBytesAndTimes(long bytes, long time)
          This method updates the downloadedBytes and downloadsTimes attributes with new new values which are parssed as input parameters.
 boolean useLogXMLFormat()
          Definition in CADILog.useXMLFormat().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

imageData

private ImageData imageData
Contains the last requested image.


thumbnailData

private ImageData thumbnailData
Is a thumbnail of the image.


clientProperties

private ClientProperties clientProperties
Contains the client preferences.


imageDataType

private int imageDataType
Is the image type that will be used to delivery the decompressed image.

Further information about allowed data types, see ImageData.dataType.


reuseCache

private boolean reuseCache
Indicates whether the cache is used between two consecutive requests. If true cached data is keep, meanwhile if it is false cached data are deleted.


managementPolicy

protected int managementPolicy
Definition in CADI.Client.Cache.ClientCache#managementPolicy.


maxCacheSize

private long maxCacheSize
Is the maximum size (in bytes) allowed for the saved data in the cache.

Only positive values are allowed.

A 0 value means unlimited.


useSession

private boolean useSession
Indicates whether stateless request or session request will be used.


useHTTPSession

public boolean useHTTPSession
Indicates if HTTP session is allowed.

This attribute is only allowed when useSession attribute is true.


useHTTPTCPSession

public boolean useHTTPTCPSession
Indicates if HTTP TCP session is allowed.

This attribute is only allowed when useSession attribute is true.


maxTargetLength

private long maxTargetLength
Is the maximum length of the compressed target to be decompresed.

A negative value means no limit (infinite length).


totalDownloadedBytes

private volatile long totalDownloadedBytes
Contains the downloaded total bytes for the actual logical target.


state

private volatile int state
Indicates the actual state of the thread process.


STOPPED

public static final int STOPPED
See Also:
Constant Field Values

PROCESSING_REQUEST

public static final int PROCESSING_REQUEST
See Also:
Constant Field Values

WAITING_SERVER_RESPONSE

public static final int WAITING_SERVER_RESPONSE
See Also:
Constant Field Values

DECOMPRESSING

public static final int DECOMPRESSING
See Also:
Constant Field Values

action

private volatile int action

RUN

public static final int RUN
See Also:
Constant Field Values

ABORT

public static final int ABORT
See Also:
Constant Field Values

FINISH

public static final int FINISH
See Also:
Constant Field Values

error

private boolean error
Indicates whether an error has been occurred.


errorMessage

private java.lang.String errorMessage
It is an error message which has a short description of the error.


bytesJPIPMessageBody

private long bytesJPIPMessageBody
Is used to save the amount of received bytes in the JPIP message body.


bytesJPIPMessageHeader

private long bytesJPIPMessageHeader
Is used to save the amount of received bytes in the JPIP message header.


userAgent

private java.lang.String userAgent
Contains the value of the HTTP user-agent feature.


logicalTarget

private ClientLogicalTarget logicalTarget

clientCache

private ClientCacheManagement clientCache
Contains the client cache.


requestViewWindow

private ViewWindowField requestViewWindow
Contains the view window requested by the client application.


log

private CADILog log
Is used to log the client messages.


httpClient

private HTTPClient httpClient
An object to send the request and receive the server response.


keepAlive

private boolean keepAlive
Indicates whether the HTTP connection to remote server are persistents.


jpipRequestEncoder

private JPIPRequestEncoder jpipRequestEncoder
Object to encode the JPIP request parameters.


jpipMessageDecoder

private JPIPMessageDecoder jpipMessageDecoder
Object used to decode the JPIP response messages.


jpipResponseFields

private JPIPResponseFields jpipResponseFields
This object contains the JPIP response parameters.


responseViewWindow

private ViewWindowField responseViewWindow
Contains the request view window which has been modified by the remote server if any of the parameters has been modified.


clientHostName

private java.lang.String clientHostName
Contains the local host name.


target

private java.lang.String target
Documentar: variables que mantienen el estado del cliente jpip. Se actualizan con los valores que proporciona la aplicacion grafica y tambien con los que se reciben del servidor JPIP. Poner comentario referenciando a la clase en la que estan definidas variables con la misma funcion (JPIPRequestFields y JPIPResponseFields)


subtarget

private int[] subtarget

tid

private java.lang.String tid

cid

private java.lang.String cid

cnew

private int[] cnew

cclose

private java.lang.String[] cclose

qid

private int qid

host

private java.lang.String host

transport

private int transport

path

private java.lang.String path

port

private int port

auxport

private int auxport

len

private int len

quality

private int quality

type

private int type
Indicates the image return type which it is being used.

Allowed values, see ImageReturnTypes


server

private java.lang.String server
Is the server name where logical targets are located.


proxyServer

private java.lang.String proxyServer
Is the proxy server used to connect to the server.


proxyPort

private int proxyPort

initStageTime

private long initStageTime
Used for verbose information (time for stage).

0 is initial time.


initTime

private long initTime
Used for verbose information (total time).

0 is initial time.


downloadedBytes

private long[] downloadedBytes
An one-dimmensional array which contains a log of the last amount of downloaded data. It is used to estimate the download rate.

This attribute is related to downloadsTimes attribute.


downloadsTimes

private long[] downloadsTimes
An one-dimmensional array which contains the time when the saved data at downloadedBytes were downloaded. Both attributes are used to estimate the download read.


stopWatch

private StopWatch stopWatch
Constructor Detail

Client

public Client(ImageData imageData)
Constructor.

Parameters:
imageData -
Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

start

public void start()
Not available yet. It will be available when this class works as a thread.


stop

public void stop()
Not available yet. It will be available when this class works as a thread.


getState

public int getState()
Not available yet. It will be available when this class works as a thread.

Returns:
the state of the thread.

isError

public boolean isError()
Not available yet. It will be available when this class works as a thread.

Returns:
the error.

getErrorMessage

public java.lang.String getErrorMessage()
Not available yet. It will be available when this class works as a thread.

Returns:
the errorMessage.

setServerAndTarget

public void setServerAndTarget(java.lang.String server,
                               int port,
                               java.lang.String target)
                        throws ErrorException
Sets the server name and port where the logical targets are located. Therefore, the logical target name is required because it connects to the server and it requests the main header of the logical target.

Parameters:
server - definition in server
port - definition in port
target - definition in target
Throws:
ErrorException - this exception can be thrown due to:
  • There is not connection to the remote server.
  • The port in the remote server is wrong.
  • The requested target is not available in the server.

setServerAndTarget

public void setServerAndTarget(java.lang.String server,
                               int port,
                               java.lang.String target,
                               long maxTargetLength)
                        throws ErrorException
Sets the server name and port where the logical targets are located. Therefore, the logical target name is required because it connects to the server and it requests the main header of the logical target.

Parameters:
server - definition in server
port - definition in port
target - definition in target
maxTargetLength - definition in maxTargetLength
Throws:
ErrorException - this exception can be thrown due to:
  • There is not connection to the remote server.
  • The port in the remote server is wrong.
  • The requested target is not available in the server.

setServerAndTarget

public void setServerAndTarget(java.lang.String server,
                               int port,
                               java.lang.String target,
                               java.lang.String proxyServer,
                               int proxyPort)
                        throws ErrorException
Sets the server name and port where the logical targets are located, as well as the proxy and port that will be used.

Parameters:
server -
port -
target -
proxyServer -
proxyPort -
Throws:
ErrorException

setServerAndTarget

public void setServerAndTarget(java.lang.String server,
                               int port,
                               java.lang.String target,
                               java.lang.String proxyServer,
                               int proxyPort,
                               long maxTargetLength)
                        throws ErrorException
Parameters:
server -
port -
target -
proxyServer -
proxyPort -
maxTargetLength -
Throws:
ErrorException

getTarget

public void getTarget()
               throws ErrorException,
                      java.lang.IllegalAccessException
This method fetchs a logical target.

Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(long maxTargetLength)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target at a fixed length. A positive value of the maxTargetLength parameters means a maximum limit for the compressed logical target; and a negative value means the maximum is unlimited.

Parameters:
maxTargetLength - maximum length of the compressed target. A positive value means a maximum, and a negative value means unlimited.
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(long maxTargetLength,
                      int layers,
                      int quality)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target at a fixed length. A positive value of the maxTargetLength parameters means a maximum limit for the compressed logical target; and a negative value means the maximum is unlimited.

Parameters:
maxTargetLength - maximum length of the compressed target. A positive value means a maximum, and a negative value means unlimited.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(java.lang.String requestURI)
               throws ErrorException
Get the target which is identified by the URI requestURI

Parameters:
requestURI - is the URI to locate the target.
Throws:
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[] components,
                      long maxTargetLength)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
components - is an one-dimension array with the component indeces.
maxTargetLength - definition in maxTargetLength
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[] components,
                      int[] fsiz,
                      int[] roff,
                      int[] rsiz,
                      long maxTargetLength)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
components - is an one-dimension array with the component indeces.
fsiz - definition in ViewWindowField.fsiz.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
maxTargetLength - definition in maxTargetLength
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[] components,
                      int resolutionLevel,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
components - is an one-dimension array with the component indeces.
resolutionLevel - is the desired resolution level of the target.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[][] comps,
                      int resolutionLevel,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
comps - definition in ViewWindowField.comps.
resolutionLevel - is the desired resolution level of the target.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[] components,
                      int resolutionLevel,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality,
                      long maxTargetLength)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
components - is an one-dimension array with the component indeces.
resolutionLevel - is the desired resolution level of the target.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
maxTargetLength - definition in maxTargetLength
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[][] comps,
                      int resolutionLevel,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality,
                      long maxTargetLength)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
comps - definition in ViewWindowField.comps.
resolutionLevel - is the desired resolution level of the target.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
maxTargetLength - definition in maxTargetLength
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[] components,
                      int[] fsiz,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality,
                      int round)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
components - is an one-dimension array with the component indeces.
fsiz - definition in ViewWindowField.fsiz.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[][] comps,
                      int[] fsiz,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality,
                      int round)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
comps - definition in ViewWindowField.comps.
fsiz - definition in ViewWindowField.fsiz.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[] components,
                      int[] fsiz,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality,
                      int round,
                      long maxTargetLength)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
components - is an one-dimension array with the component indeces.
fsiz - definition in ViewWindowField.fsiz.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
maxTargetLength - definition in maxTargetLength
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getTarget

public void getTarget(int[][] comps,
                      int[] fsiz,
                      int[] roff,
                      int[] rsiz,
                      int layers,
                      int quality,
                      int round,
                      long maxTargetLength)
               throws java.lang.IllegalAccessException,
                      ErrorException
This method fetchs a logical target defined by the method input parameters.

Parameters:
comps - definition in ViewWindowField.comps.
fsiz - definition in ViewWindowField.fsiz.
roff - definition in ViewWindowField.roff.
rsiz - definition in ViewWindowField.rsiz.
layers - definition in ViewWindowField.layers.
quality - definition in JPIPResponseFields.quality.
maxTargetLength - definition in maxTargetLength
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the target (requestURI) cannot be fetched from the server, or the delivery data cannot be decompressed correctly.

getThumbnail

public ImageData getThumbnail(int thumbnailWidth,
                              int thumbnailHeight,
                              int imageDataType)
                       throws java.lang.IllegalAccessException,
                              ErrorException
Gets a thumbnail image of the actual logical target. The thumbnail size is fitted to the size parameters throght a rounding down.

This method must be called after the setServerAndTarget(String, int, String) method had been called. Otherwise, a IllegalAccessException will be thrown.

Parameters:
thumbnailWidth - width of the thumbnail image.
thumbnailHeight - height of the thumbnail image.
imageDataType - definition in ImageData.dataType.
Returns:
the thumbnail image.
Throws:
java.lang.IllegalAccessException - if the method is called before the setServerAndTarget(String, int, String).
ErrorException - if the thumbnail compressed image cannot be got from the server, or the delivery data cannot be decompressed.

setClientProperties

public void setClientProperties(ClientProperties clientProperties)
Sets the JPIP client properties. The clientProperties attribute is an object which wraps the values of the properties.

Parameters:
clientProperties - an object with the client properties.

closeLogicalTarget

public void closeLogicalTarget()
Release all data about the current logical target. Closing the logical target does not closes the sesion, if sessions are being used.


closeSession

public boolean closeSession()
                     throws ErrorException
Closes the session with the server. Note that data of all logical targets belonging to the current session are also removed, as well the session with the remote server is closed too.

Returns:
true if the session has been closed without any problem. Otherwise, returns false.
Throws:
ErrorException - it an error occurs while the session is being closed.

setUseSession

public void setUseSession(boolean useSession)
Indicates whether sessions will be used in the JPIP connections.

Parameters:
useSession - true if sessions will be used. false if it will not.

setUseHTTPSession

public void setUseHTTPSession(boolean useHTTPSession)
Sets the useHTTPSession attribute.

Parameters:
useHTTPSession - useHTTPSession.

setUseHTTPTCPSession

public void setUseHTTPTCPSession(boolean useHTTPTCPSession)
Sets the useHTTPTCPSession attribute

Parameters:
useHTTPTCPSession - useHTTPTCPSession.

setKeepAlive

public void setKeepAlive(boolean keepAlive)
Sets the keepAlive attribute.

Parameters:
keepAlive - see keepAlive.

reuseCache

public void reuseCache(boolean reuseCache)
Sets if the client cache must be used. If client cache mustn't be used, every time a new target is requested all previously saved data will be discarded.

Parameters:
reuseCache - true if the cache is reseted every time a new target is requested.

setCacheType

public void setCacheType(int cacheType,
                         int cacheSubtype)

setManagementPolicy

public final void setManagementPolicy(int managementPolicy)
Definition in CADI.Client.Cache.ClientCache#setManagementPolicy(int).

Parameters:
managementPolicy - definition in managementPolicy.

setMaxCacheSize

public final void setMaxCacheSize(long maxCacheSize)
Definition in CADI.Client.Cache.ClientCache#setMaxCacheSize(long).

Parameters:
maxCacheSize - is the maximum size (in bytes) allowed for the cached data. Only positive values are allowed, a value of 0 means unlimited.

setLogFile

public final void setLogFile(java.lang.String logFileName)
Sets the file name where the log will be done. If the logFileName parameter is null, logs are printed out the default output in plain text.

Parameters:
logFileName - file name of the log file.

setLogFile

public final void setLogFile(java.lang.String logFileName,
                             boolean useXMLFormat)
Sets the file name where the log will be done. If the logFileName parameter is null, logs are printed out the default output.

Parameters:
logFileName - file name of the log file.
useXMLFormat - if true logs are printed out following a XML format. Otherwise, plain text is used.

setLogEnabled

public final void setLogEnabled(boolean enabled)
Sets the log enabled or disabled.

Parameters:
enabled - if true, logs are enabled. Otherwise, logs are disabled.

setLogLevel

public final void setLogLevel(int logLevel)
Sets the log level.

Parameters:
logLevel -

getTargetDescription

public final java.lang.String getTargetDescription()
This method returns a detailed description of the last decoded logical target. This description is delivery as a html table with the key in the first column and the value in the second one. If none image has been decoded, a null pointer is returned.

Returns:
an html table description of the logical target. If none logical target has been decoded yet, a null pointer is returned.

getURI

public final java.lang.String getURI()
Returns the last requested URI.

Returns:
the last requested URI.

getServer

public final java.lang.String getServer()
Return the sever name of the latest connection.

Returns:
server name of the latest connection.

getPort

public final int getPort()
Return the port number of the server.

Returns:
the port number.

getTargetName

public java.lang.String getTargetName()
Return the latest requested target name.

Returns:
the latest requested target name.

getSpeed

public float getSpeed()
Returns the download's speed average.

Returns:
the download's speed average.

getDownloadedBytes

public long getDownloadedBytes()
Returns the downloaded total bytes for the actual logical target.

Returns:
the total downloaded bytes.

resetBytesJPIPMessages

public void resetBytesJPIPMessages()
Sets the JPIP message counter to 0.


getBytesJPIPMessageHeader

public long getBytesJPIPMessageHeader()
Returns the bytesJPIPMessageHeader attribute.

Returns:
the bytesJPIPMessageHeader attribute.

getBytesJPIPMessageBody

public long getBytesJPIPMessageBody()
Returns the bytesJPIPMessageBody attribute.

Returns:
the bytesJPIPMessageBody attribute.

isKeepAlive

public boolean isKeepAlive()
Returns the keepAlive attribute.

Returns:
the keepAlive attribute.

isUseSession

public boolean isUseSession()
Returns the useSession attribute.

Returns:
the useSession attribute.

isUseHTTPSession

public boolean isUseHTTPSession()
Returns the useHTTPSession attribute.

Returns:
the useHTTPSession attribute.

isUseHTTPTCPSession

public boolean isUseHTTPTCPSession()
Returns the useHTTPTCPSession attribute

Returns:
the useHTTPTCPSession attribute.

getManagementPolicy

public int getManagementPolicy()
Definition in CADI.Client.Cache.ClientCache#getManagementPolicy()

Returns:
definition in CADI.Client.Cache.ClientCache#getManagementPolicy()

getMaxCacheSize

public long getMaxCacheSize()
Definition in CADI.Client.Cache.ClientCache#getMaxCacheSize()

Returns:
definition in CADI.Client.Cache.ClientCache#getMaxCacheSize()

isLogEnabled

public boolean isLogEnabled()
Definition in CADILog.isEnabled().

Returns:
definition in CADILog.isEnabled().

useLogXMLFormat

public boolean useLogXMLFormat()
Definition in CADILog.useXMLFormat().

Returns:
definition in CADILog.useXMLFormat().

getLogFileName

public java.lang.String getLogFileName()
Definition in CADILog.getFileName().

Returns:
definition in CADILog.getFileName().

getLogLevel

public int getLogLevel()
Definition in CADILog.getLogLevel().

Returns:
definition in CADILog.getLogLevel().

getJPIPStreamType

public int getJPIPStreamType()
Returns the JPIP-stream media type with is beind used. Allowed values are: 1 - for JPP-stream 2 - for JPT-stream

Returns:

saveCache

public void saveCache(java.lang.String fileName)
Parameters:
fileName -

loadCache

public void loadCache(java.lang.String fileName)
Parameters:
fileName -

setUserAgent

public void setUserAgent(java.lang.String userAgent)
This method sets the HTTP's user agent header.

Parameters:
userAgent -

toString

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

list

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

Parameters:
out - an output stream.

getMainHeader

private void getMainHeader()
                    throws ErrorException
Gets the main header of the logical target.

Throws:
ErrorException - if an error occurs while main header is being fetched or received data cannot be decompressed correctly.

getWindow

private void getWindow(ViewWindowField viewWindow)
                throws ErrorException
Get the target target window of interest.

Parameters:
viewWindow - the target Window Of Interest to fetch. throws WarningException if an error occurs fetching the WOI or received data cannot be decompressed
Throws:
ErrorException

getRequest

private void getRequest(java.lang.String requestURI)
                 throws WarningException
Get the target which is identified by the URI requestURI

Parameters:
requestURI - the URI to locate the logical target. throws WarningException if an error occurs fetching the target or received data cannot be decompressed
Throws:
WarningException

componentsToRangeOfComponents

private int[][] componentsToRangeOfComponents(int[] comps)
This method moves the number of components from an array structure to an array of ranges.

Parameters:
comps - an array with the component number.
Returns:
an array of ranges.

updateReceivedBytesAndTimes

private void updateReceivedBytesAndTimes(long bytes,
                                         long time)
This method updates the downloadedBytes and downloadsTimes attributes with new new values which are parssed as input parameters.

Parameters:
bytes - the new value to be added in the downloadedBytes attribute.
time - the new value to be added in the downloadsTimes attribute.

calculateAverageWeighted

public static float calculateAverageWeighted(long[] bytes,
                                             long[] times)
Calculates the average of bytes per second. The average is weighted following a gaussian distribution.

Parameters:
bytes - is an one-dimensional array with the amount of bytes.
times - is an one-dimensional array with the time where bytes was sent. It is expressed in miliseconds. The first index is when the first dada was sent, and the last one is the most most recently time.
Returns:
the average of bytes per second.

showTimeMemory

private void showTimeMemory(java.lang.String stage)
Show some time and memory usage statisticals.

Parameters:
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)