|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectmartin.common.compthreads.Master<E>
martin.common.compthreads.IteratorBasedMaster<E>
E - The class representing solutions to computational problemspublic class IteratorBasedMaster<E>
Class for facilitating parallelized computations. This class provides functionality when the "problem" instances are given by an iterator, while the ArrayBasedMaster class is better suited when the problems are stored in an array. Solutions can be retrieved as they complete through an iterator. Usage example: new Thread(new ArrayBasedMaster(problems, 4)).start(); Object[] solutions = master.getSolutions();
| Field Summary | |
|---|---|
private java.util.concurrent.Semaphore |
addedsem
|
private int |
nextJobToRelease
|
private java.util.Iterator<Problem<E>> |
problemIterator
|
private java.util.Map<java.lang.Integer,E> |
solutions
|
private java.util.concurrent.Semaphore |
solutionsem
|
private java.util.Map<java.lang.Integer,java.util.concurrent.Semaphore> |
solutionSemaphores
|
private java.util.concurrent.Semaphore |
storageLimitSem
|
private java.util.concurrent.Semaphore |
threadsem
|
| Constructor Summary | |
|---|---|
IteratorBasedMaster(java.util.Collection<Problem<E>> collection,
int numThreads)
|
|
IteratorBasedMaster(java.util.Iterator<Problem<E>> problemIterator,
int numThreads)
Creates a new IteratorBasedMaster. |
|
IteratorBasedMaster(java.util.Iterator<Problem<E>> problemIterator,
int numThreads,
java.lang.Integer maxStorageLength)
Creates a new IteratorBasedMaster. |
|
IteratorBasedMaster(Problem<E>[] array,
int numThreads)
|
|
| Method Summary | |
|---|---|
boolean |
hasNext()
|
java.util.Iterator<E> |
iterator()
|
E |
next()
If no computed solutions exist that have not already been returned, this method will block until the next problem finishes. |
E |
next(boolean remove)
If no computed solutions exist that have not already been returned, this method will block until the next problem finishes. |
void |
remove()
Does not do anything, as next() also removes elements from storage after returning them. |
(package private) void |
report(E solution,
int id)
|
void |
reset()
|
void |
run()
Runs the thread. |
| Methods inherited from class martin.common.compthreads.Master |
|---|
getReportProgress, setReportProgress, startThread |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.util.Iterator<Problem<E>> problemIterator
private java.util.Map<java.lang.Integer,E> solutions
private java.util.Map<java.lang.Integer,java.util.concurrent.Semaphore> solutionSemaphores
private java.util.concurrent.Semaphore threadsem
private java.util.concurrent.Semaphore solutionsem
private java.util.concurrent.Semaphore addedsem
private int nextJobToRelease
private java.util.concurrent.Semaphore storageLimitSem
| Constructor Detail |
|---|
public IteratorBasedMaster(java.util.Iterator<Problem<E>> problemIterator,
int numThreads,
java.lang.Integer maxStorageLength)
problemIterator - specifies an iterator which gives the problems that are to be computed.numThreads - specifies the maximum number of problems that should be computed concurrentlymaxStorageLength - specifies the maximum number of result objects that can be help in buffer memory
public IteratorBasedMaster(java.util.Iterator<Problem<E>> problemIterator,
int numThreads)
problemIterator - specifies an iterator which gives the problems that are to be computed.numThreads - specifies the maximum number of problems that should be computed concurrently
public IteratorBasedMaster(Problem<E>[] array,
int numThreads)
public IteratorBasedMaster(java.util.Collection<Problem<E>> collection,
int numThreads)
| Method Detail |
|---|
public void run()
run in interface java.lang.Runnablerun in class Master<E>
void report(E solution,
int id)
report in class Master<E>public boolean hasNext()
hasNext in interface java.util.Iterator<E>public E next()
next in interface java.util.Iterator<E>java.util.NoSuchElementException - if called when hasNext() == falsepublic E next(boolean remove)
remove - whether to also delete the returned object from the underlying storage data structures
java.util.NoSuchElementException - if called when hasNext() == falsepublic void reset()
public void remove()
remove in interface java.util.Iterator<E>public java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||