orca.shirako.util
Class BinPool

java.lang.Object
  extended by orca.shirako.util.BinPool

public class BinPool
extends java.lang.Object

This is a utility class for use in mappers: it manages a pool of resource "bins" (any Object), indexed by the number of units allocated or free from each bin.


Constructor Summary
BinPool(int ballsPerBin)
           
 
Method Summary
 void addBin(java.lang.Object o)
          Installs a new bin with all elements free.
 void drainBin(java.lang.Object o, int balls, int draining)
          Deallocates units from a bin, increasing its number of free units.
 void fillBin(java.lang.Object o, int balls, int filling)
          Allocates units from/to a bin, reducing the number of free units.
 java.lang.Object findAndFillBin(int balls)
          Finds a bin with a minimum number of units free, and allocate more units from (to?) it, reducing the number of free units.
 int getBinSize()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BinPool

public BinPool(int ballsPerBin)
Method Detail

addBin

public void addBin(java.lang.Object o)
Installs a new bin with all elements free.

Parameters:
o - the bin

drainBin

public void drainBin(java.lang.Object o,
                     int balls,
                     int draining)
Deallocates units from a bin, increasing its number of free units. Note: the names of 'fill' and 'drain' concepts seem bass-ackwards. Fill increases the number of units allocated from the bin, reducing the number of free units. Drain reduces the number of units allocated from the bin, increasing the number of free units. So we have to think of bins as 'holding' the units allocated from them, and 'free' as their remaining capacity. How very strange and confusing.

Parameters:
o - the bin
balls - how many units the bin has free
draining - how many units being restored

fillBin

public void fillBin(java.lang.Object o,
                    int balls,
                    int filling)
Allocates units from/to a bin, reducing the number of free units.

Parameters:
o - the bin
balls - how many units the bin currently has allocated
filling - how many new units being allocated

findAndFillBin

public java.lang.Object findAndFillBin(int balls)
                                throws java.lang.Exception
Finds a bin with a minimum number of units free, and allocate more units from (to?) it, reducing the number of free units.

Parameters:
balls - number of units needed
Returns:
the selected bin
Throws:
java.lang.Exception

getBinSize

public int getBinSize()


Copyright © 2007 Network/Internet Computing Lab. All Rights Reserved.