public abstract class SorterBase<T> extends Object implements SortingState
SortingState.Phase| Modifier and Type | Field and Description |
|---|---|
protected Exception |
_cancelForException |
protected AtomicBoolean |
_cancelRequest |
protected Comparator<T> |
_comparator
Comparator to use for sorting entries; defaults to 'C
|
protected SortConfig |
_config |
protected int |
_currentSortRound |
protected SortingState.Phase |
_phase |
protected int |
_presortFileCount |
protected DataReaderFactory<T> |
_readerFactory
Factory used for reading intermediate sorted files.
|
protected int |
_sortRoundCount |
protected DataWriterFactory<T> |
_writerFactory
Factory used for writing intermediate sorted files.
|
| Modifier | Constructor and Description |
|---|---|
protected |
SorterBase() |
protected |
SorterBase(SortConfig config) |
protected |
SorterBase(SortConfig config,
DataReaderFactory<T> readerFactory,
DataWriterFactory<T> writerFactory,
Comparator<T> comparator) |
| Modifier and Type | Method and Description |
|---|---|
protected static int |
_calculateRoundCount(int files,
int mergeFactor) |
protected boolean |
_checkForCancel() |
protected boolean |
_checkForCancel(Collection<File> tmpFilesToDelete) |
protected DataReader<T> |
_createMergeReader(List<File> inputs) |
protected File |
_merge(List<File> inputs) |
protected void |
_merge(List<File> inputs,
DataWriter<T> writer) |
protected void |
_presort(DataReader<T> inputReader,
SegmentedBuffer buffer,
T nextValue,
List<File> presorted) |
protected Comparator<Object> |
_rawComparator() |
protected Object[] |
_readMax(DataReader<T> inputReader,
SegmentedBuffer buffer,
long memoryToUse,
T firstItem)
Helper method that will fill given buffer with data read using
given reader, obeying given memory usage constraints.
|
protected void |
_writeAll(DataWriter<T> resultWriter,
Object[] items) |
protected File |
_writePresorted(Object[] items) |
void |
cancel()
Method that can be used to try to cancel executing sort operation.
|
void |
cancel(IOException e)
Method that can be used to try to cancel executing sort operation.
|
void |
cancel(RuntimeException e)
Method that can be used to try to cancel executing sort operation.
|
int |
getNumberOfPreSortFiles()
Accessor for checking how many pre-sort files were created during
pre-sort phase.
|
int |
getNumberOfSortRounds()
Accessor for figuring out how many regular sorting rounds need to be taken to
complete sorting, if known.
|
SortingState.Phase |
getPhase() |
int |
getSortRound()
Accessor for checking which sorting round sorter is doing: for pre-sort
it basically means number of segment (0-based) that is being processed
in-memory, for regular sort it is number of (0-based) sorting round.
|
boolean |
isCompleted()
Accessor for determining whether sorting has been successfully completed or not.
|
boolean |
isPreSorting()
Accessor for determining whether sorter is in its in-memory pre-sorting phase.
|
boolean |
isSorting()
Accessor for determining whether sorter is in regular merge-sort phase or not.
|
protected List<File> |
merge(List<File> presorted)
Main-level merge method that sorts the given input.
|
protected void |
merge(List<File> presorted,
DataWriter<T> resultWriter)
Main-level merge method that sorts the given input and writes to final output.
|
protected final SortConfig _config
protected DataReaderFactory<T> _readerFactory
protected DataWriterFactory<T> _writerFactory
protected Comparator<T> _comparator
protected SortingState.Phase _phase
protected int _presortFileCount
protected int _sortRoundCount
protected int _currentSortRound
protected final AtomicBoolean _cancelRequest
protected Exception _cancelForException
protected SorterBase(SortConfig config, DataReaderFactory<T> readerFactory, DataWriterFactory<T> writerFactory, Comparator<T> comparator)
protected SorterBase()
protected SorterBase(SortConfig config)
public void cancel()
SortingStatecancel in interface SortingStatepublic void cancel(RuntimeException e)
SortingStatecancel in interface SortingStatepublic void cancel(IOException e)
SortingStatecancel in interface SortingStatepublic SortingState.Phase getPhase()
getPhase in interface SortingStatepublic int getNumberOfSortRounds()
SortingStategetNumberOfSortRounds in interface SortingStatepublic int getNumberOfPreSortFiles()
SortingStategetNumberOfPreSortFiles in interface SortingStatepublic int getSortRound()
SortingStategetSortRound in interface SortingStatepublic boolean isCompleted()
SortingStateisCompleted in interface SortingStatepublic boolean isPreSorting()
SortingStateisPreSorting in interface SortingStatepublic boolean isSorting()
SortingStateisSorting in interface SortingStateprotected Object[] _readMax(DataReader<T> inputReader, SegmentedBuffer buffer, long memoryToUse, T firstItem) throws IOException
IOExceptionprotected void _presort(DataReader<T> inputReader, SegmentedBuffer buffer, T nextValue, List<File> presorted) throws IOException
IOExceptionprotected File _writePresorted(Object[] items) throws IOException
IOExceptionprotected void merge(List<File> presorted, DataWriter<T> resultWriter) throws IOException
IOExceptionprotected List<File> merge(List<File> presorted) throws IOException
IOExceptionprotected void _writeAll(DataWriter<T> resultWriter, Object[] items) throws IOException
IOExceptionprotected File _merge(List<File> inputs) throws IOException
IOExceptionprotected void _merge(List<File> inputs, DataWriter<T> writer) throws IOException
IOExceptionprotected DataReader<T> _createMergeReader(List<File> inputs) throws IOException
IOExceptionprotected static int _calculateRoundCount(int files,
int mergeFactor)
protected boolean _checkForCancel()
throws IOException
IOExceptionprotected boolean _checkForCancel(Collection<File> tmpFilesToDelete) throws IOException
IOExceptionprotected Comparator<Object> _rawComparator()
Copyright © 2012-2014 FasterXML. All Rights Reserved.