edu.cuny.brooklyn.swc2
Interface Worker

All Superinterfaces:
java.lang.Runnable
All Known Implementing Classes:
FactorialWorker, FactorialWorker2, ParticleWorker, ParticleWorker, ParticleWorker, PingPongWorker

public interface Worker
extends java.lang.Runnable

Worker is the interface implemented by a user's class which will perform the calculations associated with a particular computation. The implementing class is also required to define the Runnable.run() method, which will be called (potentially in a separate thread) to do all the necessary work by the computation.

The life-cycle of an object implementing this interface is as follows:

  1. instantiation
  2. setWorkUnit is invoked
  3. getGUIComponent method may be invoked
  4. the run method is invoked
  5. getPrecentageDone method may be invoked multiple times
  6. the run method returns, indicating successful completion
  7. the getResultUnit method is invoked
  8. the object and associated GUI component are discarded

Author:
Dino Klein

Method Summary
 javax.swing.JComponent getGUI()
          Returns a GUI component which is used to display progress and other information.
 float getPrecentageDone()
          Returns a float which represents what precentage of the calculation has completed.
 ResultUnit getResultUnit()
          Returns the ResultUnit produced by the implementing class.
 void setWorkUnit(WorkUnit wu)
          Called by the host of the Worker object, in order to provide it with a work unit to be processed.
 
Methods inherited from interface java.lang.Runnable
run
 

Method Detail

setWorkUnit

void setWorkUnit(WorkUnit wu)
Called by the host of the Worker object, in order to provide it with a work unit to be processed.

Parameters:
wu - the WorkUnit to process

getResultUnit

ResultUnit getResultUnit()
Returns the ResultUnit produced by the implementing class.

Returns:
the ResultUnit which is conveyed to the the Computation class

getPrecentageDone

float getPrecentageDone()
Returns a float which represents what precentage of the calculation has completed. It is also feasiable that this value cannot be calculated, in which case a -1.0 should be returned.

Returns:
a value between 0.0 and 1.0 to indicate progress, or -1.0 if unknown

getGUI

javax.swing.JComponent getGUI()
Returns a GUI component which is used to display progress and other information. It is not mandatory to provide a fancy GUI component, in which case a null should be returned.

Returns:
the GUI component, or null if none is available