Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java,v
diff -u -r1.13 -r1.14
--- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java 14 Apr 2005 06:19:29 -0000 1.13
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java 14 Apr 2005 07:56:57 -0000 1.14
@@ -28,6 +28,7 @@
import java.util.Set;
import java.util.Vector;
+import org.apache.log4j.Logger;
import org.lamsfoundation.lams.authoring.service.IAuthoringService;
import org.lamsfoundation.lams.learningdesign.Activity;
import org.lamsfoundation.lams.learningdesign.ComplexActivity;
@@ -60,6 +61,12 @@
import org.lamsfoundation.lams.util.wddx.FlashMessage;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
/**
*
This is the major service facade for all monitoring functionalities. It is
@@ -72,12 +79,14 @@
* @author Jacky Fang 2/02/2005
* @author Manpreet Minhas
*/
-public class MonitoringService implements IMonitoringService
+public class MonitoringService implements IMonitoringService,ApplicationContextAware
{
//---------------------------------------------------------------------
// Instance variables
//---------------------------------------------------------------------
+ private static Logger log = Logger.getLogger(MonitoringService.class);
+
private ILessonDAO lessonDAO;
private ILessonClassDAO lessonClassDAO;
private IOrganisationDAO organisationDAO;
@@ -86,16 +95,15 @@
private IUserDAO userDAO;
private IWorkspaceFolderDAO workspaceFolderDAO;
private ILearningDesignDAO learningDesignDAO;
-
+ private FlashMessage flashMessage;
private IAuthoringService authoringService;
private ILamsCoreToolService lamsCoreToolService;
private IUserManagementService userManagementService;
-
- private JobDetail openScheduleGateJob;
- private JobDetail closeScheduleGateJob;
private Scheduler scheduler;
-
- private FlashMessage flashMessage;
+ private ApplicationContext applicationContext;
+ //---------------------------------------------------------------------
+ // Inversion of Control Methods - Method injection
+ //---------------------------------------------------------------------
/**
* @param userManagementService The userManagementService to set.
*/
@@ -115,34 +123,20 @@
public void setWorkspaceFolderDAO(IWorkspaceFolderDAO workspaceFolderDAO) {
this.workspaceFolderDAO = workspaceFolderDAO;
}
+
/**
- * @param activityDAO The activityDAO to set.
- */
- public void setActivityDAO(IActivityDAO activityDAO) {
- this.activityDAO = activityDAO;
- }
- /**
* @param transitionDAO The transitionDAO to set.
*/
public void setTransitionDAO(ITransitionDAO transitionDAO) {
this.transitionDAO = transitionDAO;
}
+
/**
- * @param lamsCoreToolService The lamsCoreToolService to set.
- */
- public void setLamsCoreToolService(ILamsCoreToolService lamsCoreToolService) {
- this.lamsCoreToolService = lamsCoreToolService;
- }
- /**
* @param userDAO The userDAO to set.
*/
public void setUserDAO(IUserDAO userDAO) {
this.userDAO = userDAO;
}
-
- //---------------------------------------------------------------------
- // Inversion of Control Methods - Method injection
- //---------------------------------------------------------------------
/**
* @param authoringService The authoringService to set.
*/
@@ -166,25 +160,34 @@
{
this.lessonDAO = lessonDAO;
}
- public void setOrganisationDAO(IOrganisationDAO organisationDAO) {
- this.organisationDAO = organisationDAO;
- }
- /**
- * @param openScheduleGateJob The openScheduleGateJob to set.
+
+ /**
+ * @param lamsToolService The lamsToolService to set.
*/
- public void setOpenScheduleGateJob(JobDetail openScheduleGateJob)
+ public void setLamsCoreToolService(ILamsCoreToolService lamsToolService)
{
- this.openScheduleGateJob = openScheduleGateJob;
+ this.lamsCoreToolService = lamsToolService;
}
-
+
/**
- * @param closeScheduleGateJob The closeScheduleGateJob to set.
+ * @param activityDAO The activityDAO to set.
*/
- public void setCloseScheduleGateJob(JobDetail closeScheduleGateJob)
+ public void setActivityDAO(IActivityDAO activityDAO)
{
- this.closeScheduleGateJob = closeScheduleGateJob;
+ this.activityDAO = activityDAO;
}
/**
+ * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+ */
+ public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
+ {
+ this.applicationContext=applicationContext;
+ }
+ public void setOrganisationDAO(IOrganisationDAO organisationDAO) {
+ this.organisationDAO = organisationDAO;
+ }
+
+ /**
* @param scheduler The scheduler to set.
*/
public void setScheduler(Scheduler scheduler)
@@ -278,9 +281,9 @@
initToolSessionFor((ToolActivity) activity,
requestedLesson.getAllLearners(),
requestedLesson);
- //if it is schedule gate, we need to initialize sheduler for it.
+ //if it is schedule gate, we need to initialize the sheduler for it.
if(activity.getActivityTypeId().intValue()==Activity.SCHEDULE_GATE_ACTIVITY_TYPE)
- initGateScheduler((ScheduleGateActivity)activity);
+ runGateScheduler((ScheduleGateActivity)activity);
}
//update lesson status
requestedLesson.setLessonStateId(Lesson.STARTED_STATE);
@@ -289,11 +292,43 @@
}
/**
- * @param activity
+ *
Runs the system scheduler to start the scheduling for opening gate and
+ * closing gate. It invlovs a couple of steps to start the scheduler:
+ * 1. Initialize the resource needed by scheduling job by setting
+ * them into the job data map.
+ *
+ * 2. Create customized triggers for the scheduling.
+ * 3. start the scheduling job
+ *
+ * @param scheduleGate the gate that needs to be scheduled.
*/
- private void initGateScheduler(ScheduleGateActivity scheduleGate)
+ private void runGateScheduler(ScheduleGateActivity scheduleGate)
{
-
+ JobDetail openScheduleGateJob = getOpenScheduleGateJob();
+ JobDetail closeScheduleGateJob = getCloseScheduleGateJob();
+ //setup the message for scheduling job
+ openScheduleGateJob.setName("openGate");
+ openScheduleGateJob.getJobDataMap().put("gateId",scheduleGate.getActivityId());
+ closeScheduleGateJob.setName("closeGate");
+ closeScheduleGateJob.getJobDataMap().put("gateId",scheduleGate.getActivityId());
+ //create customized triggers
+ Trigger openGateTrigger = new SimpleTrigger("openGateTrigger",
+ Scheduler.DEFAULT_GROUP,
+ scheduleGate.getRealGateOpenTime());
+ Trigger closeGateTrigger = new SimpleTrigger("closeGateTrigger",
+ Scheduler.DEFAULT_GROUP,
+ scheduleGate.getRealGateCloseTime());
+ //start the scheduling job
+ try
+ {
+ scheduler.scheduleJob(openScheduleGateJob, openGateTrigger);
+ scheduler.scheduleJob(closeScheduleGateJob, closeGateTrigger);
+ }
+ catch (SchedulerException e)
+ {
+ throw new MonitoringServiceException("Error occurred at " +
+ "[runGateScheduler]- fail to start scheduling",e);
+ }
}
/**
@@ -356,6 +391,7 @@
return newLessonClass;
}
+
/**
* Setup a new lesson object without class and insert it into the database.
*
@@ -375,7 +411,7 @@
lessonDAO.saveLesson(newLesson);
return newLesson;
}
-
+
/**
* Setup the empty lesson class according to the run-time learning design
* copy.
@@ -443,7 +479,7 @@
&& !((ToolActivity) activity).getApplyGrouping().booleanValue();
}
- /**
+ /**
* (non-Javadoc)
* @see org.lamsfoundation.lams.monitoring.service.IMonitoringService#getAllLessons()
*/
@@ -696,4 +732,20 @@
FlashMessage.ERROR);
return flashMessage.serializeMessage();
}
+
+ /**
+ *
+ */
+ private JobDetail getOpenScheduleGateJob()
+ {
+ return (JobDetail)applicationContext.getBean("openScheduleGateJob");
+ }
+
+ /**
+ *
+ */
+ private JobDetail getCloseScheduleGateJob()
+ {
+ return (JobDetail)applicationContext.getBean("closeScheduleGateJob");
+ }
}
\ No newline at end of file
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringServiceException.java
===================================================================
RCS file: /usr/local/cvsroot/lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringServiceException.java,v
diff -u
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringServiceException.java 14 Apr 2005 07:56:20 -0000 1.1
@@ -0,0 +1,70 @@
+/***************************************************************************
+ * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org)
+ * =============================================================
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * http://www.gnu.org/licenses/gpl.txt
+ * ***********************************************************************/
+
+package org.lamsfoundation.lams.monitoring.service;
+
+
+/**
+ * Runtime exception that wraps the error condition occurred at monitoring
+ * side.
+ * @author Jacky Fang
+ * @since 2005-4-14
+ * @version 1.1
+ *
+ */
+public class MonitoringServiceException extends RuntimeException
+{
+
+ /**
+ *
+ */
+ public MonitoringServiceException()
+ {
+ super();
+ }
+
+ /**
+ * @param message
+ */
+ public MonitoringServiceException(String message)
+ {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public MonitoringServiceException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public MonitoringServiceException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+}
Index: lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/Attic/monitoringApplicationContext.xml,v
diff -u -r1.6 -r1.7
--- lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml 12 Apr 2005 08:09:48 -0000 1.6
+++ lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml 14 Apr 2005 07:56:20 -0000 1.7
@@ -43,9 +43,15 @@
>
-
-
-
+
+
+
+
+
+
+
+
+
Index: lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java
===================================================================
RCS file: /usr/local/cvsroot/lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/Attic/TestMonitoringService.java,v
diff -u -r1.12 -r1.13
--- lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java 14 Apr 2005 06:20:39 -0000 1.12
+++ lams_monitoring/test/java/org/lamsfoundation/lams/monitoring/service/TestMonitoringService.java 14 Apr 2005 07:56:20 -0000 1.13
@@ -108,14 +108,14 @@
*/
protected String[] getContextConfigLocation()
{
- return new String[] { "WEB-INF/spring/applicationContext.xml",
- "/org/lamsfoundation/lams/tool/toolApplicationContext.xml",
- "WEB-INF/spring/monitoringApplicationContext.xml",
- "/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml",
- "/org/lamsfoundation/lams/learningdesign/learningDesignApplicationContext.xml",
- "WEB-INF/spring/authoringApplicationContext.xml",
- "/org/lamsfoundation/lams/tool/survey/dataAccessContext.xml",
- "/org/lamsfoundation/lams/tool/survey/surveyApplicationContext.xml"};
+ return new String[] { "/org/lamsfoundation/lams/tool/toolApplicationContext.xml",
+ "/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml",
+ "/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml",
+ "/org/lamsfoundation/lams/learningdesign/learningDesignApplicationContext.xml",
+ "/WEB-INF/authoringApplicationContext.xml",
+ "/org/lamsfoundation/lams/tool/survey/dataAccessContext.xml",
+ "/org/lamsfoundation/lams/tool/survey/surveyApplicationContext.xml",
+ "applicationContext.xml"};
}
/**
* @see org.lamsfoundation.lams.AbstractLamsTestCase#getHibernateSessionFactoryName()
Index: lams_monitoring/web/WEB-INF/spring/monitoringApplicationContext.xml
===================================================================
RCS file: /usr/local/cvsroot/lams_monitoring/web/WEB-INF/spring/Attic/monitoringApplicationContext.xml,v
diff -u -r1.2 -r1.3
--- lams_monitoring/web/WEB-INF/spring/monitoringApplicationContext.xml 14 Apr 2005 05:29:17 -0000 1.2
+++ lams_monitoring/web/WEB-INF/spring/monitoringApplicationContext.xml 14 Apr 2005 07:56:20 -0000 1.3
@@ -51,6 +51,7 @@
+
@@ -66,8 +67,8 @@
-
-
+
+
org.lamsfoundation.lams.monitoring.service.OpenScheduleGateJob
@@ -95,5 +96,4 @@
-