AddressSpace library v1.0 beta

Class LruQueue

java.lang.Object
  |
  +--LruQueue

public class LruQueue
extends java.lang.Object

This list keeps SwappingPages in a Last Recently Used order.

Version:
1.0 June 05 2000
Author:
Dario Maggiorini (dario@dsi.unimi.it)

Inner Class Summary
protected  class LruQueue.Entry
           
 
Field Summary
protected  IntHashtable allPages
          All the page in the queue in an hash fasion for fast retrieval.
protected  LruQueue.Entry cursor
          Actual examined entry of the queue.
protected  int howMany
          Number of pages in the queue.
protected  LruQueue.Entry last
          Last entry of the queue.
protected  int pageLimit
          Maximum number of page allowed before trashing the last one.
protected  LruQueue.Entry queue
          First entry of the queue.
protected  AddressSpace trasher
          AddressSpace object the page belongs to.
 
Constructor Summary
LruQueue(int pages)
          Create a new empty queue.
LruQueue(int pages, AddressSpace aSpace)
          Create a new empty queue associated to an AddressSpace.
 
Method Summary
 void add(int id, SwappingPage page)
          Add a page in the Queue
The page will be added as the mostly recent accessed (last entry).
It's known that the page is not already in the list.
If the page is already full the least recently used page is trashed from the queue.
 void clear()
          Clear the queue synchronizing and purging all the pages.
 void dump(java.io.OutputStream s)
          Dump the queue into a file in a string readable format.
 int getOccupiedSize()
          Get the number of the page in the queue.
 int getSize()
          Get the size of the queue in pages
 SwappingPage select(int id)
          Get a page from the Queue
The page will be also marked as the mostly recent accessed (last entry).
 void setSize(int size)
          Set the number of the page in that fit in the queue.
 void sync()
          Synchronize (update disk image) all the pages in the queue.
 java.lang.String toString()
          Convert the queue in a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

queue

protected LruQueue.Entry queue
First entry of the queue.

last

protected LruQueue.Entry last
Last entry of the queue.

cursor

protected LruQueue.Entry cursor
Actual examined entry of the queue.

allPages

protected IntHashtable allPages
All the page in the queue in an hash fasion for fast retrieval.

howMany

protected int howMany
Number of pages in the queue.

pageLimit

protected int pageLimit
Maximum number of page allowed before trashing the last one.

trasher

protected AddressSpace trasher
AddressSpace object the page belongs to.
Constructor Detail

LruQueue

public LruQueue(int pages)
Create a new empty queue.
Parameters:
pages - the number of pages in the queue

LruQueue

public LruQueue(int pages,
                AddressSpace aSpace)
Create a new empty queue associated to an AddressSpace.
Parameters:
pages - the number of pages in the queue
aSpace - the associated AddressSpace
Method Detail

add

public void add(int id,
                SwappingPage page)
         throws java.io.IOException
Add a page in the Queue
The page will be added as the mostly recent accessed (last entry).
It's known that the page is not already in the list.
If the page is already full the least recently used page is trashed from the queue.
Parameters:
id - an identificator that will be associated to the page
page - the page to add

select

public SwappingPage select(int id)
Get a page from the Queue
The page will be also marked as the mostly recent accessed (last entry).
Parameters:
id - the identificator of the page to retrieve
Returns:
SwappingPage a reference to the page or null if the page is not in list

sync

public void sync()
          throws java.io.IOException
Synchronize (update disk image) all the pages in the queue.
The queue order will not change.

clear

public void clear()
           throws java.io.IOException
Clear the queue synchronizing and purging all the pages.

getSize

public int getSize()
Get the size of the queue in pages
Returns:
int the number of SwappingPages that fits in the queue

getOccupiedSize

public int getOccupiedSize()
Get the number of the page in the queue.
Returns:
int the number of SwappingPages in the queue

setSize

public void setSize(int size)
             throws java.io.IOException
Set the number of the page in that fit in the queue.
Mazimum page limit will be changed, pages in the queue will be synched and purged out if the new limit will be smaller of the actual number of page in the queue.
Parameters:
size - the number of SwappingPages for the new queue size

toString

public java.lang.String toString()
Convert the queue in a string.
The string is made up the sequential page references in the queue from the least to the most recently used.
This function is intended for debugging porpuse.
Overrides:
toString in class java.lang.Object
Returns:
String a string representing the queue

dump

public void dump(java.io.OutputStream s)
          throws java.io.IOException
Dump the queue into a file in a string readable format.
This format do not coincide with the toString() output.
This function is intended for debugging porpuse.
Returns:
String a string representing the queue

Help is irrilevant
You will be assimilated!

v1.0 beta by Dario Maggiorini