uws.service.controller
Class DestructionTimeController

java.lang.Object
  extended by uws.service.controller.DestructionTimeController
All Implemented Interfaces:
java.io.Serializable

public class DestructionTimeController
extends java.lang.Object
implements java.io.Serializable

Let's controlling the destruction time of all jobs managed by a UWS. Thus it is possible to set a default and a maximum value. Moreover you can indicate whether the destruction time of jobs can be modified by the user or not.

Notes:

Version:
02/2011
Author:
Grégory Mantelet (CDS)
See Also:
Serialized Form

Nested Class Summary
static class DestructionTimeController.DateField
          Represents a date/time field.
 
Field Summary
protected  boolean allowModification
          Indicates whether the destruction time of jobs can be modified.
protected  int defaultInterval
          The default interval from the initialization to the destruction of the concerned job.
protected  DestructionTimeController.DateField defaultIntervalField
          The date-time field on which the default interval applies.
protected  java.util.Date defaultTime
          The default destruction time.
protected  int maxInterval
          The maximum interval from the initialization to the destruction of the concerned job.
protected  DestructionTimeController.DateField maxIntervalField
          The date-time field on which the maximum interval applies.
protected  java.util.Date maxTime
          The maximum destruction time.
static int NO_INTERVAL
          Default value of an interval: a null interval.
 
Constructor Summary
DestructionTimeController()
           
 
Method Summary
 boolean allowModification()
          Tells whether the destruction time of any managed job can be modified.
 void allowModification(boolean allowModification)
          Lets indicating whether the destruction time of any managed job can be modified.
 void control(AbstractJob jobToControl, java.util.Date dateToCheck)
          Controls the given destruction time.
 void control(AbstractJob job, java.util.Map<java.lang.String,java.lang.String> params)
          Extracts the destruction time from the given map and controls its value.
static java.text.DateFormat getDateFormat(AbstractJob job)
          Gets the date format used currently by the given job if not null or gets the default date format of a job (see AbstractJob.DEFAULT_DATE_FORMAT).
 int getDefaultDestructionInterval()
          Gets the default interval value.
 java.util.Date getDefaultDestructionTime()
          Gets the default destruction time: either computed with an interval of time or obtained directly by a default destruction time.
 DestructionTimeController.DateField getDefaultIntervalField()
          Gets the date-time field of the default interval.
 int getMaxDestructionInterval()
          Gets the maximum interval value.
 java.util.Date getMaxDestructionTime()
          Gets the maximum destruction time: either computed with an interval of time or obtained directly by a maximum destruction time.
 DestructionTimeController.DateField getMaxIntervalField()
          Gets the date-time field of the maximum interval.
 void init(java.util.Map<java.lang.String,java.lang.String> params)
          Controls the destruction time given in the map or initializes it with the default value if not present in the map.
 void setDefaultDestructionInterval(int defaultDestructionInterval)
          Sets the default interval in minutes from the initialization to the destruction of the concerned job.
 void setDefaultDestructionInterval(int defaultDestructionInterval, DestructionTimeController.DateField timeField)
          Sets the default interval (in the given unit) from the initialization to the destruction of the concerned job.
 void setDefaultDestructionTime(AbstractJob job)
          Sets the destruction time of the given job with the default value.
 void setDefaultDestructionTime(java.util.Date defaultDestructionTime)
          Sets the default destruction time.
 void setDestructionTime(AbstractJob job, java.util.Date date)
          Controls the given value and sets the destruction time of the given job with this value.
 void setMaxDestructionInterval(int maxDestructionInterval)
          Sets the maximum interval in minutes from the initialization to the destruction of the concerned job.
 void setMaxDestructionInterval(int maxDestructionInterval, DestructionTimeController.DateField timeField)
          Sets the maximum interval (in the given unit) from the initialization to the destruction of the concerned job.
 void setMaxDestructionTime(java.util.Date maxDestructionTime)
          Sets the maximum destruction time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_INTERVAL

public static final int NO_INTERVAL
Default value of an interval: a null interval.

See Also:
Constant Field Values

defaultTime

protected java.util.Date defaultTime
The default destruction time.


defaultIntervalField

protected DestructionTimeController.DateField defaultIntervalField
The date-time field on which the default interval applies.


defaultInterval

protected int defaultInterval
The default interval from the initialization to the destruction of the concerned job.


maxTime

protected java.util.Date maxTime
The maximum destruction time.


maxIntervalField

protected DestructionTimeController.DateField maxIntervalField
The date-time field on which the maximum interval applies.


maxInterval

protected int maxInterval
The maximum interval from the initialization to the destruction of the concerned job.


allowModification

protected boolean allowModification
Indicates whether the destruction time of jobs can be modified.

Constructor Detail

DestructionTimeController

public DestructionTimeController()
Method Detail

getDefaultDestructionTime

public final java.util.Date getDefaultDestructionTime()
Gets the default destruction time: either computed with an interval of time or obtained directly by a default destruction time.

Returns:
The default destruction time (null means that jobs may stay forever).

setDefaultDestructionTime

public final void setDefaultDestructionTime(java.util.Date defaultDestructionTime)

Sets the default destruction time.

Note: If there was a default interval, it is reset and so the given destruction time will be used by getDefaultDestructionTime().

Parameters:
defaultDestructionTime - The default destruction time to set (null means jobs may stay forever).

getDefaultDestructionInterval

public final int getDefaultDestructionInterval()

Gets the default interval value.

Note: To get the corresponding unit, use getDefaultIntervalField() and Enum.name().

Returns:
The default destruction interval.

getDefaultIntervalField

public final DestructionTimeController.DateField getDefaultIntervalField()
Gets the date-time field of the default interval.

Returns:
The default interval field.

setDefaultDestructionInterval

public final void setDefaultDestructionInterval(int defaultDestructionInterval)

Sets the default interval in minutes from the initialization to the destruction of the concerned job.

Note: If there was a default destruction time, it is reset and so the given interval will be used by getDefaultDestructionTime().

Parameters:
defaultDestructionInterval - The default destruction interval (NO_INTERVAL, 0 or a negative value mean the job may stay forever).
See Also:
setDefaultDestructionInterval(int, DateField)

setDefaultDestructionInterval

public final void setDefaultDestructionInterval(int defaultDestructionInterval,
                                                DestructionTimeController.DateField timeField)

Sets the default interval (in the given unit) from the initialization to the destruction of the concerned job.

Note: If there was a default destruction time, it is reset and so the given interval will be used by getDefaultDestructionTime().

Parameters:
defaultDestructionInterval - The default destruction interval (NO_INTERVAL, 0 or a negative value mean the job may stay forever).
timeField - The unit of the interval (null means the job may stay forever).

getMaxDestructionTime

public final java.util.Date getMaxDestructionTime()
Gets the maximum destruction time: either computed with an interval of time or obtained directly by a maximum destruction time.

Returns:
The maximum destruction time (null means that jobs may stay forever).

setMaxDestructionTime

public final void setMaxDestructionTime(java.util.Date maxDestructionTime)

Sets the maximum destruction time.

Note: If there was a maximum interval, it is reset and so the given destruction time will be used by getMaxDestructionTime().

Parameters:
maxDestructionTime - The maximum destruction time to set (null means jobs may stay forever).

getMaxDestructionInterval

public final int getMaxDestructionInterval()

Gets the maximum interval value.

Note: To get the corresponding unit, use getMaxIntervalField() and Enum.name().

Returns:
The maximum destruction interval.

getMaxIntervalField

public final DestructionTimeController.DateField getMaxIntervalField()
Gets the date-time field of the maximum interval.

Returns:
The maximum interval field.

setMaxDestructionInterval

public final void setMaxDestructionInterval(int maxDestructionInterval)

Sets the maximum interval in minutes from the initialization to the destruction of the concerned job.

Note: If there was a maximum destruction time, it is reset and so the given interval will be used by getMaxDestructionTime().

Parameters:
maxDestructionInterval - The maximum destruction interval (NO_INTERVAL, 0 or a negative value mean the job may stay forever).
See Also:
setMaxDestructionInterval(int, DateField)

setMaxDestructionInterval

public final void setMaxDestructionInterval(int maxDestructionInterval,
                                            DestructionTimeController.DateField timeField)

Sets the maximum interval (in the given unit) from the initialization to the destruction of the concerned job.

Note: If there was a maximum destruction time, it is reset and so the given interval will be used by getMaxDestructionTime().

Parameters:
maxDestructionInterval - The maximum destruction interval (NO_INTERVAL, 0 or a negative value mean the job may stay forever).
timeField - The unit of the interval (null means the job may stay forever).

allowModification

public final boolean allowModification()
Tells whether the destruction time of any managed job can be modified.

Returns:
true if the destruction time can be modified, false otherwise.

allowModification

public final void allowModification(boolean allowModification)
Lets indicating whether the destruction time of any managed job can be modified.

Parameters:
allowModification - true if the destruction time can be modified, false otherwise.

init

public void init(java.util.Map<java.lang.String,java.lang.String> params)
          throws UWSException
Controls the destruction time given in the map or initializes it with the default value if not present in the map.

Parameters:
params - The map of all parameters to use for the creation of a job.
Throws:
UWSException - If the destruction time given in the map is not valid.
See Also:
control(AbstractJob, Map)

control

public void control(AbstractJob job,
                    java.util.Map<java.lang.String,java.lang.String> params)
             throws UWSException
Extracts the destruction time from the given map and controls its value.

Parameters:
job - The job whose the destruction time will be set.
params - The map which contains the new destruction time of the given job.
Throws:
UWSException - If the new destruction time does not respect the date format used by the given job or the default date format or if the destruction time of the given job can not be modified or if the given value exceeds the maximum value.
See Also:
control(AbstractJob, Date)

control

public void control(AbstractJob jobToControl,
                    java.util.Date dateToCheck)
             throws UWSException
Controls the given destruction time.

Parameters:
jobToControl - The job whose the destruction time will be updated by the given value.
dateToCheck - The new destruction time of the given value.
Throws:
UWSException - If the current phase of the job doesn't allow any modification or if this controller forbids the modification of the destruction time or if the new destruction time exceeds the maximum value.

setDefaultDestructionTime

public void setDefaultDestructionTime(AbstractJob job)
                               throws UWSException
Sets the destruction time of the given job with the default value.

Parameters:
job - The job whose the destruction time must be set.
Throws:
UWSException - If it is impossible to set the destruction time of the given job (for instance, if the job is running or is finished).
See Also:
setDestructionTime(AbstractJob, Date)

setDestructionTime

public void setDestructionTime(AbstractJob job,
                               java.util.Date date)
                        throws UWSException
Controls the given value and sets the destruction time of the given job with this value.

Parameters:
job - The job whose the destruction time must be set.
date - The new destruction time of the given job.
Throws:
UWSException - If the current phase of the job doesn't allow any modification or if this controller forbids the modification of the destruction time or if the new destruction time exceeds the maximum value.
See Also:
control(AbstractJob, Date), AbstractJob.setDestructionTime(Date)

getDateFormat

public static final java.text.DateFormat getDateFormat(AbstractJob job)
Gets the date format used currently by the given job if not null or gets the default date format of a job (see AbstractJob.DEFAULT_DATE_FORMAT).

Parameters:
job - The job whose the date format must be extracted.
Returns:
A valid date format understood by the given job (if the given job is null the date format is the default one and so, it is surely understood at the job creation).
See Also:
AbstractJob.getDateFormat(), AbstractJob.DEFAULT_DATE_FORMAT