Commits

Zemian Deng committed 245bf8d

Delete job listener before delete JobDef and Schedule.

  • Participants
  • Parent commits b32fe38

Comments (0)

Files changed (2)

timemachine-hibernate/src/main/java/timemachine/scheduler/hibernate/HibernateDataStore.java

 	public void deleteJobDef(JobDef jobDef) {
 		if (jobDef.getId() == null)
 			throw new SchedulerException("Failed to delete JobDef: missing Id value.");
+
+		// Send job listener first: Call job listener notifier on all Schedule to be remove
+		for (Schedule schedule : jobDef.getSchedules())
+			jobListenerNotifier.onScheduleDeleted(jobDef, schedule);
+		jobListenerNotifier.onJobDefDeleted(jobDef);
 		
+		// Now do the delete
 		try {
 			delete(jobDef.getSchedulerId(), jobDef);
 		} catch (ObjectNotFoundException e) {
 			throw new SchedulerException("Failed to delete JobDef: Id " + jobDef.getId() + " not found.");
 		}
-
-		// Call job listener notifier on all Schedule to be remove
-		for (Schedule schedule : jobDef.getSchedules())
-			jobListenerNotifier.onScheduleDeleted(jobDef, schedule);
-		jobListenerNotifier.onJobDefDeleted(jobDef);
 	}
 	@Override
 	public boolean existsJobDef(Long schedulerId, Long id) {
 		if (schedule.getId() == null)
 			throw new SchedulerException("Failed to delete Schedule: missing Id value.");
 		
+		// Send job listener first
+		JobDef jobDef = getJobDef(schedulerId, schedule.getJobDefId());
+		jobListenerNotifier.onScheduleDeleted(jobDef, schedule);
+		
+		// Now do the delete
 		try {
 			delete(schedulerId, schedule);
 		} catch (ObjectNotFoundException e) {
 			throw new SchedulerException("Failed to delete Schedule: Id " + schedule.getId() + " not found.");
 		}
-
-		JobDef jobDef = getJobDef(schedulerId, schedule.getJobDefId());
-		jobListenerNotifier.onScheduleDeleted(jobDef, schedule);
 	}
 	@Override
 	public boolean existsSchedule(Long schedulerId, Long id) {

timemachine-scheduler/src/main/java/timemachine/scheduler/service/MemoryDataStore.java

 		for (Schedule schedule : scheduleCopies) {
 			deleteSchedule(schedulerId, schedule);
 		}
-
+		
+		jobListenerNotifier.onJobDefDeleted(jobDef);
 		nodeStore.getJobDefs().remove(jobDef.getId());
-		jobListenerNotifier.onJobDefDeleted(jobDef);
 		logger.debug("{} deleted", jobDef);
 	}
 	@Override
 		// If schedule is already gone, then do nothing.
 		if (!existsSchedule(schedulerId, schedule.getId()))
 			return;
-		
+
 		// Remove schedule from JobDef reference
 		SchedulerNodeStore nodeStore = getSchedulerNodeStore(schedulerId);
 		JobDef jobDef = nodeStore.getJobDefs().get(schedule.getJobDefId());
+
+		// Send job listener notification first.
+		jobListenerNotifier.onScheduleDeleted(jobDef, schedule);
+		
 		// There could be times when JobDef already been deleted, so let's check for that.
 		if (jobDef != null) {
 			// Remove schedule from jobDef if it exists.
 			nodeStore.removeSchedule(schedule);
 			logger.debug("{} deleted", schedule);
 		}
-
-		jobListenerNotifier.onScheduleDeleted(jobDef, schedule);
 	}
 	@Override
 	synchronized public boolean existsSchedule(Long schedulerId, Long id) {