Class Trigger

All Implemented Interfaces:
Serializable, Comparable

public class Trigger extends GeneratedTrigger
A Trigger allows the definition of schedules for the automatic execution of Jobs and BatchJobs. There are several attributes which allow you to define the rules, when the Trigger should fire and therefore the assigned Job/BatchJob will be executed. First of all the following six attributes allow the definition of time components:
  • Second: 0 to 59, or -1 for any
  • Minute: 0 to 59, or -1 for any
  • Hour: 0 to 23, or -1 for any
  • Day: 1 to 31, or -1 for any
  • Month: 1 to 12, or -1 for any
  • Year: for example 2004, or -1 for any
The default value for all of these attributes is -1, which means that the Trigger will be fired every time the related TriggerTaskRunner activates it. The specified time attributes are either interpreted as relative or absolute values depending on the value of GeneratedTrigger.isRelative().

Some examples:

Year Month Day Hour Minute Second relative daysOfWeek weekInterval Description
-1 -1 -1 5 0 0 false --- --- every day at 5:00
-1 -1 -1 12 12 12 false --- --- every 12th of a month at 12:12:12
-1 -1 -1 6 0 0 true --- --- every six hours
-1 -1 -1 12 0 0 false MO,WE,FR --- every Monday, Wednesday, Friday at 12:00
-1 -1 -1 12 0 0 false MO,WE,FR 2 every 2 weeks, Monday, Wednesday, Friday at 12:00
See Also:
  • Constructor Details

    • Trigger

      public Trigger()
  • Method Details

    • createItem

      protected Item createItem(SessionContext ctx, ComposedType type, Item.ItemAttributeMap allAttributes) throws JaloBusinessException
      Description copied from class: Item
      Has to be implemented for each concrete subtype of item. This method is responsible for creating a new item instance ( by calling managers, ejb homes, etc. ) during ComposedType.newInstance(Map).

      In case this method uses any of the attribute values during creation it is required to override Item.getNonInitialAttributes(SessionContext, ItemAttributeMap) too.
      Sn example:

      
       public static final String MY_ATTRIBUTE = "someAttribute"; ... protected Item createItem(SessionContext
       ctx, ComposedType type, Map allAttributes ) throws JaloBusinessException { MyManager man = ... return
       man.createMyItem( (String)allAttributes.get(MY_ATTRIBUTE) );
       // here MY_ATTRIBUTE is used for creation, so it must not be set again } protected Map getNonInitialAttributes(
       SessionContext ctx, Map allAttributes ) { // let superclass remove its own initial attributes Map ret =
       super.getNonInitialAttributes( ctx, allAttributes );
       // remove MY_ATTRIBUTE from all attributes since if has already been set ret.remove(MY_ATTRIBUTE); return ret; }
      
       
      Overrides:
      createItem in class GeneratedTrigger
      Parameters:
      ctx - the current session context which this item is created within
      type - the actual item type ( since subtypes may not provide a own jalo class this may be different from the type which this method was implemented for )
      Returns:
      the new item instance
      Throws:
      JaloBusinessException - indicates an error during creation - any changes will be rollbacked
    • activate

      @Deprecated(since="ages", forRemoval=false) public void activate()
      Deprecated.
      Executes the assigned Job using the assigned CronJob if the next activation time ((@link #getActivationTime()} is less or equal than the current system time.
    • calculateNextTimeRelativeMode

      protected Calendar calculateNextTimeRelativeMode(Calendar relativeTo)
    • calculateFixedTime

      protected Calendar calculateFixedTime(Calendar relativeTo)
    • hasYear

      protected boolean hasYear()
    • hasMonth

      protected boolean hasMonth()
    • hasDay

      protected boolean hasDay()
    • hasDayOfWeek

      protected boolean hasDayOfWeek()
    • hasWeekInterval

      protected boolean hasWeekInterval()
    • hasHour

      protected boolean hasHour()
    • hasMinute

      protected boolean hasMinute()
    • hasSecond

      protected boolean hasSecond()
    • getNextTime

      @Deprecated(since="ages", forRemoval=false) public long getNextTime(long time)
      Deprecated.
      Returns the next activation time for the Trigger in relation to the specified time.
      Parameters:
      time - the time for which the next activation time should be calculated
      Returns:
      the next activation time for the Trigger in relation to the specified time
    • getNextTime

      @Deprecated(since="ages", forRemoval=false) public long getNextTime(Calendar relativeTo)
      Deprecated.
      Returns the next activation time for the Trigger in relation to the specified calendar.

      Use this method e.g. for different first day of week modes.

      Parameters:
      relativeTo - the calendar which the next activation time should be calculated relatively for
      Returns:
      the next activation time for the Trigger in relation to the specified time
    • toString

      public String toString()
      Returns the String representation of the Trigger. String format:
      Trigger[ cronjob= , active=true|false, [second=xy,][minute=xy,][hour=xy,][day=xy,][month=xy,][year=xy,][relative=xy,][days of week=xy,][week interval=xy,][date range=xy,] next activationtime=xy ]
      Overrides:
      toString in class Item
      Returns:
      the String representation of the Trigger
    • getCronJobForExecution

      protected CronJob getCronJobForExecution()
      If cronJob is null and job is a triggerable job, make a new cronJob
      Returns:
      The (possibly new) cronJob
    • setActivationTime

      @Deprecated(since="ages", forRemoval=false) public void setActivationTime(SessionContext ctx, Date activationTime)
      Deprecated.
      since ages - useGeneratedTrigger.setCronExpression(String) to cover scheduling
      Sets the next activation time of the Trigger.
      Overrides:
      setActivationTime in class GeneratedTrigger
      Parameters:
      ctx - the SessionContext, which will be used
      activationTime - the new activation time
    • getTimeTable

      @Deprecated(since="ages", forRemoval=false) public String getTimeTable(SessionContext ctx)
      Deprecated.
      since ages - useTriggerModel.getTimeTable() instead.
      Returns a localized text, representing the timetable of this trigger.
      Parameters:
      ctx - the session context
      Returns:
      the localized timeTable text
    • setMaxAcceptableDelay

      public void setMaxAcceptableDelay(SessionContext ctx, Integer value)
      The field MaxAcceptableDelayS describes how long after the job was scheduled can it still be triggered. If set to minus one, the value is ignored. If set to seconds, then this job can only be triggered up to seconds after it should have run. This is to prevent the following scenario: a heavy job is scheduled to run at midnight, but the job engine crashes before hand. When the job engine restarts at say 9am the next day, the heavy job is then run. By saying that this job can only run up to (say) 1 hour after its scheduled time, we prevent the heavy job running in the day time. Return true if the conditions are appropriate for the job to run. If provided value is null, then internally -1 one is passed in which further is ignored.
      Overrides:
      setMaxAcceptableDelay in class GeneratedTrigger
      Parameters:
      ctx - the session context
      value - the potential new value
    • setMaxAcceptableDelay

      public void setMaxAcceptableDelay(Integer value)
      Description copied from class: GeneratedTrigger
      Generated method - Setter of the Trigger.maxAcceptableDelay attribute.
      Overrides:
      setMaxAcceptableDelay in class GeneratedTrigger
      Parameters:
      value - the maxAcceptableDelay - the maximum acceptable delay (s) in which the job can be triggered, after which it is ignored.
    • setMaxAcceptableDelay

      public void setMaxAcceptableDelay(SessionContext ctx, int value)
      Description copied from class: GeneratedTrigger
      Generated method - Setter of the Trigger.maxAcceptableDelay attribute.
      Overrides:
      setMaxAcceptableDelay in class GeneratedTrigger
      value - the maxAcceptableDelay - the maximum acceptable delay (s) in which the job can be triggered, after which it is ignored.
    • setMaxAcceptableDelay

      public void setMaxAcceptableDelay(int seconds)
      Description copied from class: GeneratedTrigger
      Generated method - Setter of the Trigger.maxAcceptableDelay attribute.
      Overrides:
      setMaxAcceptableDelay in class GeneratedTrigger
      Parameters:
      seconds - the maxAcceptableDelay - the maximum acceptable delay (s) in which the job can be triggered, after which it is ignored.
    • getPulseseconds

      public static int getPulseseconds()