fiftyone.mobile.detection.entities.stream
Class TriePool

java.lang.Object
  extended by fiftyone.mobile.detection.entities.stream.TriePool
All Implemented Interfaces:
Disposable

public class TriePool
extends Object
implements Disposable

As multiple threads need to read from the Source concurrently this class provides a mechanism for readers to be recycled across threads and requests.

Used by the BaseList to provide multiple readers for the list.

The DetectorDataSet must be disposed of to ensure the readers in the pool are closed.


Field Summary
private  Queue<TrieReader> readers
           
private  TrieSource source
           
 
Constructor Summary
TriePool(TrieSource source)
          Constructs a new pool of readers for the source provided.
 
Method Summary
 void dispose()
           
 TrieReader getReader()
          Returns a reader to the temp file for exclusive use.
 void release(TrieReader reader)
          Returns the reader to the pool to be used by another process later.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

readers

private final Queue<TrieReader> readers

source

private final TrieSource source
Constructor Detail

TriePool

public TriePool(TrieSource source)
Constructs a new pool of readers for the source provided.

Parameters:
source - The data source for the list
Method Detail

getReader

public TrieReader getReader()
                     throws IOException
Returns a reader to the temp file for exclusive use. Release method must be called to return the reader to the pool when finished.

Returns:
Reader open and ready to read from the temp file
Throws:
IOException

release

public void release(TrieReader reader)
Returns the reader to the pool to be used by another process later.

Parameters:
reader - Reader open and ready to read from the temp file

dispose

public void dispose()
Specified by:
dispose in interface Disposable