diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index c01b6833fc..3ee4b4076e 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -9,18 +9,21 @@ The pattern for adding new initialisation to the bootstrap sequence is as follows: - 1) Develop a bean that implements the Spring interface ApplicationListener - 2) Place the initialisation logic in the method onApplicationEvent(ApplicationEvent event)... + 1) Develop a bean that extends the Spring Surf class AbstractLifecycleBean + 2) Place the initialisation logic in the method onBootstrap(ApplicationEvent event)... - public void onApplicationEvent(ApplicationEvent event) + public void onBootstrap(ApplicationEvent event) { - if (event instanceof ContextRefreshedEvent) - { - // initialisation logic here - } + // initialisation logic here + } + 3) Place the shutdown logic (if any) in the method onShutdown(ApplicationEvent event)... + + public void onShutdown(ApplicationEvent event) + { + // cleanup logic here } - 3) Add the bean definition to this file - Note: the beans are initialised in the order they are specified. + 4) Add the bean definition to this file - Note: the beans are initialised in the order they are specified. --> @@ -603,6 +606,11 @@ /${spaces.company_home.childname} + + + + + diff --git a/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionImpl.java b/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionImpl.java index 690151fecd..d75a048751 100644 --- a/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionImpl.java +++ b/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionImpl.java @@ -23,6 +23,7 @@ import java.util.Date; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction; import org.alfresco.service.cmr.repository.NodeRef; +import org.quartz.DateIntervalTrigger; import org.quartz.SimpleTrigger; import org.quartz.Trigger; @@ -39,6 +40,7 @@ public class ScheduledPersistedActionImpl implements ScheduledPersistedAction private NodeRef persistedAtNodeRef; private Action action; private Date scheduleStart; + private Date scheduleEnd; private Integer intervalCount; private IntervalPeriod intervalPeriod; @@ -81,6 +83,24 @@ public class ScheduledPersistedActionImpl implements ScheduledPersistedAction { this.scheduleStart = startDate; } + + /** + * Not yet publicly available - get the date after + * which the action should no longer be run. + */ + protected Date getScheduleEnd() + { + return scheduleEnd; + } + + /** + * Not yet publicly available - set the date after + * which the action should no longer be run. + */ + protected void setScheduleEnd(Date endDate) + { + this.scheduleEnd = endDate; + } /** @@ -149,58 +169,40 @@ public class ScheduledPersistedActionImpl implements ScheduledPersistedAction // Use our nodeRef as the unique title String triggerName = persistedAtNodeRef.toString(); - // Monthly is a special case, since the period - // will vary - // TODO - Make more things use DateIntervalTrigger - if(intervalPeriod == IntervalPeriod.Month) + + // If they don't want it to repeat, and didn't set any + // dates, then we can't schedule it! + if(getScheduleInterval() == null && scheduleStart == null) { -// TODO -// DateIntervalTrigger trigger = new DateIntervalTrigger( -// triggerName, null, -// scheduleStart, null, -// DateIntervalTrigger.IntervalUnit.MONTH, -// intervalCount -// ); -// trigger.setMisfireInstruction( DateIntervalTrigger.MISFIRE_INSTRUCTION_FIRE_NOW ); + return null; } - SimpleTrigger trigger = null; - // Is it Start Date + Repeat Interval? - if(scheduleStart != null && getScheduleInterval() != null) + // If they don't want it to repeat, just use a simple interval + if(getScheduleInterval() == null) { - trigger = new SimpleTrigger( - triggerName, null, - scheduleStart, null, - SimpleTrigger.REPEAT_INDEFINITELY, - intervalCount * intervalPeriod.getInterval() - ); - } - - // Is it a single Start Date? - if(scheduleStart != null && getScheduleInterval() == null) - { - trigger = new SimpleTrigger( + SimpleTrigger trigger = new SimpleTrigger( triggerName, null, scheduleStart - ); - } - - // Is it start now, run with Repeat Interval? - if(getScheduleInterval() != null) - { - trigger = new SimpleTrigger( - triggerName, null, - SimpleTrigger.REPEAT_INDEFINITELY, - intervalCount * intervalPeriod.getInterval() - ); - } - - if(trigger != null) - { - // If we miss running, run as soon after as we can + ); trigger.setMisfireInstruction(SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW); + return trigger; } + + + // There are some repeating rules + // Create a Date Interval trigger + DateIntervalTrigger.IntervalUnit quartzInterval = + DateIntervalTrigger.IntervalUnit.valueOf( + intervalPeriod.toString().toUpperCase() + ); + + DateIntervalTrigger trigger = new DateIntervalTrigger( + triggerName, null, + scheduleStart, scheduleEnd, + quartzInterval, intervalCount + ); + trigger.setMisfireInstruction( DateIntervalTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW ); return trigger; } } diff --git a/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionServiceImpl.java b/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionServiceImpl.java index 11df023ffe..7ae2ae8208 100644 --- a/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionServiceImpl.java +++ b/source/java/org/alfresco/repo/action/scheduled/ScheduledPersistedActionServiceImpl.java @@ -43,6 +43,8 @@ import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.Trigger; +import org.springframework.context.ApplicationEvent; +import org.springframework.extensions.surf.util.AbstractLifecycleBean; /** * A service which handles the scheduling of the execution of persisted actions. @@ -118,6 +120,7 @@ public class ScheduledPersistedActionServiceImpl implements ScheduledPersistedAc this.namespaceService = namespaceService; } + /** * Find all our previously persisted scheduled actions, and tell the * scheduler to start handling them. Called by spring when startup is @@ -259,4 +262,30 @@ public class ScheduledPersistedActionServiceImpl implements ScheduledPersistedAc return detail; } + + + /** + * This is used to trigger the loading of previously persisted schedules on + * an application startup. It is an additional bean to make the context + * files cleaner. + */ + public static class ScheduledPersistedActionServiceBootstrap extends AbstractLifecycleBean + { + private ScheduledPersistedActionServiceImpl service; + public void setScheduledPersistedActionService(ScheduledPersistedActionServiceImpl scheduledPersistedActionService) + { + this.service = scheduledPersistedActionService; + } + + public void onBootstrap(ApplicationEvent event) + { + service.schedulePreviouslyPersisted(); + } + + public void onShutdown(ApplicationEvent event) + { + // We don't need to do anything here, as the scheduler shutdown + // will stop running our jobs for us + } + } } diff --git a/source/java/org/alfresco/service/cmr/action/scheduled/ScheduledPersistedAction.java b/source/java/org/alfresco/service/cmr/action/scheduled/ScheduledPersistedAction.java index ac70e1753c..b1b7949aad 100644 --- a/source/java/org/alfresco/service/cmr/action/scheduled/ScheduledPersistedAction.java +++ b/source/java/org/alfresco/service/cmr/action/scheduled/ScheduledPersistedAction.java @@ -86,28 +86,18 @@ public interface ScheduledPersistedAction public static enum IntervalPeriod { - Month ('M', -1), - Week ('W', 7*24*60*60*1000), - Day ('D', 24*60*60*1000), - Hour ('h', 60*60*1000), - Minute ('m', 60*1000); + Month ('M'), + Week ('W'), + Day ('D'), + Hour ('h'), + Minute ('m'); private final char letter; - private final long interval; - - IntervalPeriod(char letter, long interval) { + IntervalPeriod(char letter) { this.letter = letter; - this.interval = interval; } public char getLetter() { return letter; } - /** - * Returns the interval of one of these - * periods, in milliseconds - */ - public long getInterval() { - return interval; - } } }