|
@@ -17,8 +17,11 @@
|
|
|
|
|
|
package org.maxkey.synchronizer;
|
|
package org.maxkey.synchronizer;
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+
|
|
import org.apache.mybatis.jpa.util.WebContext;
|
|
import org.apache.mybatis.jpa.util.WebContext;
|
|
import org.maxkey.entity.Synchronizers;
|
|
import org.maxkey.entity.Synchronizers;
|
|
|
|
+import org.maxkey.persistence.service.SynchronizersService;
|
|
import org.quartz.Job;
|
|
import org.quartz.Job;
|
|
import org.quartz.JobExecutionContext;
|
|
import org.quartz.JobExecutionContext;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -27,6 +30,7 @@ import org.slf4j.LoggerFactory;
|
|
public class SynchronizerJob implements Job {
|
|
public class SynchronizerJob implements Job {
|
|
final static Logger _logger = LoggerFactory.getLogger(SynchronizerJob.class);
|
|
final static Logger _logger = LoggerFactory.getLogger(SynchronizerJob.class);
|
|
|
|
|
|
|
|
+ SynchronizersService synchronizersService;
|
|
|
|
|
|
public static class JOBSTATUS{
|
|
public static class JOBSTATUS{
|
|
public static int STOP = 0;
|
|
public static int STOP = 0;
|
|
@@ -34,35 +38,49 @@ public class SynchronizerJob implements Job {
|
|
public static int FINISHED = 2;
|
|
public static int FINISHED = 2;
|
|
}
|
|
}
|
|
|
|
|
|
- private static int jobStatus = JOBSTATUS.STOP;
|
|
|
|
|
|
+ private static HashMap<String,Integer> jobStatus = new HashMap<String,Integer>();
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void execute(JobExecutionContext context){
|
|
public void execute(JobExecutionContext context){
|
|
- if(jobStatus == JOBSTATUS.RUNNING) {
|
|
|
|
|
|
+ Synchronizers synchronizer = readSynchronizer(context);
|
|
|
|
+ if(jobStatus.get(synchronizer.getId()) ==null ) {
|
|
|
|
+ //init
|
|
|
|
+ jobStatus.put(synchronizer.getId(), JOBSTATUS.STOP) ;
|
|
|
|
+ }else if(jobStatus.get(synchronizer.getId())== JOBSTATUS.RUNNING) {
|
|
_logger.info("SynchronizerJob is in running . " );
|
|
_logger.info("SynchronizerJob is in running . " );
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
_logger.debug("SynchronizerJob is running ... " );
|
|
_logger.debug("SynchronizerJob is running ... " );
|
|
- jobStatus = JOBSTATUS.RUNNING;
|
|
|
|
|
|
+ jobStatus.put(synchronizer.getId(), JOBSTATUS.RUNNING) ;
|
|
try {
|
|
try {
|
|
- Synchronizers synchronizer = (Synchronizers)context.getMergedJobDataMap().get("synchronizer");
|
|
|
|
|
|
+
|
|
_logger.debug("synchronizer : " + synchronizer.getName()+"("+synchronizer.getId()+"_"+synchronizer.getSourceType()+")");
|
|
_logger.debug("synchronizer : " + synchronizer.getName()+"("+synchronizer.getId()+"_"+synchronizer.getSourceType()+")");
|
|
_logger.debug("synchronizer service : " + synchronizer.getService());
|
|
_logger.debug("synchronizer service : " + synchronizer.getService());
|
|
_logger.debug("synchronizer Scheduler : " + synchronizer.getScheduler());
|
|
_logger.debug("synchronizer Scheduler : " + synchronizer.getScheduler());
|
|
ISynchronizerService service = (ISynchronizerService)WebContext.getBean(synchronizer.getService());
|
|
ISynchronizerService service = (ISynchronizerService)WebContext.getBean(synchronizer.getService());
|
|
service.setSynchronizer(synchronizer);
|
|
service.setSynchronizer(synchronizer);
|
|
service.sync();
|
|
service.sync();
|
|
-
|
|
|
|
|
|
+ jobStatus.put(synchronizer.getId(), JOBSTATUS.FINISHED);
|
|
_logger.debug("SynchronizerJob is success " );
|
|
_logger.debug("SynchronizerJob is success " );
|
|
}catch(Exception e) {
|
|
}catch(Exception e) {
|
|
_logger.error("Exception " ,e);
|
|
_logger.error("Exception " ,e);
|
|
- jobStatus = JOBSTATUS.STOP;
|
|
|
|
|
|
+ jobStatus.put(synchronizer.getId(), JOBSTATUS.STOP);
|
|
}
|
|
}
|
|
- jobStatus = JOBSTATUS.FINISHED;
|
|
|
|
_logger.debug("SynchronizerJob is finished . " );
|
|
_logger.debug("SynchronizerJob is finished . " );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ public Synchronizers readSynchronizer(JobExecutionContext context) {
|
|
|
|
+ Synchronizers jobSynchronizer = (Synchronizers)context.getMergedJobDataMap().get("synchronizer");
|
|
|
|
+ if(synchronizersService == null) {
|
|
|
|
+ synchronizersService = (SynchronizersService)WebContext.getBean("synchronizersService");
|
|
|
|
+ }
|
|
|
|
+ //read synchronizer by id from database
|
|
|
|
+ Synchronizers synchronizer = synchronizersService.get(jobSynchronizer.getId());
|
|
|
|
+ _logger.trace("synchronizer " + synchronizer);
|
|
|
|
+ return synchronizer;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|