<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="renewalReminderBean" class="com.playphone.billing.renewal.RenewalReminderBean"/>
<bean id="renewalReminderJob" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>com.playphone.billing.renewal.RenewalReminderJob</value>
</property>
<property name="jobDataAsMap">
<map>
<entry key="renewalReminderBean">
<ref bean="renewalReminderBean" />
</entry>
</map>
</property>
</bean>
<bean id="cronRenewalReminderTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="renewalReminderJob" />
</property>
<property name="cronExpression">
<value>0 0/500 * * * ?</value>
</property>
</bean>
<bean id="recurrentBillingScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="cronRenewalReminderTrigger"/>
</list>
</property>
</bean>
</beans>
renewalReminderBean java code:
public class RenewalReminderBean {
/**
* Get A Instance Of Log
*/
private static Log log = LogFactory.getLog(RenewalReminderBean.class);
/**
* 1.fetch account list belong to accountGroup from database
* 2.put message in queue
*/
public void sendRenewalReminder() {
List accountList = null;
IAcctAccountgroupDAO accAccountgroupDao = (IAcctAccountgroupDAO) SpringBeanLoader
.loadBean("AcctAccountgroupDAOProxy");
try {
accountList = accAccountgroupDao.findAll();
} catch (Exception e) {
log.error("fetch all accountGroup from database Exception. Caused by "
+ e.getMessage(), e);
return;
}
AcctAccountgroup accountGroup = null;
SubsActivePlanDAO reminderDAO = null;
List<RenewalReminder> returnUserList = null;
for (Iterator it = accountList.iterator(); it.hasNext();) {
accountGroup = (AcctAccountgroup) it.next();
try {
reminderDAO = new SubsActivePlanDAO();
returnUserList = reminderDAO.findRenewalReminderBy(accountGroup);
} catch (Exception e) {
log.error("send renewal message throw exception. Caused by "
+ e.getMessage(), e);
}
sendRenewalMessage(returnUserList);
}
}
/**
* put message to queue.
* @param userList the account which receive message
*/
private void sendRenewalMessage(List<RenewalReminder> userList) {
RenewalReminderProducer producer = (RenewalReminderProducer) SpringBeanLoader
.loadBean("renewalReminderProducer");
for (RenewalReminder user : userList) {
producer.send(user);
}
}
}
public class RenewalReminderJob extends QuartzJobBean {
/**
* Get A Instance Of Log
*/
private Log log = LogFactory.getLog(RenewalReminderJob.class);
/**
* JavaBean of RenewalReminder
*/
private RenewalReminderBean renewalReminderBean;
/**
* set RenewalReminderBean with Spring IOC Container
* @param renewalReminderBean javabean
*/
public void setRenewalReminderBean(RenewalReminderBean renewalReminderBean) {
this.renewalReminderBean = renewalReminderBean;
}
/**
* override the executeInternal
* @param arg0 JobExecutionContext
* @throws JobExecutionException JobExecutionException
*/
@Override
protected void executeInternal(JobExecutionContext arg0) throws JobExecutionException {
if (log.isInfoEnabled()) {
log.info("RenewalReminder Job is Starting....");
}
long startTime = System.currentTimeMillis();
renewalReminderBean.sendRenewalReminder();
long endTime = System.currentTimeMillis();
if (log.isInfoEnabled()) {
log.info("RenewalReminder Job is Completed. Total spend time : "
+ (endTime - startTime) + "ms");
}
}
}
public class ScheduleJobStart {
private static boolean started = false;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ScheduleJobStart.start();
}
public static void start() {
if (!started) {
new ClassPathXmlApplicationContext("/billingSchedulerContext.xml");
started = true;
}
}
/**
* @return Returns the started.
*/
public static boolean isStarted() {
return started;
}
/**
* @param started The started to set.
*/
public static void setStarted(boolean started) {
ScheduleJobStart.started = started;
}
}