storage.primitiveStorage
Class PrimitiveStorageManager

java.lang.Object
  extended bystorage.primitiveStorage.PrimitiveStorageManager

public final class PrimitiveStorageManager
extends java.lang.Object

This class is used to manage the operatios of a primitive storage component. The primitive storage component controls the access to secundary storage manager (using chunks) and the intermediate memory (using a buffer). In the primitive storage component the page is the minimum storage unit.


Nested Class Summary
 class PrimitiveStorageManager.Chunk
          A chunks is a part of secundary storage.
 class PrimitiveStorageManager.ChunkNumberIterator
          This class is used to retrieve the used chunk numbers.
 class PrimitiveStorageManager.ChunksTable
          This class represents the chunk's table, i.e. a set of number-chunk pairs.
 class PrimitiveStorageManager.FixedChunk
          Fixed chunks are used to storage information in files which size is considered fixed.
 class PrimitiveStorageManager.FlexibleChunk
          Flexible chunks are used to storage information in files which size can grow or decrease.
 
Field Summary
static int CLOCK_ALGORITHM
          Represents the Clock or LRU with second chance replace algorithm.
static int DEFAULT_PAGE_SIZE
          The default page size if other is not specified.
static int FIFO_ALGORITHM
          Represents the FIFO (First In First Out) replace algorithm.
static int LIFO_ALGORITHM
          Represents the LIFO (Last In First Out) replace algorithm.
static int LRU_ALGORITHM
          Represents the LRU (Least Recent Used) replace algorithm.
static long MAX_CHUNK_NUMBER
          The maximum number which a chunk can be associated.
static long MAX_CHUNK_SIZE
          The maximum size of a chunk.
static int MIN_PAGE_SIZE
          The manimum size of a page.
static int MRU_ALGORITHM
          Represents the MRU (Most Recent Used) replace algorithm.
 
Constructor Summary
PrimitiveStorageManager()
          Constructs a primitive storage manager with the default page size and with no actived buffer.
PrimitiveStorageManager(int pageSize)
          Constructs a primitive storage manager with a specific page size (in bytes) and with no actived buffer.
PrimitiveStorageManager(int pageSize, int bufferSize)
          Constructs a primitive storage manager with a specific page size (in bytes), a specific buffer size (in bytes) and the LRU replace algorithm.
PrimitiveStorageManager(int pageSize, int bufferSize, int replaceAlgorithm)
          Constructs a primitive storage manager with a specific page size (in bytes), a specific buffer size (in bytes) and a specific replace algorithm.
 
Method Summary
 void activeBuffer()
          Actives the buffer.
 void closeAll()
          Closes all files used in this component.
 void deactiveBuffer()
          Deactives the buffer.
 PrimitiveStorageManager.Chunk getChunk(int chunkNumber)
          Returns the chunk with the specified number.
 PrimitiveStorageManager.ChunkNumberIterator getChunkNumbers()
          Returns the sequence of used chunk numbers.
 int getPageSize()
          Return the used page size (in bytes).
 void loadFixedChunk(int chunkNumber, java.io.File fileName, long offset, long maxSize)
          Load a fixed chunk with a specified chunk number.
 void loadFlexibleChunk(int chunkNumber, java.io.File fileName)
          Load a flexible chunk with a specified chunk number, the default maximum size and keeping the previous file's content.
 void loadFlexibleChunk(int chunkNumber, java.io.File fileName, boolean overwrite)
          Load a flexible chunk with a specified chunk number and the default maximum size.
 void loadFlexibleChunk(int chunkNumber, java.io.File fileName, long maxSize, boolean overwrite)
          Load a flexible chunk with a specified chunk number.
 void readPage(int chunkNumber, long pageNumber, byte[] b)
          Read a specified page in a specified chunk and copies its content in an array.
 void removeChunk(int chunkNumber)
          Removes the chunk with the specified number.
 void show()
          Shows information about this component.
 void transferAndClearBuffer()
          Copies the buffer's content to the secundary storage and clean the buffer.
 void transferBuffer()
          Copies the buffer's content to the secundary storage.
 void writePage(int chunkNumber, long pageNumber, byte[] b)
          Write a specified page in a specified chunk and copies its content from an array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CHUNK_SIZE

public static final long MAX_CHUNK_SIZE
The maximum size of a chunk.

See Also:
Constant Field Values

MIN_PAGE_SIZE

public static final int MIN_PAGE_SIZE
The manimum size of a page.

See Also:
Constant Field Values

MAX_CHUNK_NUMBER

public static final long MAX_CHUNK_NUMBER
The maximum number which a chunk can be associated.

See Also:
Constant Field Values

DEFAULT_PAGE_SIZE

public static final int DEFAULT_PAGE_SIZE
The default page size if other is not specified.

See Also:
Constant Field Values

LRU_ALGORITHM

public static final int LRU_ALGORITHM
Represents the LRU (Least Recent Used) replace algorithm.

See Also:
Constant Field Values

CLOCK_ALGORITHM

public static final int CLOCK_ALGORITHM
Represents the Clock or LRU with second chance replace algorithm.

See Also:
Constant Field Values

FIFO_ALGORITHM

public static final int FIFO_ALGORITHM
Represents the FIFO (First In First Out) replace algorithm.

See Also:
Constant Field Values

MRU_ALGORITHM

public static final int MRU_ALGORITHM
Represents the MRU (Most Recent Used) replace algorithm.

See Also:
Constant Field Values

LIFO_ALGORITHM

public static final int LIFO_ALGORITHM
Represents the LIFO (Last In First Out) replace algorithm.

See Also:
Constant Field Values
Constructor Detail

PrimitiveStorageManager

public PrimitiveStorageManager(int pageSize,
                               int bufferSize,
                               int replaceAlgorithm)
                        throws InvalidPageSizeException,
                               InvalidBufferCapacityException
Constructs a primitive storage manager with a specific page size (in bytes), a specific buffer size (in bytes) and a specific replace algorithm.


PrimitiveStorageManager

public PrimitiveStorageManager(int pageSize,
                               int bufferSize)
                        throws InvalidPageSizeException,
                               InvalidBufferCapacityException
Constructs a primitive storage manager with a specific page size (in bytes), a specific buffer size (in bytes) and the LRU replace algorithm.


PrimitiveStorageManager

public PrimitiveStorageManager(int pageSize)
                        throws InvalidPageSizeException
Constructs a primitive storage manager with a specific page size (in bytes) and with no actived buffer.


PrimitiveStorageManager

public PrimitiveStorageManager()
Constructs a primitive storage manager with the default page size and with no actived buffer.

Method Detail

activeBuffer

public void activeBuffer()
Actives the buffer.


deactiveBuffer

public void deactiveBuffer()
                    throws java.io.IOException
Deactives the buffer.

Throws:
java.io.IOException

loadFixedChunk

public void loadFixedChunk(int chunkNumber,
                           java.io.File fileName,
                           long offset,
                           long maxSize)
                    throws InvalidChunkNumberException,
                           AlreadyExistingChunkNumberException,
                           InvalidChunkSizeException,
                           InvalidChunkOffsetException,
                           UnaddressableChunkException,
                           java.io.FileNotFoundException
Load a fixed chunk with a specified chunk number.

Parameters:
chunkNumber - The number which the chunk will be identified.
fileName - The file to be used by the chunk.
offset - The offset in the file when the chunk starts.
maxSize - The maximun size that the chunk can occup.
Throws:
InvalidChunkNumberException
AlreadyExistingChunkNumberException
InvalidChunkSizeException
InvalidChunkOffsetException
UnaddressableChunkException
java.io.FileNotFoundException

loadFlexibleChunk

public void loadFlexibleChunk(int chunkNumber,
                              java.io.File fileName,
                              long maxSize,
                              boolean overwrite)
                       throws InvalidChunkNumberException,
                              AlreadyExistingChunkNumberException,
                              java.io.FileNotFoundException,
                              InvalidChunkSizeException,
                              java.io.IOException
Load a flexible chunk with a specified chunk number.

Parameters:
chunkNumber - The number which the chunk will be identified.
fileName - The file to be used by the chunk.
maxSize - The maximun size that the chunk can grow.
overwrite - If it is false the files's content will not be changed, if it is true the files's content will be erased.
Throws:
InvalidChunkNumberException
AlreadyExistingChunkNumberException
java.io.FileNotFoundException
InvalidChunkSizeException
java.io.IOException

loadFlexibleChunk

public void loadFlexibleChunk(int chunkNumber,
                              java.io.File fileName,
                              boolean overwrite)
                       throws InvalidChunkNumberException,
                              AlreadyExistingChunkNumberException,
                              java.io.FileNotFoundException,
                              java.io.IOException
Load a flexible chunk with a specified chunk number and the default maximum size.

Parameters:
chunkNumber - The number which the chunk will be identified.
fileName - The file to be used by the chunk.
overwrite - If it is false the files's content will not be changed, if it is true the files's content will be erased.
Throws:
InvalidChunkNumberException
AlreadyExistingChunkNumberException
java.io.FileNotFoundException
java.io.IOException

loadFlexibleChunk

public void loadFlexibleChunk(int chunkNumber,
                              java.io.File fileName)
                       throws InvalidChunkNumberException,
                              AlreadyExistingChunkNumberException,
                              java.io.FileNotFoundException
Load a flexible chunk with a specified chunk number, the default maximum size and keeping the previous file's content.

Parameters:
chunkNumber - The number which the chunk will be identified.
fileName - The file to be used by the chunk.
Throws:
InvalidChunkNumberException
AlreadyExistingChunkNumberException
java.io.FileNotFoundException

removeChunk

public void removeChunk(int chunkNumber)
                 throws NotExistingChunkNumberException
Removes the chunk with the specified number.

Parameters:
chunkNumber - The number of the chunk to be removed.
Throws:
NotExistingChunkNumberException

getChunk

public PrimitiveStorageManager.Chunk getChunk(int chunkNumber)
Returns the chunk with the specified number.

Parameters:
chunkNumber - The number of the chunk to be retrieved.
Returns:
The Chunk object requested.

transferBuffer

public void transferBuffer()
                    throws java.io.IOException
Copies the buffer's content to the secundary storage.

Throws:
java.io.IOException

transferAndClearBuffer

public void transferAndClearBuffer()
                            throws java.io.IOException
Copies the buffer's content to the secundary storage and clean the buffer.

Throws:
java.io.IOException

readPage

public void readPage(int chunkNumber,
                     long pageNumber,
                     byte[] b)
              throws NotExistingChunkNumberException,
                     PageNumberOutOfRangeException,
                     java.io.IOException
Read a specified page in a specified chunk and copies its content in an array.

Parameters:
chunkNumber - The chunk number in which the page is.
pageNumber - The number of the page inside the chunk.
b - The byte array in which the page's content will be copied.
Throws:
NotExistingChunkNumberException
PageNumberOutOfRangeException
java.io.IOException

writePage

public void writePage(int chunkNumber,
                      long pageNumber,
                      byte[] b)
               throws NotExistingChunkNumberException,
                      PageNumberOutOfRangeException,
                      java.io.IOException
Write a specified page in a specified chunk and copies its content from an array.

Parameters:
chunkNumber - The chunk number in which the page is.
pageNumber - The number of the page inside the chunk.
b - The byte array from which the page's content will be copied.
Throws:
NotExistingChunkNumberException
PageNumberOutOfRangeException
java.io.IOException

getPageSize

public int getPageSize()
Return the used page size (in bytes).


getChunkNumbers

public PrimitiveStorageManager.ChunkNumberIterator getChunkNumbers()
Returns the sequence of used chunk numbers.


closeAll

public void closeAll()
Closes all files used in this component.


show

public void show()
          throws java.io.IOException
Shows information about this component.

Throws:
java.io.IOException