org.ourgrid.mygrid.scheduler.jobmanager
Class TaskEntry

java.lang.Object
  extended by org.ourgrid.mygrid.scheduler.jobmanager.TaskEntry
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<TaskEntry>
Direct Known Subclasses:
FakeScheduler.FakeTask

public class TaskEntry
extends java.lang.Object
implements java.lang.Comparable<TaskEntry>, java.io.Serializable

An abstraction to represent a task of a job sent by user to be executed. A task can be made of n replicas defined by maxReplicas. A replica is the lower level abstraction that is executed on the GridMachines.

See Also:
Serialized Form

Field Summary
protected  java.util.List<ReplicaEntry> replicas
          This Task's Replicas.
 
Constructor Summary
TaskEntry(TaskSpec taskSpec, int id, int jobId, int maxFails, int maxReplicas)
          The constructor.
 
Method Summary
 boolean canReplicate()
          Verifies if a task replica can be done.
 int compareTo(TaskEntry objectTask)
           
protected  ReplicaEntry createReplicaEntry(int id, int taskId, int jobId, TaskSpec taskSpec)
           
 boolean equals(java.lang.Object o)
           
 int getActualFails()
          Returns the current number of replica fails.
 int getId()
          Returns the Task identification.
 int getJobId()
          Returns the job identification of this Task.
 int getMaxFails()
          Returns the maximum number of replica fails a Task can have.
 int getMaxReplicas()
          Returns the maximum number of running replicas the Task can have.
 ReplicaEntry getNewReplica()
          Creates and returns a new Replica.
 int getNumberOfRunningReplicas()
          Returns the number of running Replicas.
 int getNumberOfUnstartedReplicas()
          Returns the number of unstarted Replicas.
 ReplicaEntry getReplicaById(int id)
          Returns the Replica with the specified identification.
 java.util.Collection<ReplicaEntry> getReplicas()
          Returns the Task's Replicas.
 TaskSpec getSpec()
           
 ExecutionStatus getState()
          Returns the Task state.
 void replicaAborted(ReplicaExecutorResult result)
          Sets a Replica state to Aborted, if the replica is 'Running'.
 void replicaCanceled(ReplicaExecutorResult result)
          Sets a Replica state to Canceled by the User, if the replica is 'Running' or 'Unstarted'.
 void replicaFailed(ReplicaExecutorResult result)
          Sets a Replica state to Failed, if the replica is 'Running'.
 void replicaFinished(ReplicaExecutorResult result)
          Sets a Replica state to Finished, if the replica is 'Running'.
 void setCancelled()
          Sets the task as canceled.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

replicas

protected java.util.List<ReplicaEntry> replicas
This Task's Replicas.

Constructor Detail

TaskEntry

public TaskEntry(TaskSpec taskSpec,
                 int id,
                 int jobId,
                 int maxFails,
                 int maxReplicas)
The constructor.

Parameters:
taskSpec - The Task specification.
id - This Task identification
jobId - The Job identification.
maxFails - The maximum number of replicas' fails allowed.
maxReplicas - The maximum number of running Replicas permitted.
Method Detail

getId

public int getId()
Returns the Task identification.

Returns:
The Task identification.

getJobId

public int getJobId()
Returns the job identification of this Task.

Returns:
The job id of this Task.

getActualFails

public int getActualFails()
Returns the current number of replica fails.

Returns:
The current number of replica fails

getMaxFails

public int getMaxFails()
Returns the maximum number of replica fails a Task can have.

Returns:
The maximum number of replica fails

getMaxReplicas

public int getMaxReplicas()
Returns the maximum number of running replicas the Task can have.

Returns:
The maximum number of running replicas

getReplicas

public java.util.Collection<ReplicaEntry> getReplicas()
Returns the Task's Replicas.

Returns:
The Collection containing all the Replicas.

getNewReplica

public ReplicaEntry getNewReplica()
Creates and returns a new Replica.

Returns:
A new Replica in case that a replication is possible to be made, null otherwise.

createReplicaEntry

protected ReplicaEntry createReplicaEntry(int id,
                                          int taskId,
                                          int jobId,
                                          TaskSpec taskSpec)

getNumberOfRunningReplicas

public int getNumberOfRunningReplicas()
Returns the number of running Replicas.

Returns:
The number of running Replicas.

getNumberOfUnstartedReplicas

public int getNumberOfUnstartedReplicas()
Returns the number of unstarted Replicas.

Returns:
The number of unstarted Replicas.

canReplicate

public boolean canReplicate()
Verifies if a task replica can be done.

Returns:
True if it is possible to create a task replica, false otherwise

replicaFinished

public void replicaFinished(ReplicaExecutorResult result)
Sets a Replica state to Finished, if the replica is 'Running'.

Parameters:
result - The result of the replica execution

replicaFailed

public void replicaFailed(ReplicaExecutorResult result)
Sets a Replica state to Failed, if the replica is 'Running'.

Parameters:
result - The result of the replica execution

replicaAborted

public void replicaAborted(ReplicaExecutorResult result)
Sets a Replica state to Aborted, if the replica is 'Running'.

Parameters:
result - The result of the replica execution

replicaCanceled

public void replicaCanceled(ReplicaExecutorResult result)
Sets a Replica state to Canceled by the User, if the replica is 'Running' or 'Unstarted'.

Parameters:
result - The result of the replica execution

getState

public ExecutionStatus getState()
Returns the Task state.

Returns:
The Task state.
Throws:
IllegalStateException - - Case the Task is not in any of the expected states.

getReplicaById

public ReplicaEntry getReplicaById(int id)
Returns the Replica with the specified identification.

Parameters:
id - The Replica identification.
Returns:
The Replica case the identification exists, null otherwise.

compareTo

public int compareTo(TaskEntry objectTask)
Specified by:
compareTo in interface java.lang.Comparable<TaskEntry>
See Also:
Comparable.compareTo(java.lang.Object)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

setCancelled

public void setCancelled()
Sets the task as canceled.


equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

getSpec

public TaskSpec getSpec()
Returns:
this task's TaskSpec