com.unister.semweb.drums.bucket
Class BucketContainer<Data extends AbstractKVStorable>

java.lang.Object
  extended by com.unister.semweb.drums.bucket.BucketContainer<Data>
Type Parameters:
Data - an implementation of AbstractKVStorable, e.g. GeneralStorable

public class BucketContainer<Data extends AbstractKVStorable>
extends java.lang.Object

This class handles AbstractKVStorable-objects in memory. Depending on the given AbstractHashFunction, the BucketContainer distributes incoming data to a defined number of Buckets. This class is allowed to use the by DRUMSParameterSet.BUCKET_MEMORY defined amount of memory.

Author:
Martin Nettling

Constructor Summary
BucketContainer(Bucket<Data>[] buckets, AbstractHashFunction hashFunction)
           
 
Method Summary
 void addToCache(Data... toAdd)
          Add the given records to the Buckets, if possible.
 boolean contains(Data element)
           
 Bucket<Data> getBucket(int bucketId)
           
 AbstractHashFunction getHashFunction()
          returns the AbstractHashFunction for mapping keys to Buckets.
 int getNumberOfBuckets()
           
 void setBucket(Bucket<Data> bucket)
          sets a new bucket.
 void shutdown()
          This method initializes the shutdown of this BucketContainer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BucketContainer

public BucketContainer(Bucket<Data>[] buckets,
                       AbstractHashFunction hashFunction)
Parameters:
buckets - the buckets, where to store the AbstractKVStorable
hashFunction - the AbstractHashFunction is used to map from the key of a AbstractKVStorable-object to the relevant Bucket
Method Detail

addToCache

public void addToCache(Data... toAdd)
                throws BucketContainerException,
                       java.lang.InterruptedException
Add the given records to the Buckets, if possible. If all Buckets are full the method is blocking.

Parameters:
toAdd - the data to add
Throws:
BucketContainerException
java.lang.InterruptedException

getNumberOfBuckets

public int getNumberOfBuckets()
Returns:
the number of buckets

getBucket

public Bucket<Data> getBucket(int bucketId)
Parameters:
bucketId -
Returns:
the bucket with the given bucketId

setBucket

public void setBucket(Bucket<Data> bucket)
               throws BucketContainerException,
                      java.lang.InterruptedException
sets a new bucket. The bucketId is read from the given Bucket-object

Parameters:
bucket - the Bucket-object to add
Throws:
BucketContainerException
java.lang.InterruptedException

contains

public boolean contains(Data element)
Parameters:
element -
Returns:
Checks, if an record with the key of the given element is already in memory.

getHashFunction

public AbstractHashFunction getHashFunction()
returns the AbstractHashFunction for mapping keys to Buckets.

Returns:
AbstractHashFunction

shutdown

public void shutdown()
This method initializes the shutdown of this BucketContainer. No records are accepted anymore.