Fields Summary |
---|
static Logger | _logger |
protected Thread | _threadInternal Thread holder |
private static PeriodicEventScheduler | _instanceScheduler instance holder |
private static Object | instanceLockInstance lock |
protected TimedTaskList | sortedListSorted task list |
protected boolean | bRunThread runs while bRun is true (unless shutdown) |
protected boolean | bDebugDebug flag |
protected transient long | counterCurrent time holder |
protected long | delay_time_approxDelay for time approximation |
protected com.sun.enterprise.util.ApproximateClock | clockApproximate clock holder |
private PeriodicallyServicable | executingTaskMaintained by the run() method |
private boolean | removeExecutingTaskOn remove, a check is made if the executingTask is the one to be removed. This is the flag set. |
Methods Summary |
---|
public synchronized boolean | addTimeRepeatableTask(PeriodicallyServicable obj, int startingTime)Add a PeriodicallyServicable object to the 'timed task execution queue'.
if(startingTime < 0 || obj.getFrequency() < 1)
{
//Bug 4677074 if(bDebug) System.out.println("PeriodicEventScheduler::addTimeRepeatableTask() rejected task" + obj.toString());
//Bug 4677074 begin
if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"PeriodicEventScheduler::addTimeRepeatableTask() rejected task" + obj.toString());
//Bug 4677074 end
return false;
}
boolean bool = sortedList.addTask(obj, startingTime, counter);
synchronized(instanceLock)
{
instanceLock.notify();
}
return bool;
|
public static com.sun.enterprise.util.scheduler.PeriodicEventScheduler | getInstance()Method to access the PeriodicEventScheduler singleton.
_instance = new PeriodicEventScheduler();
return _instance;
|
private long | getTime()Get approximate or actual time.
return clock.getActualTime(); // TODO : change actual time to perhaps approx time
|
protected synchronized boolean | insertSorted(TaskData taskObj)Insert the task object into the task list.
return sortedList.insertTask(taskObj);
|
public synchronized boolean | removeTimeRepeatableTask(PeriodicallyServicable obj)Remove the servicable object from the task list.
if(executingTask.equals(obj))
{
removeExecutingTask=true;
return true;
}
else
return sortedList.removeTask(obj);
|
public void | run()Start running the thread.
TaskData task=null;
while(bRun)
{
try
{
//if(bDebug) System.out.println("---run()" + sortedList.toString() + "---");
//Bug 4677074 begin
//if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"---run()" + sortedList.toString() + "---");
//Bug 4677074 end
task = sortedList.getFirstTask();
//if(bDebug) System.out.println("---run()" + sortedList.toString() + "+++");
//Bug 4677074 begin
//if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"---run()" + sortedList.toString() + "+++");
//Bug 4677074 end
if(null==task)
{
synchronized(instanceLock)
{
instanceLock.wait();
continue; // fetches a task
}
}
executingTask=task.obj;
// got the first task
counter = getTime();
long sleepingTime = task.abs_execute_time - counter;
if(sleepingTime > 0L)
{
try
{
//Bug 4677074 if(bDebug) System.out.println("Current time=" + (int)(counter/1000) + ", Sleeping for " + sleepingTime + " msec.");
//Bug 4677074 begin
if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"Current time=" + (int)(counter/1000) + ", Sleeping for " + sleepingTime + " msec.");
//Bug 4677074 end
Thread.sleep( sleepingTime );
}
catch(InterruptedException ieInner)
{
//Bug 4677074 if(bDebug) System.out.println("PeriodicEventScheduler::run() > " + ieInner);
//Bug 4677074 begin
if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"PeriodicEventScheduler::run() > " + ieInner);
//Bug 4677074 end
}
}else
{
// a decision has to be made immediately if we want to execute
// the task even if we missed the right time to execute it
if (!task.obj.getExecutionTolerance(Math.abs(sleepingTime)) )
{
//Bug 4677074 if(bDebug) System.out.println("Missed scheduling for " + task.obj.toString());
//Bug 4677074 begin
if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"Missed scheduling for " + task.obj.toString());
//Bug 4677074 end
continue;
} else
{
//Bug 4677074 if(bDebug) System.out.println("Executing after missing scheduling for " + task.obj.toString());
//Bug 4677074 begin
if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"Executing after missing scheduling for " + task.obj.toString());
//Bug 4677074 end
}
}
// now we can execute this task in multiple ways, one is on this thread,
// other is on other task queues (by putting this task on the front of the Q)
task.obj.service();
}catch(InterruptedException ieOuter)
{
//Bug 4677074 if(bDebug) System.out.println("PeriodicEventScheduler::run() > " + ieOuter);
//Bug 4677074 begin
if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"PeriodicEventScheduler::run() > " + ieOuter);
//Bug 4677074 end
}
catch(Exception e)
{
System.out.println("PeriodicEventScheduler::run() > " + e);
//Bug 4677074 begin
_logger.log(Level.WARNING,"iplanet_util.generic_exception",e);
//Bug 4677074 end
}
finally
{
if (null!=task)
{
counter = getTime();
// now put this task back into the Q
task.abs_execute_time = counter;
//if(bDebug) System.out.println("Adding in list " + task.obj.toString());
//Bug 4677074 begin
//if(com.sun.enterprise.util.logging.Debug.enabled) _logger.log(Level.FINE,"Adding in list " + task.obj.toString());
//Bug 4677074 end
if(!removeExecutingTask)
insertSorted(task);
else
removeExecutingTask=false;
executingTask=null;
}
}
} // while
|
public java.lang.String | toString()
return "[PeriodicEventScheduler: " + sortedList.toString() + "]";
|