Lightweight Bartering Grid

lbg.peer.core.qms
Class QueueManager

java.lang.Object
  extended by lbg.peer.core.qms.QueueManager

public class QueueManager
extends java.lang.Object

Queueing Management System, or Request Manager.

Local Jobs and Supplying Jobs are maintained by order of submission time in their own queue respectively.

Each Local Job is currently composed of 1 Bag of Tasks.

Each Supplying Job is currently composed of 1 Bag of 1 Task.

Author:
Cyril Briquet

Field Summary
static int ALLOWED_PREEMPTIONS_BEFORE_CANCELLATION
          Number of allowed preemptions (expectedly a high value, e.g.
 
Constructor Summary
QueueManager(Peer managed_peer, Scheduler scheduler, boolean enable_ttg)
           
 
Method Summary
 int countWaitingLocalTasks()
           
 int countWaitingSupplyingTasks()
           
 void dequeueAllWaitingSupplyingTasks(boolean notify_consumers)
          Dequeues all waiting Supplying Tasks.
 void dequeueCancelledLocalTask(Task t, long xstart_time, long runtime, java.lang.String supplier_id)
          Dequeues a Local Task after its execution has been cancelled.
 void dequeueCancelledSupplyingTask(Task t, long xstart_time)
          Dequeues a Supplying Task after its execution has been cancelled.
 RequestStatus dequeueCompletedConsumptionTask(Task t, long xstart_time, long runtime)
          Dequeues a Consumption Task after its execution has been completed
 RequestStatus dequeueCompletedLocalTask(Task t, long xstart_time, long runtime)
          Dequeues a Local Task after its execution has been completed
 RequestStatus dequeueCompletedSupplyingTask(Task t, long xstart_time, long runtime)
          Dequeues a Supplying Task after its execution has been completed
 void dequeueLocalJob(int job_id)
          Dequeues a Local Job.
 void dequeueMostRecentWaitingSupplyingTasks(boolean notify_consumers, int k)
          Dequeues the k most recently queued waiting Supplying Tasks.
 void dequeueOldestWaitingSupplyingTaskOfConsumer(boolean notify_consumer, java.lang.String consumer_id)
          Dequeues the oldest waiting Supplying Task of target consumer.
 void dequeueWaitingLocalTask(Task t)
          Dequeues a waiting Local Task.
 void dequeueWaitingSupplyingTask(boolean notify_consumer, Task t)
          Dequeues target waiting Supplying Task.
 void dequeueWorstRankedWaitingSupplyingTasks(boolean notify_consumers, int k)
          Dequeues the k worst NoF-ranked queued waiting Supplying Tasks.
 PeerProfile[] getAllConsumers()
          Profiles of all consumer Peers with queued Supplying Tasks.
 long getCompletedLocalJobsCount()
           
 double getMeanJobCompletionTime()
           
 double getMeanJobCompletionTimeOfFirstKJobs(int k)
           
 double getMeanJobCompletionTimeOfNm5FirstKJobs()
           
 PeerProfile[] getRunningConsumers()
          Profiles of all consumer Peers with running Supplying Tasks.
 double getStdDevJobCompletionTime()
           
 PeerProfile[] getWaitingConsumers()
          Profiles of all consumer Peers with waiting Supplying Tasks.
 boolean hasWaitingLocalTasks()
           
 boolean hasWaitingSupplyingTasks()
           
 boolean isSupplyingTaskRunning(Task t)
           
 void preemptWaitingSupplyingTasks()
           
 JobPreQueue prequeue()
           
 int queryLocalJobStatus(int job_id)
          Returns the number of completed Tasks of target Local Job.
 void queueLocalJob(Job job)
          Queues a Local Job.
 void queueSupplyingJob(Job job, java.lang.String consumer_id)
          Queues a Supplying Job.
 void requeuePreemptedConsumptionTask(Task t, long xstart_time, long runtime, java.lang.String supplier_id)
          Requeues a Consumption Task after its execution has been cancelled.
 void requeuePreemptedLocalTask(Task t, long xstart_time, long runtime, java.lang.String supplier_id)
          Requeues a Local Task after its execution has been cancelled.
 void requeuePreemptedSupplyingTask(Task t, long xstart_time)
          Requeues a Supplying Task after its execution has been cancelled.
 void requeueUnqueuedConsumptionTask(Task t)
          Requeues a Consumption Task that has been unqueued, but not executed, i.e.
 void requeueUnqueuedLocalTask(Task t)
          Requeues a Local Task that has been unqueued, but not executed, i.e.
 void requeueUnqueuedSupplyingTask(Task t)
          Requeues a Supplying Task that has been unqueued, but not executed, i.e.
 RequestContainer scheduleBestRankedSupplyingTask()
          Selects for Local execution the best Favors-ranked, queued, yet unscheduled Supplying Task
 RequestContainer scheduleFirstConsumptionTask(boolean head_job_only)
          Selects for Consumption execution the first queued, yet unscheduled Local Task.
 RequestContainer scheduleFirstLocalTask(boolean head_job_only)
          Selects for Local execution the first queued, yet unscheduled Local Task.
 RequestContainer scheduleFirstSupplyingTask()
          Selects for Local execution the first queued, yet unscheduled Supplying Task
 RequestContainer scheduleNextConsumptionTask(LocalQueueCursor lqc)
          Selects for Consumption execution the next queued, yet unscheduled Local Task
 boolean shouldPreemptWaitingSupplyingTasks()
          Indicates whether waiting Supplying Tasks should be dequeued, i.e.
 java.lang.String toString()
           
 void updateStatistics()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ALLOWED_PREEMPTIONS_BEFORE_CANCELLATION

public static final int ALLOWED_PREEMPTIONS_BEFORE_CANCELLATION
Number of allowed preemptions (expectedly a high value, e.g. 256) before a Task is automatically cancelled.

This Task control mechanism prevents Tasks-that-can-never-complete (i.e.~because they are bugged) to become zombies.

See Also:
Constant Field Values
Constructor Detail

QueueManager

public QueueManager(Peer managed_peer,
                    Scheduler scheduler,
                    boolean enable_ttg)
             throws GridException
Throws:
GridException
Method Detail

toString

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

prequeue

public JobPreQueue prequeue()

hasWaitingLocalTasks

public boolean hasWaitingLocalTasks()

hasWaitingSupplyingTasks

public boolean hasWaitingSupplyingTasks()

countWaitingLocalTasks

public int countWaitingLocalTasks()

countWaitingSupplyingTasks

public int countWaitingSupplyingTasks()

getMeanJobCompletionTime

public double getMeanJobCompletionTime()

getMeanJobCompletionTimeOfFirstKJobs

public double getMeanJobCompletionTimeOfFirstKJobs(int k)
                                            throws GridException
Throws:
GridException

getMeanJobCompletionTimeOfNm5FirstKJobs

public double getMeanJobCompletionTimeOfNm5FirstKJobs()
                                               throws GridException
Throws:
GridException

getStdDevJobCompletionTime

public double getStdDevJobCompletionTime()

getCompletedLocalJobsCount

public long getCompletedLocalJobsCount()

queueLocalJob

public void queueLocalJob(Job job)
                   throws GridException
Queues a Local Job.

Parameters:
job - Local Job to queue
Throws:
GridException - if a parameter is illegal

queueSupplyingJob

public void queueSupplyingJob(Job job,
                              java.lang.String consumer_id)
                       throws GridException
Queues a Supplying Job.

Parameters:
job - Supplying Job to queue
Throws:
GridException - if a parameter is illegal

queryLocalJobStatus

public int queryLocalJobStatus(int job_id)
                        throws GridException
Returns the number of completed Tasks of target Local Job.

Returns:
number of completed Tasks of target Local Job
Throws:
GridException - if an unexpected error occurs

isSupplyingTaskRunning

public boolean isSupplyingTaskRunning(Task t)
                               throws GridException
Throws:
GridException

scheduleFirstLocalTask

public RequestContainer scheduleFirstLocalTask(boolean head_job_only)
                                        throws GridException
Selects for Local execution the first queued, yet unscheduled Local Task.

Parameters:
head_job_only - if true, selects Tasks from head Local Job only
Returns:
Local Task selected for Local execution as well as its scheduling context, or null if there is no Local Task to be scheduled
Throws:
GridException - if queue is corrupted

scheduleFirstConsumptionTask

public RequestContainer scheduleFirstConsumptionTask(boolean head_job_only)
                                              throws GridException
Selects for Consumption execution the first queued, yet unscheduled Local Task.

Parameters:
head_job_only - if true, selects Tasks from head Local Job only
Returns:
Local Task selected for Consumption execution, as well as its scheduling context, or null if there is no Local Task to be scheduled
Throws:
GridException - if queue is corrupted

scheduleNextConsumptionTask

public RequestContainer scheduleNextConsumptionTask(LocalQueueCursor lqc)
                                             throws GridException
Selects for Consumption execution the next queued, yet unscheduled Local Task

Returns:
Local Task selected for Consumption execution, as well as its scheduling context, or null if there remains no Local Task to be scheduled that is less prioritary than the Task memorized by the Local queue cursor
Throws:
GridException - if a parameter is illegal

scheduleFirstSupplyingTask

public RequestContainer scheduleFirstSupplyingTask()
                                            throws GridException
Selects for Local execution the first queued, yet unscheduled Supplying Task

Returns:
Supplying Task selected for Local execution, as well as its scheduling context, or null if there is no Supplying Task to be scheduled
Throws:
GridException - if queue is corrupted

scheduleBestRankedSupplyingTask

public RequestContainer scheduleBestRankedSupplyingTask()
                                                 throws GridException
Selects for Local execution the best Favors-ranked, queued, yet unscheduled Supplying Task

Returns:
Supplying Task selected for Local execution, as well as its scheduling context, or null if there is no Supplying Task to be scheduled
Throws:
GridException - if queue is corrupted

dequeueCompletedLocalTask

public RequestStatus dequeueCompletedLocalTask(Task t,
                                               long xstart_time,
                                               long runtime)
                                        throws GridException
Dequeues a Local Task after its execution has been completed

Parameters:
t - target Task
xstart_time - Task execution start time
runtime - Task run time
Returns:
completion level status (useful for Workflow Jobs only)
Throws:
GridException - if a parameter is illegal

dequeueCompletedConsumptionTask

public RequestStatus dequeueCompletedConsumptionTask(Task t,
                                                     long xstart_time,
                                                     long runtime)
                                              throws GridException
Dequeues a Consumption Task after its execution has been completed

Parameters:
t - target Task
xstart_time - Task execution start time
runtime - Task run time
Returns:
completion level status (useful for Workflow Jobs only)
Throws:
GridException - if a parameter is illegal

dequeueCompletedSupplyingTask

public RequestStatus dequeueCompletedSupplyingTask(Task t,
                                                   long xstart_time,
                                                   long runtime)
                                            throws GridException
Dequeues a Supplying Task after its execution has been completed

Parameters:
t - target Task
xstart_time - Task execution start time
runtime - Task run time
Returns:
completion level status
Throws:
GridException - if Task or queue is corrupted

requeueUnqueuedLocalTask

public void requeueUnqueuedLocalTask(Task t)
                              throws GridException
Requeues a Local Task that has been unqueued, but not executed, i.e. scheduled by the owner Peer.

Unqueued Tasks are in a bizarre state, as they have been removed from the waiting queue, but haven't yet been added to the running queue. It is therefore very important to put them back into the waiting queue.

Parameters:
t - target Task
Throws:
GridException - if Task or queue is corrupted

requeueUnqueuedConsumptionTask

public void requeueUnqueuedConsumptionTask(Task t)
                                    throws GridException
Requeues a Consumption Task that has been unqueued, but not executed, i.e. accepted by a Supplier Peer.

Unqueued Tasks are in a bizarre state, as they have been removed from the waiting queue, but haven't yet been added to the running queue. It is therefore very important to put them back into the waiting queue.

Parameters:
t - target Task
Throws:
GridException - if Task or queue is corrupted

requeuePreemptedLocalTask

public void requeuePreemptedLocalTask(Task t,
                                      long xstart_time,
                                      long runtime,
                                      java.lang.String supplier_id)
                               throws GridException
Requeues a Local Task after its execution has been cancelled.

Parameters:
t - target Local Task
xstart_time - Task execution start time
runtime - Task run time
supplier_id - Supplier Peer id, in this case equals to the Task owner Peer id
Throws:
GridException - if a parameter is illegal

requeuePreemptedConsumptionTask

public void requeuePreemptedConsumptionTask(Task t,
                                            long xstart_time,
                                            long runtime,
                                            java.lang.String supplier_id)
                                     throws GridException
Requeues a Consumption Task after its execution has been cancelled.

Parameters:
t - target Consumption Task
xstart_time - Task execution start time
runtime - Task run time
supplier_id - Supplier Peer id
Throws:
GridException - if a parameter is illegal

requeueUnqueuedSupplyingTask

public void requeueUnqueuedSupplyingTask(Task t)
                                  throws GridException
Requeues a Supplying Task that has been unqueued, but not executed, i.e. scheduled by the owner Peer.

Unqueued Tasks are in a bizarre state, as they have been removed from the waiting queue, but haven't yet been added to the running queue. It is therefore very important to put them back into the waiting queue.

Parameters:
t - target Task
Throws:
GridException - if Task or queue is corrupted

requeuePreemptedSupplyingTask

public void requeuePreemptedSupplyingTask(Task t,
                                          long xstart_time)
                                   throws GridException
Requeues a Supplying Task after its execution has been cancelled.

Parameters:
t - target Task
xstart_time - Task execution start time
Throws:
GridException - if Task or queue is corrupted

dequeueLocalJob

public void dequeueLocalJob(int job_id)
                     throws GridException
Dequeues a Local Job.

Note: as User-generated Job cancellation is not currently supported, this method is currently not implemented and will throw a GridException.

Parameters:
job_id - target job_id
Throws:
GridException - if Task or queue is corrupted

dequeueCancelledLocalTask

public void dequeueCancelledLocalTask(Task t,
                                      long xstart_time,
                                      long runtime,
                                      java.lang.String supplier_id)
                               throws GridException
Dequeues a Local Task after its execution has been cancelled.

Parameters:
t - target Local Task
xstart_time - Task execution start time
runtime - Task run time
supplier_id - Supplier Peer id, in this case equals to the Task owner Peer id
Throws:
GridException - if Task or queue is corrupted

dequeueWaitingLocalTask

public void dequeueWaitingLocalTask(Task t)
                             throws GridException
Dequeues a waiting Local Task.

Parameters:
t - target Task
Throws:
GridException - if Task or queue is corrupted

dequeueCancelledSupplyingTask

public void dequeueCancelledSupplyingTask(Task t,
                                          long xstart_time)
                                   throws GridException
Dequeues a Supplying Task after its execution has been cancelled.

Parameters:
t - target Task
xstart_time - Task execution start time
Throws:
GridException - if Task or queue is corrupted

dequeueWaitingSupplyingTask

public void dequeueWaitingSupplyingTask(boolean notify_consumer,
                                        Task t)
                                 throws GridException
Dequeues target waiting Supplying Task.

Parameters:
notify_consumer - communicates cancellation to consumer
t - target Task
Throws:
GridException - if Task or queue is corrupted

dequeueOldestWaitingSupplyingTaskOfConsumer

public void dequeueOldestWaitingSupplyingTaskOfConsumer(boolean notify_consumer,
                                                        java.lang.String consumer_id)
                                                 throws GridException
Dequeues the oldest waiting Supplying Task of target consumer.

Parameters:
notify_consumer - communicates cancellation to consumer
consumer_id - target consumer
Throws:
GridException - if Task or queue is corrupted

dequeueAllWaitingSupplyingTasks

public void dequeueAllWaitingSupplyingTasks(boolean notify_consumers)
                                     throws GridException
Dequeues all waiting Supplying Tasks.

Parameters:
notify_consumers - communicates cancellations to consumers
Throws:
GridException - if queue is corrupted

dequeueMostRecentWaitingSupplyingTasks

public void dequeueMostRecentWaitingSupplyingTasks(boolean notify_consumers,
                                                   int k)
                                            throws GridException
Dequeues the k most recently queued waiting Supplying Tasks.

Parameters:
notify_consumers - communicates cancellations to consumers
k - number of Supplying Tasks to dequeue
Throws:
GridException - if queue is corrupted

dequeueWorstRankedWaitingSupplyingTasks

public void dequeueWorstRankedWaitingSupplyingTasks(boolean notify_consumers,
                                                    int k)
                                             throws GridException
Dequeues the k worst NoF-ranked queued waiting Supplying Tasks.

Parameters:
notify_consumers - communicates cancellations to consumers
k - number of Supplying Tasks to dequeue
Throws:
GridException - if queue is corrupted

shouldPreemptWaitingSupplyingTasks

public boolean shouldPreemptWaitingSupplyingTasks()
Indicates whether waiting Supplying Tasks should be dequeued, i.e. cancelled, that is if the number of waiting Local Tasks exceeds LOCAL_Q_LEN_PREEMPTION_THRESHOLD

Returns:
true, if waiting Supplying Tasks should be dequeued, i.e. cancelled

preemptWaitingSupplyingTasks

public void preemptWaitingSupplyingTasks()
                                  throws GridException
Throws:
GridException

getRunningConsumers

public PeerProfile[] getRunningConsumers()
Profiles of all consumer Peers with running Supplying Tasks.

Returns:
profiles of all consumer Peers with running Supplying Tasks.

getWaitingConsumers

public PeerProfile[] getWaitingConsumers()
Profiles of all consumer Peers with waiting Supplying Tasks.

Returns:
profiles of all consumer Peers with waiting Supplying Tasks.

getAllConsumers

public PeerProfile[] getAllConsumers()
Profiles of all consumer Peers with queued Supplying Tasks.

Returns:
profiles of all consumer Peers with queued Supplying Tasks.

updateStatistics

public void updateStatistics()

Lightweight Bartering Grid

Copyright (c) 2005-2008, Cyril Briquet, parts Xavier Dalem.