com.gargoylesoftware.htmlunit.javascript.background
Class JavaScriptJobManagerImpl

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl
All Implemented Interfaces:
JavaScriptJobManager, Serializable

public class JavaScriptJobManagerImpl
extends Object
implements JavaScriptJobManager

Default implementation of JavaScriptJobManager.

This job manager class is guaranteed not to keep old windows in memory (no window memory leaks).

This job manager is serializable, but any running jobs are transient and are not serialized.

Version:
$Revision: 5842 $
Author:
Daniel Gredler, Katharina Probst, Amit Manjhi
See Also:
MemoryLeakTest, Serialized Form

Constructor Summary
JavaScriptJobManagerImpl(WebWindow window)
          Creates a new instance.
 
Method Summary
 int addJob(JavaScriptJob job, Page page)
          Adds the specified job to this job manager, assigning it an ID.
 JavaScriptJob getEarliestJob()
          Gets the earliest job for this manager.
 int getJobCount()
          Returns the number of active jobs, including jobs that are currently executing and jobs that are waiting to execute.
 void removeAllJobs()
          Removes all jobs from the execution queue.
 void removeJob(int id)
          Removes the specified job from the execution queue.
 boolean runSingleJob(JavaScriptJob givenJob)
          Runs the provided job if it is the right time for it.
 void shutdown()
          Shuts down this job manager and stops all of its jobs.
 void stopJob(int id)
          Stops the specified job and removes it from the execution queue, not even allowing the job to finish if it is currently executing.
 int waitForJobs(long timeoutMillis)
          Blocks until all active jobs have finished executing.
 int waitForJobsStartingBefore(long delayMillis)
          Blocks until all jobs scheduled to start executing before (now + delayMillis) have finished executing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaScriptJobManagerImpl

public JavaScriptJobManagerImpl(WebWindow window)
Creates a new instance.

Parameters:
window - the window associated with the new job manager
Method Detail

getJobCount

public int getJobCount()
Returns the number of active jobs, including jobs that are currently executing and jobs that are waiting to execute.

Specified by:
getJobCount in interface JavaScriptJobManager
Returns:
the number of active jobs

addJob

public int addJob(JavaScriptJob job,
                  Page page)
Adds the specified job to this job manager, assigning it an ID. If the specified page is not currently loaded in the window which owns this job manager, the operation fails and this method returns 0.

Specified by:
addJob in interface JavaScriptJobManager
Parameters:
job - the job to add to the job manager
page - the page which is trying to add the job
Returns:
the ID assigned to the job

removeJob

public void removeJob(int id)
Removes the specified job from the execution queue. This doesn't interrupt the job if it is currently running.

Specified by:
removeJob in interface JavaScriptJobManager
Parameters:
id - the ID of the job to be removed from the execution queue

stopJob

public void stopJob(int id)
Stops the specified job and removes it from the execution queue, not even allowing the job to finish if it is currently executing.

Specified by:
stopJob in interface JavaScriptJobManager
Parameters:
id - the ID of the job to be stopped

removeAllJobs

public void removeAllJobs()
Removes all jobs from the execution queue. This doesn't interrupt any jobs that may be currently running.

Specified by:
removeAllJobs in interface JavaScriptJobManager

waitForJobs

public int waitForJobs(long timeoutMillis)
Blocks until all active jobs have finished executing. If a job is scheduled to begin executing after (now + timeoutMillis), this method will wait for timeoutMillis milliseconds and then return false.

Specified by:
waitForJobs in interface JavaScriptJobManager
Parameters:
timeoutMillis - the maximum amount of time to wait (in milliseconds); may be negative, in which case this method returns immediately
Returns:
the number of background JavaScript jobs still executing or waiting to be executed when this method returns; will be 0 if there are no jobs left to execute

waitForJobsStartingBefore

public int waitForJobsStartingBefore(long delayMillis)
Blocks until all jobs scheduled to start executing before (now + delayMillis) have finished executing. If there is no background JavaScript task currently executing, and there is no background JavaScript task scheduled to start executing within the specified time, this method returns immediately -- even if there are tasks scheduled to be executed after (now + delayMillis).

Specified by:
waitForJobsStartingBefore in interface JavaScriptJobManager
Parameters:
delayMillis - the delay which determines the background tasks to wait for (in milliseconds); may be negative, as it is relative to the current time
Returns:
the number of background JavaScript jobs still executing or waiting to be executed when this method returns; will be 0 if there are no jobs left to execute

shutdown

public void shutdown()
Shuts down this job manager and stops all of its jobs.

Specified by:
shutdown in interface JavaScriptJobManager

getEarliestJob

public JavaScriptJob getEarliestJob()
Gets the earliest job for this manager.

Specified by:
getEarliestJob in interface JavaScriptJobManager
Returns:
null if none

runSingleJob

public boolean runSingleJob(JavaScriptJob givenJob)
Runs the provided job if it is the right time for it.

Specified by:
runSingleJob in interface JavaScriptJobManager
Parameters:
givenJob - the job to run
Returns:
returns true if the job was run.


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.