|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.fasterxml.sort.Sorter<T>
public class Sorter<T>
Main entry point for sorting functionality; object that drives the sorting process from pre-sort to final output. Instances are not thread-safe, although they are reusable. Since the cost of creating new instances is trivial, there is usally no benefit from reusing instances, other than possible convenience.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.fasterxml.sort.SortingState |
|---|
SortingState.Phase |
| Field Summary | |
|---|---|
protected Exception |
_cancelForException
|
protected AtomicBoolean |
_cancelRequest
|
protected Comparator<T> |
_comparator
|
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. |
| Constructor Summary | |
|---|---|
Sorter(SortConfig config,
DataReaderFactory<T> readerFactory,
DataWriterFactory<T> writerFactory,
Comparator<T> comparator)
|
|
| Method Summary | |
|---|---|
protected static int |
_calculateRoundCount(int files,
int mergeFactor)
|
protected boolean |
_checkForCancel()
|
protected boolean |
_checkForCancel(Collection<File> tmpFilesToDelete)
|
protected File |
_merge(List<File> inputs)
|
protected void |
_merge(List<File> inputs,
DataWriter<T> writer)
|
protected Comparator<Object> |
_rawComparator()
|
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 succesfully 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 void |
merge(List<File> presorted,
DataWriter<T> resultWriter)
Main-level merge method called during once during sorting. |
protected List<File> |
presort(DataReader<T> inputReader,
SegmentedBuffer buffer,
Object[] firstSortedBatch,
T nextValue)
|
boolean |
sort(DataReader<T> inputReader,
DataWriter<T> resultWriter)
Method that will perform full sort on input data read using given DataReader, and written out using specified DataWriter. |
void |
sort(InputStream source,
OutputStream destination)
Method that will perform full sort on specified input, writing results into specified destination. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final SortConfig _config
protected final DataReaderFactory<T> _readerFactory
protected final DataWriterFactory<T> _writerFactory
protected final Comparator<T> _comparator
protected SortingState.Phase _phase
protected int _presortFileCount
protected int _sortRoundCount
protected int _currentSortRound
protected final AtomicBoolean _cancelRequest
protected Exception _cancelForException
| Constructor Detail |
|---|
public Sorter(SortConfig config,
DataReaderFactory<T> readerFactory,
DataWriterFactory<T> writerFactory,
Comparator<T> comparator)
config - Configuration for the sorterreaderFactory - Factory used for creating readers for pre-sorted data;
as well as for input if an InputStream is passed as sourcewriterFactory - Factory used for creating writers for storing pre-sorted data;
as well as for results if an OutputStream is passed as destination.| Method Detail |
|---|
public void cancel()
SortingState
cancel in interface SortingStatepublic void cancel(RuntimeException e)
SortingState
cancel in interface SortingStatepublic void cancel(IOException e)
SortingState
cancel in interface SortingStatepublic SortingState.Phase getPhase()
getPhase in interface SortingStatepublic int getNumberOfSortRounds()
SortingState
getNumberOfSortRounds in interface SortingStatepublic int getNumberOfPreSortFiles()
SortingState
getNumberOfPreSortFiles in interface SortingStatepublic int getSortRound()
SortingState
getSortRound in interface SortingStatepublic boolean isCompleted()
SortingState
isCompleted in interface SortingStatepublic boolean isPreSorting()
SortingState
isPreSorting in interface SortingStatepublic boolean isSorting()
SortingState
isSorting in interface SortingState
public void sort(InputStream source,
OutputStream destination)
throws IOException
DataReaderFactory and DataWriterFactory configured
for this sorter.
IOException
public boolean sort(DataReader<T> inputReader,
DataWriter<T> resultWriter)
throws IOException
DataReader, and written out using specified DataWriter.
Conversions to and from intermediate sort files is done
using DataReaderFactory and DataWriterFactory configured
for this sorter.
IOException
protected List<File> presort(DataReader<T> inputReader,
SegmentedBuffer buffer,
Object[] firstSortedBatch,
T nextValue)
throws IOException
IOException
protected File _writePresorted(Object[] items)
throws IOException
IOException
protected void merge(List<File> presorted,
DataWriter<T> resultWriter)
throws IOException
IOException
protected void _writeAll(DataWriter<T> resultWriter,
Object[] items)
throws IOException
IOException
protected File _merge(List<File> inputs)
throws IOException
IOException
protected void _merge(List<File> inputs,
DataWriter<T> writer)
throws IOException
IOException
protected static int _calculateRoundCount(int files,
int mergeFactor)
protected boolean _checkForCancel()
throws IOException
IOException
protected boolean _checkForCancel(Collection<File> tmpFilesToDelete)
throws IOException
IOExceptionprotected Comparator<Object> _rawComparator()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||