com.ebay.erl.mobius.core.collection
Class BigTupleList

java.lang.Object
  extended by com.ebay.erl.mobius.core.collection.BigTupleList
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<Tuple>, java.util.EventListener, java.util.Observer, javax.management.NotificationListener

public class BigTupleList
extends java.lang.Object
implements javax.management.NotificationListener, java.util.Observer, java.lang.Iterable<Tuple>, java.lang.Cloneable

Stores one to many Tuple elements.

By default, the tuples are stored in memory, but if the memory is insufficient, the tuples are flushed into underlying file system.

When iterating the Tuple elements using iterator(), the tuples are sorted based on the comparator if it is provided in the constructor, otherwise it would be in the insertion order.

This product is licensed under the Apache License, Version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0. This product contains portions derived from Apache hadoop which is licensed under the Apache License, Version 2.0, available at http://hadoop.apache.org. © 2007 – 2012 eBay Inc., Evan Chiu, Woody Zhou, Neel Sundaresan


Field Summary
static BigTupleList ZERO_SIZE_UNMODIFIABLE
          A immutable zero size BigTupleList.
 
Constructor Summary
BigTupleList(java.util.Comparator<Tuple> comparator, org.apache.hadoop.mapred.Reporter reporter)
          Create an instance of BigTupleList with specified comparator.
BigTupleList(org.apache.hadoop.mapred.Reporter reporter)
          Create an instance of BigTupleList with default comparator (Tuple).
 
Method Summary
 void add(Tuple newTuple)
          Add a new Tuple into this BigTupleList.
 void addAll(java.util.Collection<Tuple> collection)
          Add all the tuples in collection into this list.
 void addAll(java.lang.Iterable<Tuple> collection)
          Add all the tuples in collection into this list.
 void clear()
          Remove all Tuple in this BigTupleList
 BigTupleList clone()
          Make a deep clone of this list and return a new instance.
 long getEstimatedSizeInMemory()
           
 Tuple getFirst()
           
 void handleNotification(javax.management.Notification notification, java.lang.Object handback)
          When the used memory exceed the threshold.
static BigTupleList immutable(BigTupleList list)
          Create a new instance of immutable BigTupleList which has identical content of the given list.
 boolean isMutable()
          Check if this list is mutable or not.
 CloseableIterator<Tuple> iterator()
          Create an iterator for iterating the Tuple in this list.
 long size()
          return the total number of Tuple stored in this BigTupleList
 void update(java.util.Observable o, java.lang.Object arg)
          Listening to JVM shutdown signal.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ZERO_SIZE_UNMODIFIABLE

public static final BigTupleList ZERO_SIZE_UNMODIFIABLE
A immutable zero size BigTupleList.

Constructor Detail

BigTupleList

public BigTupleList(org.apache.hadoop.mapred.Reporter reporter)
Create an instance of BigTupleList with default comparator (Tuple).


BigTupleList

public BigTupleList(java.util.Comparator<Tuple> comparator,
                    org.apache.hadoop.mapred.Reporter reporter)
Create an instance of BigTupleList with specified comparator.

Tuples stored in this list is sorted by the comparator

Method Detail

getFirst

public Tuple getFirst()

isMutable

public boolean isMutable()
Check if this list is mutable or not.


immutable

public static BigTupleList immutable(BigTupleList list)
Create a new instance of immutable BigTupleList which has identical content of the given list.

This method returns a new instance, so list is still mutable.


add

public void add(Tuple newTuple)
Add a new Tuple into this BigTupleList.

Throws:
java.lang.UnsupportedOperationException - if this list is immutable.

addAll

public void addAll(java.lang.Iterable<Tuple> collection)
Add all the tuples in collection into this list.

Throws:
java.lang.UnsupportedOperationException - if this list is immutable.

addAll

public void addAll(java.util.Collection<Tuple> collection)
Add all the tuples in collection into this list.

Throws:
java.lang.UnsupportedOperationException - if this list is immutable.

size

public long size()
return the total number of Tuple stored in this BigTupleList


getEstimatedSizeInMemory

public long getEstimatedSizeInMemory()

clear

public void clear()
Remove all Tuple in this BigTupleList


handleNotification

public void handleNotification(javax.management.Notification notification,
                               java.lang.Object handback)
When the used memory exceed the threshold. this method will be called.

If the number of tuples in this list is greater or equals to 1000, all the tuples will be saved into disk.

Specified by:
handleNotification in interface javax.management.NotificationListener

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Listening to JVM shutdown signal.

If JVM shutdown normally, this method will be called and clear() will be called to remove all the stored tuples.

Specified by:
update in interface java.util.Observer
See Also:
JVMShutdownNotifier

clone

public BigTupleList clone()
Make a deep clone of this list and return a new instance.

Tuples in memory will be cloned and the files store tuples in this list will be duplicated and stored in the returned list.

Since it's a deep clone, make changes to this list won't change the returned clone.

Mutable or not of the return clone is the same as this list.

Overrides:
clone in class java.lang.Object

iterator

public CloseableIterator<Tuple> iterator()
Create an iterator for iterating the Tuple in this list.

The Tuples are sorted by a comparator, either the default one ( Tuple) or the specified one in #BigTupleList(Comparator)

It's it very important to invoke the CloseableIterator.close() after the iteration is done, whether the elements insides have been all iterated or not.

Specified by:
iterator in interface java.lang.Iterable<Tuple>