AddressSpace library v1.0 beta

mmap
Class SwappingPage

java.lang.Object
  |
  +--mmap.Page
        |
        +--mmap.SwappingPage

public class SwappingPage
extends Page


Field Summary
protected  boolean dirty
          The memory image differs from the file image.
protected  long position
          The position of the page inside it's swap.
protected  java.io.RandomAccessFile swapper
          The swap where the page resides.
 
Fields inherited from class mmap.Page
data, filler, interStep, pageSize
 
Constructor Summary
SwappingPage(java.io.RandomAccessFile raf)
          Create a new page inside a swap.
SwappingPage(java.io.RandomAccessFile raf, long offset)
          Create a new page inside a swap.
SwappingPage(java.io.RandomAccessFile raf, long offset, boolean toBeRead)
          Create a new page inside a swap.
 
Method Summary
 long getPosition()
          Retrieve the position of the page inside the swap.
 void setDirty()
          Set the page as dirty.
 void setPosition(int loc)
          Relocate the page inside the swap.
 void sync()
          Synchronize the memory image and the disk image.
 int write(int offset, byte v)
          Write a byte in the page.
 int write(int offset, byte[] buffer)
          Write an array of bytes to the page.
 int write(int offset, byte[] buffer, int len)
          Write an array of bytes to the page.
 int write(int offset, byte[] buffer, int len, int boffset)
          Write an array of bytes to the page.
 int writeInt(int offset, int value)
          Write an integer to the page.
 int writeLong(int offset, long value)
          Write a long integer to the page.
 int writeShort(int offset, short value)
          Write a short int to the page.
 void zeroFill()
          Blank a page.
 
Methods inherited from class mmap.Page
dump, getData, isAllZero, read, read, read, read, readInt, readLong, readShort, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

position

protected long position
The position of the page inside it's swap.

swapper

protected java.io.RandomAccessFile swapper
The swap where the page resides.

dirty

protected boolean dirty
The memory image differs from the file image.
Constructor Detail

SwappingPage

public SwappingPage(java.io.RandomAccessFile raf)
             throws java.io.IOException
Create a new page inside a swap.
The newly created page will be located to the end of the file.
Parameters:
raf - the RandomAccessFile to be used as the swap. connected to the page.

SwappingPage

public SwappingPage(java.io.RandomAccessFile raf,
                    long offset,
                    boolean toBeRead)
             throws java.io.IOException
Create a new page inside a swap.
The newly created page will be located in the middle of the swap.
It's possible that the memory image is not yet the real content of the page.
This is the case when we are retrieving an already existing page.
In the second case we are instantiating a new page that will occupy an old "trashed" position, so, the content have to be blanked.
Parameters:
raf - the RandomAccessFile to be used as the swap.
offset - the location of the page inside the swap.
toBeRead - flag that is true if the page has to be read from the swap, false if the content in the swap has to be lost and replaced by the page one.

SwappingPage

public SwappingPage(java.io.RandomAccessFile raf,
                    long offset)
             throws java.io.IOException
Create a new page inside a swap.
The newly created page will be located in the middle of the swap.
We are retrieving an already existing page.
Parameters:
raf - the RandomAccessFile to be used as the swap.
offset - the location of the page inside the swap.
Method Detail

zeroFill

public void zeroFill()
Blank a page.
The content of the page will be all zero bytes.
The page will be also marked as dirty.
Overrides:
zeroFill in class Page

getPosition

public long getPosition()
Retrieve the position of the page inside the swap.
Returns:
the position of the page.

setPosition

public void setPosition(int loc)
Relocate the page inside the swap.
The content will not change and the page will be also marked as dirty.
Parameters:
loc - the new location of the page.

setDirty

public void setDirty()
Set the page as dirty.
This should means that memory image differs from disk image.

sync

public void sync()
          throws java.io.IOException
Synchronize the memory image and the disk image.
The memory image is written to the file.
Throws:
java.io.IOException - if problems occurs when writing to the file.

write

public int write(int offset,
                 byte v)
Write a byte in the page.
Overrides:
write in class Page
Parameters:
offset - the location of the byte to write.
v - the value to write.
Returns:
the number of bytes written (1).

write

public int write(int offset,
                 byte[] buffer)
Write an array of bytes to the page.
The array is written until the end of the page is reached.
Overrides:
write in class Page
Parameters:
offset - the location of the bytes to write.
buffer - the buffer to be written.
Returns:
the number of bytes written

write

public int write(int offset,
                 byte[] buffer,
                 int len)
Write an array of bytes to the page.
The array is written until a specified amount of bytes are transferred or the end of the page is reached.
Overrides:
write in class Page
Parameters:
offset - the location of the bytes to write.
buffer - the buffer to be written.
len - the number of bytes to write.
Returns:
the number of bytes written.

write

public int write(int offset,
                 byte[] buffer,
                 int len,
                 int boffset)
Write an array of bytes to the page.
The array is written starting from a given offset until a specified amount of bytes are transferred or the end of the page is reached.
Overrides:
write in class Page
Parameters:
offset - the location of the bytes to write.
buffer - the buffer to be written.
len - the number of bytes to write.
boffset - the offset inside the buffer.
Returns:
the number of bytes written.

writeShort

public int writeShort(int offset,
                      short value)
               throws NotAlignedPointer
Write a short int to the page.
Overrides:
writeShort in class Page
Parameters:
offset - the location of the page where the data is located.
Returns:
the number of bytes written to the page.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

writeInt

public int writeInt(int offset,
                    int value)
             throws NotAlignedPointer
Write an integer to the page.
Overrides:
writeInt in class Page
Parameters:
offset - the location of the page where the data is located.
Returns:
the number of bytes written to the page.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

writeLong

public int writeLong(int offset,
                     long value)
              throws NotAlignedPointer
Write a long integer to the page.
Overrides:
writeLong in class Page
Parameters:
offset - the location of the page where the data is located.
Returns:
the number of bytes written to the page.
Throws:
NotAlignedPointer - exception if the location is aligned with data size.

Help is irrilevant
You will be assimilated!

v1.0 beta by Dario Maggiorini