public class DefaultDestructionManager extends java.lang.Object implements DestructionManager
DestructionManager
interface. Its
goal is to manage the automatic destruction any given jobs.
Jobs can be added thanks to update(UWSJob)
and removed with
remove(UWSJob)
. All added jobs are stored in a TreeSet
which sorts them by ascending destruction time. The job which must be
destroyed in first is used to start a timer. This one will destroyed the job
once its destruction time is reached.
The list of jobs to destroy is supposed to be updated each time the
destruction time of a job is changed. This update works only if the job
knows its jobs list (UWSJob.getJobList()
!= null) and its jobs list
has a destruction manager.
Note:
The stop()
function lets stop this manager to watch for
destructions of job until refresh()
or update(UWSJob)
or
remove(UWSJob)
is called. When stopped, the inner timer is canceled
and set to NULL ; no more thread resources is used.
Modifier and Type | Class and Description |
---|---|
protected static class |
DefaultDestructionManager.TimeComparator
Lets a TreeSet or a TreeMap sorting
UWSJob instances in an
ascending order and according to their destruction time. |
Modifier and Type | Field and Description |
---|---|
protected java.util.Date |
currentDate
The date used by the timer to trigger the destruction of
currentJob . |
protected UWSJob |
currentJob
The job currently planned for destruction.
|
protected java.util.TreeSet<UWSJob> |
jobsToDestroy
The list of jobs to destroy.
|
protected java.util.Timer |
timDestruction
Timer for the job destruction time.
|
Constructor and Description |
---|
DefaultDestructionManager()
Builds the default destruction manager.
|
Modifier and Type | Method and Description |
---|---|
protected void |
destroyJob(UWSJob job)
Merely destroys the given job
(if not NULL and not
ARCHIVED ). |
int |
getNbJobsToDestroy()
Gets the total number of jobs planned to be destroyed.
|
java.util.Date |
getNextDestruction()
Gets the destruction date/time of the job currently planned for destruction.
|
java.lang.String |
getNextJobToDestroy()
Gets the ID of the job currently planned for destruction.
|
boolean |
isRunning()
Returns
true if currentDate is different from NULL. |
void |
refresh()
First, check the currently planned job:
if
currentDate is past, the timer is stopped.
else if another job must be destroyed before the current one
or if the destruction time of the current job has been
changed, the timer is stopped and the job is re-added into
the list of jobs to destroy.
Then, only if there is no currently planned job:
Clean the list of jobs to destroy (jobs which are supposed
to be destroyed are destroyed and the others are only
removed from this manager).
Restart the timer with the first job to destroy.
|
void |
remove(UWSJob job)
Merely removes the given job from the list of jobs to destroyed.
|
void |
stop()
|
void |
update(UWSJob job)
This function does something only if the given job knows its jobs list
and has a valid destruction time.
|
protected final java.util.TreeSet<UWSJob> jobsToDestroy
DefaultDestructionManager.TimeComparator
.protected transient java.util.Timer timDestruction
Once the date-time indicated by this timer is reached the job is destroyed and removed from the jobs list.
protected UWSJob currentJob
protected java.util.Date currentDate
currentJob
.public DefaultDestructionManager()
The list of jobs to destroy is initialized so that sorting jobs by ascending destruction time.
DefaultDestructionManager.TimeComparator
public final void stop()
stop
in interface DestructionManager
protected final void destroyJob(UWSJob job)
ARCHIVED
).job
- The job to destroy.UWSJob.getJobList()
,
JobList.destroyJob(String)
public final boolean isRunning()
true
if currentDate
is different from NULL.isRunning
in interface DestructionManager
public final java.util.Date getNextDestruction()
DestructionManager
getNextDestruction
in interface DestructionManager
public final java.lang.String getNextJobToDestroy()
DestructionManager
getNextJobToDestroy
in interface DestructionManager
public final int getNbJobsToDestroy()
DestructionManager
getNbJobsToDestroy
in interface DestructionManager
public void refresh()
currentDate
is past, the timer is stopped.refresh
in interface DestructionManager
DestructionManager.refresh()
,
stop()
,
destroyJob(UWSJob)
public void update(UWSJob job)
destroyJob(UWSJob)
).refresh()
).update
in interface DestructionManager
job
- The job whose the destruction time may have changed.DestructionManager.update(uws.job.UWSJob)
,
destroyJob(UWSJob)
,
refresh()
public void remove(UWSJob job)
remove
in interface DestructionManager
job
- The job to remove.DestructionManager.remove(uws.job.UWSJob)
,
stop()
,
refresh()