CADI.Client.Cache
Class ClientCacheManagement

java.lang.Object
  extended by CADI.Common.Cache.DataBinsCacheManagement
      extended by CADI.Client.Cache.ClientCacheManagement

public class ClientCacheManagement
extends DataBinsCacheManagement

Version:
1.0 2009/09/08
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  long cacheSize
          This attributes is used to save the size of the cached data.
private  int codestreamType
          1 - JPC 2 - JP2 3 - JPK 4 - JPX
private  java.util.ArrayList<java.lang.Long> dataBinsList
          Is a list used to save the data-bins identifiers.
static int FIFO
           
private  JPCParameters jpcParameters
          Definition in JPCParameters.
static int LRU
           
protected  int managementPolicy
          Indicates which is the cache management policy.
protected  long maxCacheSize
          Indicates which is the maximum size (in bytes) which is allowed for the cached data.
static int NONE
           
private  java.util.ArrayList<java.lang.Long> removedDataBins
          Contains the data-bins which has been removed from the cache.
 
Fields inherited from class CADI.Common.Cache.DataBinsCacheManagement
codParameters, EXPLICIT_FORM, IMPLICIT_FORM, INDEX_RANGE, mainHeaderDataBin, NUMBER_OF_BYTES, NUMBER_OF_LAYERS, precinctsDataBins, sizParameters, type, WILDCARD
 
Constructor Summary
ClientCacheManagement()
           
ClientCacheManagement(int codestreamType)
           
ClientCacheManagement(java.lang.String fileName)
          This constructor must be used if the client cache is mapped to a file.
 
Method Summary
 void addJPIPMessage(byte[] jpipMessageBody, int classIdentifier, long inClassIdentifier, boolean completeDataBin, long offset, int aux)
           
 void addJPIPMessage(JPIPMessage jpipMessage)
           
private  byte[] ArrayListToArray(java.util.ArrayList<byte[]> src)
           
 int getCodestreamType()
           
 byte[] getDataBin(long inClassIdentifier)
          Returns the byte array of the data-bin idientified by inClassIdentifier.
 int getManagementPolicy()
          Returns the managementPolicy attribute.
 long getMaxCacheSize()
          Returns the maxCacheSize attribute.
 boolean isReady()
          Check if the cache parameters has been initialized.
 void list(java.io.PrintStream out)
          Prints this cache out to the specified output stream.
 void manage()
           
private static void printByteStream(byte[] buffer)
          Useful method for printing out a ByteStream.
 void reset()
          Sets the attributes to its initial values.
 void setJPCParameters(JPCParameters jpcParameters)
          Sets the jpcParameters attribute.
 void setManagementPolicy(int managementPolicy)
          Sets the managementPolicy attribute.
 void setMaxCacheSize(long maxCacheSize)
          Sets the maxCacheSize attribute.
 java.lang.String toString()
           
private  void updateLists(int classIdentifier, long inClassIdentifier)
           
 
Methods inherited from class CADI.Common.Cache.DataBinsCacheManagement
explicitForm, explicitForm, getCacheDescriptor, getDataBin, getMainHeader, getPrecinctDataBin, getPrecinctDataBins, implicitForm, isCompleteMainHeader, isInCache, setSIZAndCODParamters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jpcParameters

private JPCParameters jpcParameters
Definition in JPCParameters.


maxCacheSize

protected long maxCacheSize
Indicates which is the maximum size (in bytes) which is allowed for the cached data.


managementPolicy

protected int managementPolicy
Indicates which is the cache management policy. If none policy has been set, the cache size is no limited and it can be augmented indefinitely.

Two cache management policies has been defined. LRU (Last Recent Used): value, see LRU FIFO (First In, First Out): value see FIFO


NONE

public static final int NONE
See Also:
Constant Field Values

LRU

public static final int LRU
See Also:
Constant Field Values

FIFO

public static final int FIFO
See Also:
Constant Field Values

dataBinsList

private java.util.ArrayList<java.lang.Long> dataBinsList
Is a list used to save the data-bins identifiers. It can be used either a LRU or a FIFO.


removedDataBins

private java.util.ArrayList<java.lang.Long> removedDataBins
Contains the data-bins which has been removed from the cache. It is useful to get a list of the removed data-bins to send the server.


cacheSize

private long cacheSize
This attributes is used to save the size of the cached data. Its value must be shorter than maxCacheSize.


codestreamType

private int codestreamType
1 - JPC 2 - JP2 3 - JPK 4 - JPX

Constructor Detail

ClientCacheManagement

public ClientCacheManagement()

ClientCacheManagement

public ClientCacheManagement(int codestreamType)

ClientCacheManagement

public ClientCacheManagement(java.lang.String fileName)
This constructor must be used if the client cache is mapped to a file.

OBS:It is not being used yet.

Parameters:
fileName -
Method Detail

setManagementPolicy

public final void setManagementPolicy(int managementPolicy)
Sets the managementPolicy attribute.

Parameters:
managementPolicy - definition in managementPolicy.

getManagementPolicy

public final int getManagementPolicy()
Returns the managementPolicy attribute.

Returns:
the managementPolicy attribute.

setJPCParameters

public void setJPCParameters(JPCParameters jpcParameters)
Sets the jpcParameters attribute.

Parameters:
jpcParameters - definition in jpcParameters.

getCodestreamType

public int getCodestreamType()
Returns:

setMaxCacheSize

public final void setMaxCacheSize(long maxCacheSize)
Sets the maxCacheSize attribute.

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

getMaxCacheSize

public final long getMaxCacheSize()
Returns the maxCacheSize attribute.

Returns:
the maxCacheSize attribute.

addJPIPMessage

public void addJPIPMessage(JPIPMessage jpipMessage)
Overrides:
addJPIPMessage in class DataBinsCacheManagement

addJPIPMessage

public final void addJPIPMessage(byte[] jpipMessageBody,
                                 int classIdentifier,
                                 long inClassIdentifier,
                                 boolean completeDataBin,
                                 long offset,
                                 int aux)
Overrides:
addJPIPMessage in class DataBinsCacheManagement
Parameters:
jpipMessageBody - definition in JPIPMessage.messageBody
classIdentifier - definition in CADI.Common.Cache.CacheDescriptor#Class
inClassIdentifier - definition in JPIPMessageHeader.inClassIdentifier
completeDataBin - definition in JPIPMessageHeader.isLastByte
offset - definition in JPIPMessageHeader.msgOffset
aux - definition in JPIPMessageHeader.Aux

getDataBin

public final byte[] getDataBin(long inClassIdentifier)
Returns the byte array of the data-bin idientified by inClassIdentifier. If the data-bin is not in the cache, a null pointer is returned.

Parameters:
inClassIdentifier - definition in JPIPMessageHeader.inClassIdentifier
Returns:
the byte array of the data-bin. A null pointer if the data-bin is not in the cache.

reset

public void reset()
Sets the attributes to its initial values.

Overrides:
reset in class DataBinsCacheManagement

isReady

public final boolean isReady()
Check if the cache parameters has been initialized. If it was, the cache is ready. Otherwise, it is not ready.

Returns:
true if the cache is ready. Otherwise, return false.

manage

public void manage()

toString

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

list

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

Overrides:
list in class DataBinsCacheManagement
Parameters:
out - an output stream.

updateLists

private void updateLists(int classIdentifier,
                         long inClassIdentifier)
Parameters:
classIdentifier -
inClassIdentifier -

ArrayListToArray

private byte[] ArrayListToArray(java.util.ArrayList<byte[]> src)

printByteStream

private static void printByteStream(byte[] buffer)
Useful method for printing out a ByteStream. Only for debugging purposes.

Parameters:
buffer - the byte array to be printed.


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)