de.unidu.is.util
Class ThreadedCaller

java.lang.Object
  extended byde.unidu.is.util.ThreadedCaller

public abstract class ThreadedCaller
extends java.lang.Object

A class providing parallel execution of its method call(Object) (which has to be implemented in subclasses for an array of "targets". Targets can be arbitrary objects which are delivered to call(Object). The results are collected in a map.

Currently, the threaded calling is disabled, and sequential order is enabled.

Since:
2001-08-21
Version:
$Revision: 1.8 $, $Date: 2005/02/28 22:27:55 $
Author:
Henrik Nottelmann

Field Summary
protected  java.util.Map results
          Map, containing all targets (as keys) and their results (as values).
protected  java.lang.Object[] targets
          The targets.
 
Constructor Summary
ThreadedCaller(java.util.Iterator iterator)
          Creates a new instance.
ThreadedCaller(java.util.List list)
          Creates a new instance.
ThreadedCaller(java.lang.Object[] targets)
          Creates a new instance.
 
Method Summary
abstract  java.lang.Object call(java.lang.Object target)
          The method performing the actual work for a target.
 java.lang.Object getResult(java.lang.Object target)
          Returns the result object of the specified target.
 java.util.Map getResults()
          Returns a map, containing all targets (as keys) and their results (as values).
 java.lang.Object[] getTargets()
          Returns an array, containing all targets.
 java.util.Map start()
          Starts the execution.
 java.util.Map start10()
          Starts the parallel execution. 10 threads are used for handling the targets.
 java.util.Map startAll()
          Starts the parallel execution.
 java.util.Map startSequential()
          Starts the sequential execution, without creating new threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

results

protected java.util.Map results
Map, containing all targets (as keys) and their results (as values).


targets

protected java.lang.Object[] targets
The targets.

Constructor Detail

ThreadedCaller

public ThreadedCaller(java.util.Iterator iterator)
Creates a new instance.

Parameters:
iterator - iterator, producing all targets

ThreadedCaller

public ThreadedCaller(java.util.List list)
Creates a new instance.

Parameters:
list - targets

ThreadedCaller

public ThreadedCaller(java.lang.Object[] targets)
Creates a new instance.

Parameters:
targets - targets
Method Detail

call

public abstract java.lang.Object call(java.lang.Object target)
The method performing the actual work for a target.

Subclasses have to overwrite this method.

Parameters:
target - target for this call
Returns:
result of this call

start

public java.util.Map start()
Starts the execution. This implementation uses the sequential variant.

Returns:
map, containing the targets and their results

startAll

public java.util.Map startAll()
Starts the parallel execution. For each target, a thread is created and started. The thread calls the method call(Object) with its target and puts the result in the result map. This method returns after all threads terminated.

Returns:
map, containing the targets and their results

startSequential

public java.util.Map startSequential()
Starts the sequential execution, without creating new threads. This method calls the method call(Object) with its target and puts the result in the result map.

Returns:
map, containing the targets and their results

start10

public java.util.Map start10()
Starts the parallel execution. 10 threads are used for handling the targets. The threads call the method call(Object) with its target and puts the result in the result map. This method returns after all threads terminated.

Returns:
map, containing the targets and their results

getResults

public java.util.Map getResults()
Returns a map, containing all targets (as keys) and their results (as values).

Returns:
map, containing the targets and their results

getResult

public java.lang.Object getResult(java.lang.Object target)
Returns the result object of the specified target.

Parameters:
target - target
Returns:
result object of target, or null if no result exists

getTargets

public java.lang.Object[] getTargets()
Returns an array, containing all targets.

Returns:
array with all targets