Class ScheduleExpression
- java.lang.Object
-
- jakarta.ejb.ScheduleExpression
-
- All Implemented Interfaces:
Serializable
public class ScheduleExpression extends Object implements Serializable
A calendar-based timeout expression for an enterprise bean timer.
Each attribute used to define a calendar-based timeout schedule has two overloaded setter methods, one that takes a String and one that takes an int. The int version is merely a convenience method for setting the attribute in the common case that the value is a simple integer value.
For example,
scheduleExpression.second(10)
is semantically equivalent toscheduleExpression.second("10")There are seven attributes that constitute a schedule specification which are listed below. In addition, thetimezoneattribute may be used to specify a non-default time zone in whose context the schedule specification is to be evaluated.The attributes that specify the calendar-based schedule itself are as follows:
- second : one or more seconds within a minute
Allowable values: [0,59]
- minute : one or more minutes within an hour
Allowable values : [0,59]
- hour : one or more hours within a day
Allowable values : [0,23]
- dayOfMonth : one or more days within a month
Allowable values:
- [1,31]
- [-7, -1]
- "Last"
- {"1st", "2nd", "3rd", "4th", "5th", "Last"} {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
"Last" means the last day of the month
-x (where x is in the range [-7, -1]) means x day(s) before the last day of the month
"1st","2nd", etc. applied to a day of the week identifies a single occurrence of that day within the month.
- month : one or more months within a year
Allowable values :
- [1,12]
- {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", Dec"}
- dayOfWeek : one or more days within a week
Allowable values :
- [0,7]
- {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}
"0" and "7" both refer to Sunday
- year : a particular calendar year
Allowable values : a four-digit calendar year
Each attribute supports values expressed in one of the following forms
- Single Value. This constrains the attribute to only one of its possible values.
Example: second = "10" Example: month = "Sep"
- Wild Card. "*" represents all allowable values for a given attribute.
Example: second = "*" Example: dayOfWeek = "*"
- List. This constrains the attribute to two or more allowable values or ranges, with a comma used as a separator
character within the string. Each item in the list must be a single value or range. List items cannot be lists, wild
cards, or increments. Duplicate values are ignored.
Example: second = "10,20,30" Example: dayOfWeek = "Mon,Wed,Fri" Example: minute = "0-10,30,40"
- Range. This constrains the attribute to an inclusive range of values, with a dash separating both ends of the
range. Each side of the range must be a single attribute value. Members of a range cannot be lists, wild cards,
ranges, or increments. If
xis larger thanyin a range"x-y", the range is equivalent to"x-max, min-y", wheremaxis the largest value of the corresponding attribute andminis the smallest. The range"x-x", where both range values are the same, evaluates to the single valuex. The day of the week range"0-7"is equivalent to"*".Example: second = "1-10" Example: dayOfWeek = "Fri-Mon" Example: dayOfMonth = "27-3" (Equivalent to "27-Last , 1-3")
- Increments. The forward slash constrains an attribute based on a starting point and an interval, and is used to
specify every
Nseconds, minutes, or hours within the minute, hour, or day, respectively. For the expressionx/y, the attribute is constrained to everyyth value within the set of allowable values beginning at timex. Thexvalue is inclusive. The wild card character (*) can be used in thexposition, and is equivalent to0. The use of increments is only supported within thesecond,minute, andhourattributes. For thesecondandminuteattributes,xandymust each be in the range[0,59]. For thehourattribute,xandymust each be in the range[0,23].Example: minute = "∗/5" (Every five minutes within the hour)
This is equivalent to:minute = "0,5,10,15,20,25,30,35,40,45,50,55"Example: second = "30/10" (Every 10 seconds within the minute, starting at second 30)
This is equivalent to:second = "30,40,50"Note that the set of matching increment values stops once the maximum value for that attribute is exceeded. It does not "roll over" past the boundary.
Example : ( minute = "∗/14", hour="1,2")
This is equivalent to:
(minute = "0,14,28,42,56", hour = "1,2")(Every 14 minutes within the hour, for the hours of 1 and 2 a.m.)
The following additional rules apply to the schedule specification attributes:
- If the
dayOfMonthattribute has a non-wildcard value and thedayOfWeekattribute has a non-wildcard value, then any day matching either thedayOfMonthvalue or thedayOfWeekvalue will be considered to apply. - Whitespace is ignored, except for string constants and numeric values.
- All string constants (e.g.,
"Sun","Jan","1st", etc.) are case insensitive.
Schedule-based timer times are evaluated in the context of the default time zone associated with the container in which the application is executing. A schedule-based timer may optionally override this default and associate itself with a specific time zone. If the schedule-based timer is associated with a specific time zone, all its times are evaluated in the context of that time zone, regardless of the default time zone in which the container is executing.
None of the ScheduleExpression methods are required to be called. The defaults are :
- second: "0"
- minute: "0"
- hour: "0"
- dayOfMonth: "*"
- month: "*"
- dayOfWeek: "*"
- year: "*"
- timezone : default JVM time zone
- start : upon timer creation
- end : no end date
Applications must not rely on the getter methods that return the attributes of a calendar-based timeout schedule to return them in the same syntactic format in which they were passed in to a
ScheduleExpressionmethod or supplied to theScheduleannotation, and portable implementations must not assume any particular syntactic format. Implementations are required only to preserve semantic equivalence.- Since:
- EJB 3.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ScheduleExpression()Create a schedule with the default values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ScheduleExpressiondayOfMonth(int d)Set the day of the month attribute.ScheduleExpressiondayOfMonth(String d)Set the day of the month attribute.ScheduleExpressiondayOfWeek(int d)Set the day of the week attribute.ScheduleExpressiondayOfWeek(String d)Set the day of the week attribute.ScheduleExpressionend(Date e)Set the end date.StringgetDayOfMonth()Return the value of the day of the month attribute.StringgetDayOfWeek()Return the value of the day of the week attribute.DategetEnd()Return the end date, if set; otherwise null.StringgetHour()Return the value of the hour attribute.StringgetMinute()Return the value of the minute attribute.StringgetMonth()Return the value of the month attribute.StringgetSecond()Return the value of the second attribute.DategetStart()Return the start date, if set; otherwise null.StringgetTimezone()Return the timezone, if set; otherwise null.StringgetYear()Return the value of the year attribute.ScheduleExpressionhour(int h)Set the hour attribute.ScheduleExpressionhour(String h)Set the hour attribute.ScheduleExpressionminute(int m)Set the minute attribute.ScheduleExpressionminute(String m)Set the minute attribute.ScheduleExpressionmonth(int m)Set the month attribute.ScheduleExpressionmonth(String m)Set the month attribute.ScheduleExpressionsecond(int s)Set the second attribute.ScheduleExpressionsecond(String s)Set the second attribute.ScheduleExpressionstart(Date s)Set the start date.ScheduleExpressiontimezone(String timezoneID)Set the timezone.StringtoString()ScheduleExpressionyear(int y)Set the year attribute.ScheduleExpressionyear(String y)Set the year attribute.
-
-
-
Method Detail
-
second
public ScheduleExpression second(String s)
Set the second attribute.- Parameters:
s- the attribute value as aString- Returns:
- a
ScheduleExpressionobject.
-
second
public ScheduleExpression second(int s)
Set the second attribute.- Parameters:
s- the attribute value as anint, if the value is a simple integer value- Returns:
- a
ScheduleExpressionobject.
-
getSecond
public String getSecond()
Return the value of the second attribute.- Returns:
- second
-
minute
public ScheduleExpression minute(String m)
Set the minute attribute.- Parameters:
m- the attribute value as aString- Returns:
- a
ScheduleExpressionobject.
-
minute
public ScheduleExpression minute(int m)
Set the minute attribute.- Parameters:
m- the attribute value as anint, if the value is a simple integer value- Returns:
- a
ScheduleExpressionobject.
-
getMinute
public String getMinute()
Return the value of the minute attribute.- Returns:
- minute
-
hour
public ScheduleExpression hour(String h)
Set the hour attribute.- Parameters:
h- the attribute value as aString- Returns:
- a
ScheduleExpressionobject.
-
hour
public ScheduleExpression hour(int h)
Set the hour attribute.- Parameters:
h- the attribute value as anint, if the value is a simple integer value- Returns:
- a
ScheduleExpressionobject.
-
getHour
public String getHour()
Return the value of the hour attribute.- Returns:
- hour
-
dayOfMonth
public ScheduleExpression dayOfMonth(String d)
Set the day of the month attribute.- Parameters:
d- the attribute value as aString- Returns:
- a
ScheduleExpressionobject.
-
dayOfMonth
public ScheduleExpression dayOfMonth(int d)
Set the day of the month attribute.- Parameters:
d- the attribute value as anint, if the value is a simple integer value- Returns:
- a
ScheduleExpressionobject.
-
getDayOfMonth
public String getDayOfMonth()
Return the value of the day of the month attribute.- Returns:
- day of the month
-
month
public ScheduleExpression month(String m)
Set the month attribute.- Parameters:
m- the attribute value as aString- Returns:
- a
ScheduleExpressionobject.
-
month
public ScheduleExpression month(int m)
Set the month attribute.- Parameters:
m- the attribute value as anint, if the value is a simple integer value- Returns:
- a
ScheduleExpressionobject.
-
getMonth
public String getMonth()
Return the value of the month attribute.- Returns:
- month
-
dayOfWeek
public ScheduleExpression dayOfWeek(String d)
Set the day of the week attribute.- Parameters:
d- the attribute value as aString- Returns:
- a
ScheduleExpressionobject.
-
dayOfWeek
public ScheduleExpression dayOfWeek(int d)
Set the day of the week attribute.- Parameters:
d- the attribute value as anint, if the value is a simple integer value- Returns:
- a
ScheduleExpressionobject.
-
getDayOfWeek
public String getDayOfWeek()
Return the value of the day of the week attribute.- Returns:
- day of the week
-
year
public ScheduleExpression year(String y)
Set the year attribute.- Parameters:
y- the attribute value as aString- Returns:
- a
ScheduleExpressionobject.
-
year
public ScheduleExpression year(int y)
Set the year attribute.- Parameters:
y- the attribute value as anint, if the value is a simple integer value- Returns:
- a
ScheduleExpressionobject.
-
getYear
public String getYear()
Return the value of the year attribute.- Returns:
- year
-
timezone
public ScheduleExpression timezone(String timezoneID)
Set the timezone.- Parameters:
timezoneID- the Time zone specified as an ID String- Returns:
- a
ScheduleExpressionobject.
-
getTimezone
public String getTimezone()
Return the timezone, if set; otherwise null.- Returns:
- timezone
-
start
public ScheduleExpression start(Date s)
Set the start date.- Parameters:
s- the start date- Returns:
- a
ScheduleExpressionobject.
-
getStart
public Date getStart()
Return the start date, if set; otherwise null.- Returns:
- start date
-
end
public ScheduleExpression end(Date e)
Set the end date.- Parameters:
e- the end date- Returns:
- a
ScheduleExpressionobject.
-
getEnd
public Date getEnd()
Return the end date, if set; otherwise null.- Returns:
- end date
-
-