001 | /* Licensed under the Apache License, Version 2.0 (the "License"); |
002 | * you may not use this file except in compliance with the License. |
003 | * You may obtain a copy of the License at |
004 | * |
006 | * |
007 | * Unless required by applicable law or agreed to in writing, software |
008 | * distributed under the License is distributed on an "AS IS" BASIS, |
009 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
010 | * See the License for the specific language governing permissions and |
011 | * limitations under the License. |
012 | */ |
013 | package org.activiti.engine.impl.persistence.entity; |
014 |
015 | import java.util.Date; |
016 |
017 | import org.activiti.engine.impl.calendar.BusinessCalendar; |
018 | import org.activiti.engine.impl.calendar.CycleBusinessCalendar; |
019 | import org.activiti.engine.impl.context.Context; |
020 | import org.activiti.engine.impl.interceptor.CommandContext; |
021 | import org.activiti.engine.impl.jobexecutor.TimerDeclarationImpl; |
022 | import org.slf4j.Logger; |
023 | import org.slf4j.LoggerFactory; |
024 |
025 |
026 | /** |
027 | * @author Tom Baeyens |
028 | */ |
029 | public class TimerEntity extends JobEntity { |
030 |
031 | private static final long serialVersionUID = 1L; |
032 |
033 | private static Logger log = LoggerFactory.getLogger(TimerEntity. class ); |
034 |
035 | protected String repeat; |
036 |
037 | public TimerEntity() { |
038 | } |
039 |
040 | public TimerEntity(TimerDeclarationImpl timerDeclaration) { |
041 | jobHandlerType = timerDeclaration.getJobHandlerType(); |
042 | jobHandlerConfiguration = timerDeclaration.getJobHandlerConfiguration(); |
043 | isExclusive = timerDeclaration.isExclusive(); |
044 | repeat = timerDeclaration.getRepeat(); |
045 | retries = timerDeclaration.getRetries(); |
046 | } |
047 |
048 | private TimerEntity(TimerEntity te) { |
049 | jobHandlerConfiguration = te.jobHandlerConfiguration; |
050 | jobHandlerType = te.jobHandlerType; |
051 | isExclusive = te.isExclusive; |
052 | repeat = te.repeat; |
053 | retries = te.retries; |
054 | executionId = te.executionId; |
055 | processInstanceId = te.processInstanceId; |
056 |
057 | } |
058 |
059 | @Override |
060 | public void execute(CommandContext commandContext) { |
061 |
062 | super .execute(commandContext); |
063 |
064 | if (repeat == null ) { |
065 |
066 | if (log.isDebugEnabled()) { |
067 | log.debug( "Timer {} fired. Deleting timer." , getId()); |
068 | } |
069 | delete(); |
070 | } else { |
071 | delete(); |
072 | Date newTimer = calculateRepeat(); |
073 | System.out.println(repeat); |
074 | System.out.println(newTimer); |
075 | if (newTimer != null ) { |
076 | TimerEntity te = new TimerEntity( this ); |
077 | te.setDuedate(newTimer); |
078 | Context |
079 | .getCommandContext() |
080 | .getJobEntityManager() |
081 | .schedule(te); |
082 | } |
083 | } |
084 |
085 | } |
086 |
087 | private Date calculateRepeat() { |
088 | BusinessCalendar businessCalendar = Context |
089 | .getProcessEngineConfiguration() |
090 | .getBusinessCalendarManager() |
091 | .getBusinessCalendar(CycleBusinessCalendar.NAME); |
092 | return businessCalendar.resolveDuedate(repeat); |
093 | } |
094 |
095 | public String getRepeat() { |
096 | return repeat; |
097 | } |
098 |
099 | public void setRepeat(String repeat) { |
100 | this .repeat = repeat; |
101 | } |
102 | } |

dada2211 LV1
2022年7月18日
shiyujir LV7
2021年4月8日
lironggang LV38
2021年3月26日
mixiumissuuu LV1
2020年11月22日
caozhaoqi83 LV5
2020年10月21日
527732528 LV2
2020年8月6日
he752650052 LV1
2020年4月21日
gnocchi LV1
2020年4月14日
菜鸟真的是菜 LV8
2020年2月3日
limi LV9
2019年12月30日

四小只by白丫头 LV3
2月17日
sunqing971 LV2
1月18日
whfuai LV14
2024年9月28日
CrystalQ LV8
2024年8月15日
wubz2008 LV5
2024年4月22日
denglu123321 LV4
2024年4月11日
dmy2008 LV6
2024年1月2日
wang_d LV12
2023年12月9日
taoshen95 LV16
2023年8月7日
dapeng0011 LV15
2023年7月3日