FileDocCategorySizeDatePackage
TimedTaskList.javaAPI DocGlassfish v2 API6409Fri May 04 22:32:18 BST 2007com.sun.enterprise.util.scheduler

TimedTaskList

public class TimedTaskList extends Object
Maintains a list of elements in an increasing order. Each element is a TaskData object encapsulating an absolute execute time and the servicable task object.
$Source: /cvs/glassfish/appserv-commons/src/java/com/sun/enterprise/util/scheduler/TimedTaskList.java,v $
author
$Author: tcfujii $
version
1.0 $Revision: 1.4 $ $Date: 2007/05/05 05:32:17 $
see
PeriodicallyServicable

Fields Summary
private com.sun.enterprise.util.collection.DListNode
first
First dummy node.
private com.sun.enterprise.util.collection.DListNode
last
Last dummy node.
private int
size
Maintains the current size of the list.
Constructors Summary
protected TimedTaskList()
Constructor for TimedTaskList, created a new DList object.

    
                
     
    
        first = new DListNode(null);
        last = new DListNode(null);
        first.next = last;
        last.prev = first;
        first.prev = last.next = null;
    
Methods Summary
protected booleanaddTask(PeriodicallyServicable taskObj, int startingTime, long currentTime)
Add a new servicable task into the task list (ordered in increasing order).

param
taskObj servicable object to add.
param
startingTime wait for how long to start considering this task.
param
currentTime current time when executing other tasks.
return
boolean true on success, false otherwise.

        TaskData task = new TaskData();
        task.obj = taskObj;
        // decrement frequency time as it will be added on insertTask( ) anyway
        task.abs_execute_time = currentTime + startingTime - taskObj.getFrequency();
        return insertTask(task);
    
protected TaskDatagetFirstTask()
Remove first task from the ordered list, and return it.

return
first task on the queue.

        DListNode node = first;
        node = node.next;
        if(null!=node.next) // not the end
        {
            node.delink();
            --size;
            return (TaskData) node.object;
        }
        return null;
    
protected booleaninsertTask(TaskData task)
Insert task back into the task list (ordered in increasing order).

param
task object to execute in an order.
return
boolean true on success, false otherwise.

        task.abs_execute_time += ((PeriodicallyServicable)task.obj).getFrequency();
        DListNode addingNode = new DListNode(task);
        DListNode node = first;
        ++size;
        for(int i=0; i<size-1; i++)
        {
            node = node.next;
            long nodeTime = ((TaskData)node.object).abs_execute_time;
            if(nodeTime > task.abs_execute_time)
            {
                node.insertBefore(addingNode);
                return true;
            }
        }
        node.insertAfter(addingNode);
        return true;
      
protected booleanremoveTask(PeriodicallyServicable obj)
Removes the Servicable object from the task list permanently.

param
obj servicable object to remove.
return
boolean true on success, false otherwise.

        DListNode node = first;

        for(int i=0; i<size; i++)
        {
            node = node.next;
            PeriodicallyServicable nodeObj = ((TaskData)node.object).obj;

            if(nodeObj.equals(obj))
            {
                node.delink();
                --size;
                return true;
            }
        }
        return false;
    
protected intsize()
Return the size of the task list.

return
0 if empty, otherwise a number indicating the number of elements.

        return size;
    
public java.lang.StringtoString()
Prints information about the list and its contents.

return
String

        StringBuffer sb = new StringBuffer(100);
        sb.append(" [TimedTaskList: ");
        sb.append( size + " elements: ");
        DListNode node = first;
        while(null!=node.next && null!=node.next.object)
        {
            node = node.next;
            sb.append((int) ( ((TaskData)node.object).abs_execute_time / 1000) );
            sb.append(",");
        }
        sb.append("] ");
        return sb.toString();