Package tenapull.run
Class DbManagerJob
java.lang.Object
tenapull.run.Job
tenapull.run.DbManagerJob
public class DbManagerJob extends Job
DbManager Job manages the pile of dbTasks which other threads will provide. Because multi-threaded
DB write operations tend to cause many exceptions, the critical dbTasks are all handled by a single
thread whose job is strictly to execute these tasks. The thread actually executing the tasks runs
the DbManager.Helper job, while the DbManager job/thread itself merely manages the pile of db tasks
coming in from the child jobs.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDbManagerJob.ChildJobs which implement DbManager.Child are the jobs which do all of the fetching and pre-processing before providing dbTasks to the db manager. -
Field Summary
Fields Modifier and Type Field Description static intMAX_EXCEPTIONSThe constant MAX_EXCEPTIONS.static intMAX_JOBS_TASKSThe constant MAX_JOBS_TASKS.static intNUM_HELPERSThe number of helper jobs.static longWAIT_FOR_CHILD_JOB_TIMEOUT_MSThe constant WAIT_FOR_CHILD_JOB_TIMEOUT_MS. -
Constructor Summary
Constructors Constructor Description DbManagerJob(java.lang.String name)Instantiates a new Db manager job with the provided nameDbManagerJob(java.lang.String name, java.util.List<DbManagerJob.Child> childJobs)Instantiates a new Db manager job with the provided name and list of child jobs -
Method Summary
Modifier and Type Method Description protected booleanexceptionHandler(java.lang.Exception e, Job.Stage stage)Handles any exceptions thrown by isReady, fetch, process, and output methods.protected booleanexceptionHandler(java.lang.Exception e, Job.Stage stage, Job runningJob)If there is an exception, the exceptionCount is incremented, then checked to see if it has surpassed MAX_EXCEPTIONS.protected voidfetch(NessusClient client)Fetch any API resources, using the NessusClient provided by the worker thread.java.lang.StringgetNameForNext()Gets the name set for the next dbManager jobprotected booleanisReady()Is ready boolean.protected voidoutput()Perform any outputting of the processed data The job will remain in the OUTPUT stage until fetch returns without an exception, or the job is marked as failed.protected voidprocess()Perform any processing of the fetched data The job will remain in the PROCESS stage until fetch returns without an exception, or the job is marked as failed.protected booleanprocessLoop(Job runningJob)Process loop boolean.voidsetNameForNext(java.lang.String name)Sets name for the next DbManager job to be created from the list of nextJobs, after this dbManager is finishedMethods inherited from class tenapull.run.Job
addJob, addJobs, equals, failed, getAccessor, getStage, notifyOfExit, start, tryAgainIn, waitForExit
-
Field Details
-
NUM_HELPERS
public static final int NUM_HELPERSThe number of helper jobs. Experience has shown that any more than 1 will cause exceptions- See Also:
- Constant Field Values
-
MAX_JOBS_TASKS
public static final int MAX_JOBS_TASKSThe constant MAX_JOBS_TASKS. The limit on the number of tasks which will be allowed to pile up, before new child jobs are released to the main thread for scheduling in the readyJobs queue- See Also:
- Constant Field Values
-
MAX_EXCEPTIONS
public static final int MAX_EXCEPTIONSThe constant MAX_EXCEPTIONS. The maximum number of exceptions that will be allowed before the job exits with failure status. Prevents infinite loops of exceptions and rescheduling the jobs causing them.- See Also:
- Constant Field Values
-
WAIT_FOR_CHILD_JOB_TIMEOUT_MS
public static final long WAIT_FOR_CHILD_JOB_TIMEOUT_MSThe constant WAIT_FOR_CHILD_JOB_TIMEOUT_MS. The maximum amount of time the DbManager job will wait for a child job to finish before double-checking the status of other tasks or jobs. This is probably unnecessary, but was included as a fail-safe in case of a bug or mistake in the DbManager logic...- See Also:
- Constant Field Values
-
-
Constructor Details
-
DbManagerJob
public DbManagerJob(java.lang.String name)Instantiates a new Db manager job with the provided name- Parameters:
name- the name
-
DbManagerJob
Instantiates a new Db manager job with the provided name and list of child jobs- Parameters:
name- the namechildJobs- the child jobs
-
-
Method Details
-
isReady
protected boolean isReady()Description copied from class:JobIs ready boolean. Indicates whether the job is ready to run yet. If false is returned, the job will be placed in the JobFactory's waitingJobs queue, with either the default wait time, or another wait time if a new one is set before returning false from isReady. The job will remain in the IDLE stage until isReady returns true, or the job is marked as failed. Failed jobs are not marked as DONE until after the method has returned -
fetch
Description copied from class:JobFetch any API resources, using the NessusClient provided by the worker thread. The job will remain in the FETCH stage until fetch returns without an exception, or the job is marked as failed. Failed jobs are not marked as DONE until after the method has returned -
process
protected void process() throws java.lang.ExceptionDescription copied from class:JobPerform any processing of the fetched data The job will remain in the PROCESS stage until fetch returns without an exception, or the job is marked as failed. Failed jobs are not marked as DONE until after the method has returned -
processLoop
Process loop boolean.- Parameters:
runningJob- the running job- Returns:
- the boolean
- Throws:
java.lang.Exception- the exception
-
output
protected void output()Description copied from class:JobPerform any outputting of the processed data The job will remain in the OUTPUT stage until fetch returns without an exception, or the job is marked as failed. Failed jobs are not marked as DONE until after the method has returned -
exceptionHandler
Description copied from class:JobHandles any exceptions thrown by isReady, fetch, process, and output methods. Return true if the operation should be attempted again immediately. Mark as failed to permanently end the job. Otherwise, the job will be placed in the delayedJobs queue, and put back into readyJobs once its wait time is up- Specified by:
exceptionHandlerin classJob- Parameters:
e- the estage- the stage- Returns:
- the boolean
-
exceptionHandler
If there is an exception, the exceptionCount is incremented, then checked to see if it has surpassed MAX_EXCEPTIONS. If it has, the job is marked as failed and false is returned. Otherwise, the true is returned and processing continues.- Parameters:
e- the estage- the stagerunningJob- the running job- Returns:
- the boolean
-
setNameForNext
public void setNameForNext(java.lang.String name)Sets name for the next DbManager job to be created from the list of nextJobs, after this dbManager is finished- Parameters:
name- the name of the next dbManager
-
getNameForNext
public java.lang.String getNameForNext()Gets the name set for the next dbManager job- Returns:
- the name for next dbManager job
-