edu.wpi.prc.task
Class WorkUnit

java.lang.Object
  extended by edu.wpi.prc.task.Task
      extended by edu.wpi.prc.task.WorkUnit
All Implemented Interfaces:
Prioritizable

public class WorkUnit
extends Task

A WorkUnit is a type of Task that contains raw data to be analyzed by the science application. It can be sent to one or more clients.

Author:
James Baldassari

Field Summary
private  int assignmentCount
           
static long DEFAULT_EXPIRATION_TIME
           
private  java.util.Date expirationDate
           
private  long expirationDelta
           
private  int numValidResults
           
private  int points
           
private  java.util.Set<Volunteer> users
           
 
Fields inherited from class edu.wpi.prc.task.Task
MIN_PRIORITY
 
Constructor Summary
protected WorkUnit()
          Default constructor is protected so that the WorkUnit will either be created by the TaskFactory or the public constructor that takes a task ID will be called.
protected WorkUnit(java.lang.String taskID)
          Constructor that takes a task ID.
 
Method Summary
 void assignUser(Volunteer user)
          Add a user to the set of users associated with this work unit, and increments the assignment count.
 void delete()
          Deletes a WorkUnit from the database.
 boolean equals(java.lang.Object o)
          Tests whether this WorkUnit is equal to another.
 WorkUnit[] find()
          Finds all WorkUnits in the database that match the attributes set in this WorkUnit.
static WorkUnit[] findAll()
          Finds all WorkUnits in the database.
static WorkUnit[] findAllEgress()
           
static WorkUnit[] findAllIngress()
           
static WorkUnit[] findAllPending()
           
static WorkUnit[] findAllSpotCheck()
           
 int getAssignmentCount()
           
protected  java.util.Date getExpirationDate()
           
protected  long getExpirationDelta()
           
 int getNumValidResults()
           
 int getPoints()
           
 java.util.Set<Volunteer> getUsers()
           
 boolean hasExpired()
           
 boolean hasUser(Volunteer user)
          Tests whether this work unit has been assigned to the given user.
 void incrementNumValidResults()
          Increments the number of valid results for this work unit.
 void removeAllusers()
          Removes all users from this work unit.
 Volunteer removeUser(Volunteer user)
          Remove a user from the set of users associated with this work unit.
 void resetExpirationDate()
          Sets this work unit's expiration date to the current time plus the expiration time.
 void save()
          Inserts this WorkUnit into the database as a new record.
 void setAssignmentCount(int assignmentCount)
           
protected  void setExpirationDate(java.util.Date expirationDate)
           
protected  void setExpirationDelta(long expirationDelta)
           
 void setExpirationTime(long expirationTime)
          Sets the expiration time and, then calculates and sets the expiration date.
protected  void setNumValidResults(int numValidResults)
           
 void setPoints(int points)
           
protected  void setUsers(java.util.Set<Volunteer> users)
           
 void update()
          Updates this WorkUnit in the database.
 
Methods inherited from class edu.wpi.prc.task.Task
getCreationDate, getData, getDataPartitions, getId, getPriority, getState, getStateStr, getTaskID, isEqual, setCreationDate, setData, setDataPartitions, setId, setPriority, setState, setStateStr, setTaskID
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_EXPIRATION_TIME

public static final long DEFAULT_EXPIRATION_TIME
See Also:
Constant Field Values

points

private int points

numValidResults

private int numValidResults

users

private java.util.Set<Volunteer> users

assignmentCount

private int assignmentCount

expirationDate

private java.util.Date expirationDate

expirationDelta

private long expirationDelta
Constructor Detail

WorkUnit

protected WorkUnit()
Default constructor is protected so that the WorkUnit will either be created by the TaskFactory or the public constructor that takes a task ID will be called. This restriction ensures that the WorkUnit will always have a valid task ID.


WorkUnit

protected WorkUnit(java.lang.String taskID)
Constructor that takes a task ID.

Parameters:
taskID - The task ID to set.
Method Detail

getPoints

public int getPoints()
Returns:
Returns the points that will be added to the user's score when a Result is returned for this WorkUnit.

setPoints

public void setPoints(int points)
Parameters:
points - The points to set.

getNumValidResults

public int getNumValidResults()
Returns:
Returns the numValidResults.

setNumValidResults

protected void setNumValidResults(int numValidResults)
Parameters:
numValidResults - The numValidResults to set.

incrementNumValidResults

public void incrementNumValidResults()
Increments the number of valid results for this work unit.


getUsers

public java.util.Set<Volunteer> getUsers()
Returns:
Returns the users.

setUsers

protected void setUsers(java.util.Set<Volunteer> users)
Parameters:
users - The users to set.

assignUser

public void assignUser(Volunteer user)
Add a user to the set of users associated with this work unit, and increments the assignment count.

Parameters:
user - The user to add.

removeAllusers

public void removeAllusers()
Removes all users from this work unit.


hasUser

public boolean hasUser(Volunteer user)
Tests whether this work unit has been assigned to the given user.

Parameters:
user - The user to search for.
Returns:
True if the given user is associated with this work unit, false otherwise.

removeUser

public Volunteer removeUser(Volunteer user)
Remove a user from the set of users associated with this work unit.

Parameters:
user - The user to remove.
Returns:
The user that was removed, or null if the user did not appear in the set.

getAssignmentCount

public int getAssignmentCount()
Returns:
Returns the assignmentCount.

setAssignmentCount

public void setAssignmentCount(int assignmentCount)
Parameters:
assignmentCount - The assignmentCount to set.

getExpirationDate

protected java.util.Date getExpirationDate()
Returns:
Returns the expirationDate.

setExpirationDate

protected void setExpirationDate(java.util.Date expirationDate)
Parameters:
expirationDate - The expirationDate to set.

hasExpired

public boolean hasExpired()
Returns:
Returns true if the expiration date for this work unit has passed, false otherwise.

getExpirationDelta

protected long getExpirationDelta()
Returns:
Returns the expirationDelta.

setExpirationDelta

protected void setExpirationDelta(long expirationDelta)
Parameters:
expirationDelta - The expirationDelta to set.

setExpirationTime

public void setExpirationTime(long expirationTime)
Sets the expiration time and, then calculates and sets the expiration date. NOTE: This method will only set the expiration time if it is greater than zero.

Parameters:
expirationTime - The expiration time in seconds to set.

resetExpirationDate

public void resetExpirationDate()
Sets this work unit's expiration date to the current time plus the expiration time. NOTE: This method will only reset the expiration date if this work unit has expired.


save

public void save()
Inserts this WorkUnit into the database as a new record.

Specified by:
save in class Task

update

public void update()
Updates this WorkUnit in the database.

Specified by:
update in class Task

find

public WorkUnit[] find()
Finds all WorkUnits in the database that match the attributes set in this WorkUnit.

Returns:
An array of all matching WorkUnits.

findAll

public static WorkUnit[] findAll()
Finds all WorkUnits in the database.

Returns:
An array of all WorkUnits in the database.

findAllIngress

public static WorkUnit[] findAllIngress()
Returns:
Returns an array of all WorkUnits in the Ingress state.

findAllPending

public static WorkUnit[] findAllPending()
Returns:
Returns an array of all WorkUnits in the Pending state.

findAllEgress

public static WorkUnit[] findAllEgress()
Returns:
Returns an array of all WorkUnits in the Egress state.

findAllSpotCheck

public static WorkUnit[] findAllSpotCheck()
Returns:
Returns an array of all WorkUnits in the SpotCheck state.

delete

public void delete()
Deletes a WorkUnit from the database.

Specified by:
delete in class Task

equals

public boolean equals(java.lang.Object o)
Tests whether this WorkUnit is equal to another.

Overrides:
equals in class java.lang.Object
Parameters:
o - The object to compare this WorkUnit to.