storage.advancedStorage
Class AdvancedStorageManager.Segment.Space

java.lang.Object
  extended bystorage.advancedStorage.AdvancedStorageManager.Segment.Space
Enclosing class:
AdvancedStorageManager.Segment

public final class AdvancedStorageManager.Segment.Space
extends java.lang.Object

This class represents a space, a space is a set of units, each unit inside a space is identified by a unique number. Spaces provides methods for the free space management of units. Each space is mounted over a chunk (of primitive storage component).


Method Summary
 long findFirstFreeUnit()
          This function finds the first available unit in the space.
 long findFreeUnitCloseOf(long unitNumber)
          Find a free unit in the same page of a given unit.
 void freeUnit(long unitNumber)
          Sets a specific unit as free.
 int getChunkNumber()
          Returns the number (in primitive storage component) of the chunk in wich the space is mounted.
 long getMaxNumberOfUnits()
          Returns the maximun number of units that can be stored in the space.
 long getUsedSize()
          Returns the number of bytes that the space is really using.
 boolean isEmpty()
          Returns true if the space is empty, i.e. all is units are free.
 boolean isFreeUnit(long unitNumber)
          Checks if a unit is free.
 boolean isOccupiedUnit(long unitNumber)
          Checks if a unit is occupied.
 void occupUnit(long unitNumber)
          Sets a specific unit as occupied.
 void readUnit(long unitNumber, byte[] b, int off)
          Reads fully a unit.
 void readUnit(long unitNumber, int unitOffset, int length, byte[] b, int off)
          Reads partially a unit starting from an offset and reading a specific length.
 void reduce()
          Reduce the logic assigned space, later the physical space can be reduced.
 void writeUnit(long unitNumber, byte[] b, int off)
          Writes fully a unit.
 void writeUnit(long unitNumber, int unitOffset, int length, byte[] b, int off)
          Writes partially a unit starting from an offset and writing a specific length of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getChunkNumber

public int getChunkNumber()
Returns the number (in primitive storage component) of the chunk in wich the space is mounted.


getMaxNumberOfUnits

public long getMaxNumberOfUnits()
Returns the maximun number of units that can be stored in the space.


getUsedSize

public long getUsedSize()
                 throws PrimitiveStorageException,
                        IntermediateStorageException,
                        java.io.IOException
Returns the number of bytes that the space is really using.

Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException

isEmpty

public boolean isEmpty()
Returns true if the space is empty, i.e. all is units are free. Returns false otherwise.


readUnit

public void readUnit(long unitNumber,
                     int unitOffset,
                     int length,
                     byte[] b,
                     int off)
              throws PrimitiveStorageException,
                     IntermediateStorageException,
                     java.io.IOException,
                     UnitNumberOutOfRangeException,
                     InvalidUnitOffsetException,
                     OutOfUnitException
Reads partially a unit starting from an offset and reading a specific length.

Parameters:
unitNumber - The number of the unit inside the space.
unitOffset - The position of the unit from which the reading starts.
length - The number of bytes to be readed.
b - The byte array which the content of the readed unit will be stored.
off - The offset of b from which the readed content will be stored.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException
InvalidUnitOffsetException
OutOfUnitException

readUnit

public void readUnit(long unitNumber,
                     byte[] b,
                     int off)
              throws PrimitiveStorageException,
                     IntermediateStorageException,
                     java.io.IOException,
                     UnitNumberOutOfRangeException
Reads fully a unit.

Parameters:
unitNumber - The number of the unit inside the space.
b - The byte array which the content of the readed unit will be stored.
off - The offset of b from which the readed content will be stored.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException

writeUnit

public void writeUnit(long unitNumber,
                      int unitOffset,
                      int length,
                      byte[] b,
                      int off)
               throws PrimitiveStorageException,
                      IntermediateStorageException,
                      java.io.IOException,
                      UnitNumberOutOfRangeException,
                      InvalidUnitOffsetException,
                      OutOfUnitException
Writes partially a unit starting from an offset and writing a specific length of bytes.

Parameters:
unitNumber - The number of the unit.
unitOffset - The position of the unit from which the writing starts.
b - The byte array from which the units's content will be get.
off - The offset of b from which the unit's content will be get.
length - The number of bytes to be wrote.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException
InvalidUnitOffsetException
OutOfUnitException

writeUnit

public void writeUnit(long unitNumber,
                      byte[] b,
                      int off)
               throws PrimitiveStorageException,
                      IntermediateStorageException,
                      java.io.IOException,
                      UnitNumberOutOfRangeException
Writes fully a unit.

Parameters:
unitNumber - The number of the unit.
b - The byte array from which the units's content will be get.
off - The offset of b from which the unit's content will be get.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException

findFirstFreeUnit

public long findFirstFreeUnit()
                       throws PrimitiveStorageException,
                              IntermediateStorageException,
                              java.io.IOException,
                              InconsistentStorageStructureException
This function finds the first available unit in the space.

Returns:
The number of the first free unit, or -1 if there are not free units.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
InconsistentStorageStructureException

findFreeUnitCloseOf

public long findFreeUnitCloseOf(long unitNumber)
                         throws PrimitiveStorageException,
                                IntermediateStorageException,
                                java.io.IOException,
                                UnitNumberOutOfRangeException
Find a free unit in the same page of a given unit.

Parameters:
unitNumber - The number of the unit that has to be in the same page that the unit to be found.
Returns:
The number of the found free unit, or -1 if there are not free units in the same page that unitNumber.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException

occupUnit

public void occupUnit(long unitNumber)
               throws PrimitiveStorageException,
                      IntermediateStorageException,
                      java.io.IOException,
                      UnitNumberOutOfRangeException
Sets a specific unit as occupied.

Parameters:
unitNumber - The number of the unit to occup.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException

freeUnit

public void freeUnit(long unitNumber)
              throws PrimitiveStorageException,
                     IntermediateStorageException,
                     java.io.IOException,
                     UnitNumberOutOfRangeException
Sets a specific unit as free.

Parameters:
unitNumber - The number of the unit to free.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException

isOccupiedUnit

public boolean isOccupiedUnit(long unitNumber)
                       throws PrimitiveStorageException,
                              IntermediateStorageException,
                              java.io.IOException,
                              UnitNumberOutOfRangeException
Checks if a unit is occupied.

Parameters:
unitNumber - The number of the unit.
Returns:
true if the specified unit is occupied, false otherwise.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException

isFreeUnit

public boolean isFreeUnit(long unitNumber)
                   throws PrimitiveStorageException,
                          IntermediateStorageException,
                          java.io.IOException,
                          UnitNumberOutOfRangeException
Checks if a unit is free.

Parameters:
unitNumber - The number of the unit.
Returns:
true if the specified unit is free, false otherwise.
Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException
UnitNumberOutOfRangeException

reduce

public void reduce()
            throws PrimitiveStorageException,
                   IntermediateStorageException,
                   java.io.IOException
Reduce the logic assigned space, later the physical space can be reduced.

Throws:
PrimitiveStorageException
IntermediateStorageException
java.io.IOException