com.amazon.carbonado.cursor
Class MergeSortBuffer<S extends Storable>
java.lang.Object
java.util.AbstractCollection<S>
com.amazon.carbonado.cursor.MergeSortBuffer<S>
- All Implemented Interfaces:
- SortBuffer<S>, Iterable<S>, Collection<S>
public class MergeSortBuffer<S extends Storable>
- extends AbstractCollection<S>
- implements SortBuffer<S>
Sort buffer implemented via a merge sort algorithm. If there are too many
storables to fit in the reserved memory buffer, they are sorted and
serialized to temporary files.
The following system properties can be set to change the default
performance characteristics of the merge sort. Each property name must be
prefixed with "com.amazon.carbonado.cursor.MergeSortBuffer."
Property Default Notes
------------------- ---------- ----------------------------------------------
maxArrayCapacity 8192 Larger value greatly improves performance, but
more memory is used for each running sort.
maxOpenFileCount 100 Larger value may reduce the amount of file
merges, but there is an increased risk of
running out of file descriptors.
outputBufferSize 10000 Larger value may improve performance of file
writing, but not by much.
tmpdir Merge sort files by default are placed in the
Java temp directory. Override to place them
somewhere else.
- Author:
- Brian S O'Neill
- See Also:
SortedCursor
| Methods inherited from interface java.util.Collection |
addAll, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, toArray, toArray |
MergeSortBuffer
public MergeSortBuffer()
- Since:
- 1.2
MergeSortBuffer
public MergeSortBuffer(Storage<S> storage)
- Parameters:
storage - storage for elements; if null use first Storable to
prepare reloaded Storables
MergeSortBuffer
public MergeSortBuffer(Storage<S> storage,
String tempDir)
- Parameters:
storage - storage for elements; if null use first Storable to
prepare reloaded StorablestempDir - directory to store temp files for merging, or null for default
MergeSortBuffer
public MergeSortBuffer(Storage<S> storage,
String tempDir,
int maxArrayCapacity)
- Parameters:
storage - storage for elements; if null use first Storable to
prepare reloaded StorablestempDir - directory to store temp files for merging, or null for defaultmaxArrayCapacity - maximum amount of storables to keep in an array
before serializing to a file
- Throws:
IllegalArgumentException - if storage is null
prepare
public void prepare(Comparator<S> comparator)
- Description copied from interface:
SortBuffer
- Clears buffer and assigns a comparator for sorting.
- Specified by:
prepare in interface SortBuffer<S extends Storable>
add
public boolean add(S storable)
- Specified by:
add in interface Collection<S extends Storable>- Overrides:
add in class AbstractCollection<S extends Storable>
size
public int size()
- Specified by:
size in interface Collection<S extends Storable>- Specified by:
size in class AbstractCollection<S extends Storable>
iterator
public Iterator<S> iterator()
- Specified by:
iterator in interface Iterable<S extends Storable>- Specified by:
iterator in interface Collection<S extends Storable>- Specified by:
iterator in class AbstractCollection<S extends Storable>
clear
public void clear()
- Specified by:
clear in interface Collection<S extends Storable>- Overrides:
clear in class AbstractCollection<S extends Storable>
sort
public void sort()
- Description copied from interface:
SortBuffer
- Finish sorting buffer.
- Specified by:
sort in interface SortBuffer<S extends Storable>
close
public void close()
- Description copied from interface:
SortBuffer
- Clear and close buffer.
- Specified by:
close in interface SortBuffer<S extends Storable>
Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.