ariba.util.io
Class BufferedSort

java.lang.Object
  extended by ariba.util.io.BufferedSort

public class BufferedSort
extends java.lang.Object

Resource-limited sort The resource limited sort uses a buffer to manage. First, the overall list is split into a set of buffers constrained by the memory resources. Then, we merge sort that list of buffers until we arrive at only one buffer. The number of buffers that are merged are restricted in 2 ways: - minimally 2 buffers are merged - maximally maxBufferLimit buffers are merged - a buffer may refuse to open, which allows for a dynamic control over the number of concurrently open buffers This is geared towards file handles in a multi-threaded environment. If file reads are expensive, it makes sense to merge as many buffers as possible, but if many threads do this, it could lead to an exhaustion of file handles. This allows us to do better than the 2 minimum.


Nested Class Summary
static interface BufferedSort.Resource
           
static interface BufferedSort.SortBuffer
           
 
Constructor Summary
BufferedSort(BufferedSort.SortBuffer source, long resourceLimit, long upperBufferLimit, java.util.Comparator<BufferedSort.Resource> comparator)
          Prepare for a sort, using a source buffer.
 
Method Summary
 BufferedSort.SortBuffer sort()
          Performs the sort.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferedSort

public BufferedSort(BufferedSort.SortBuffer source,
                    long resourceLimit,
                    long upperBufferLimit,
                    java.util.Comparator<BufferedSort.Resource> comparator)
Prepare for a sort, using a source buffer. This buffer will be opened and read from, and child buffers will be created using its factory. Note for all intermediate buffers "dispose()" will be called, but it will not be called for either the source or the result.

Parameters:
source - - the source data
resourceLimit - - maximum resource count of sortable elements
upperBufferLimit - - maximum number of sort buffers that are merged simultaneously
comparator - - the comparator
Method Detail

sort

public BufferedSort.SortBuffer sort()
                             throws java.io.IOException
Performs the sort.

Returns:
a sorted sortBuffer, if a sort was performed. If null is returned, the source is sorted (however a sorted source doesn't mean null will be returned for sure).
Throws:
java.io.IOException


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.