1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.hr.time.batch;
17
18 import java.util.List;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.log4j.Logger;
22 import org.kuali.hr.time.service.base.TkServiceLocator;
23 import org.kuali.hr.time.util.TKUtils;
24 import org.kuali.hr.time.util.TkConstants;
25
26
27
28
29 public class BatchJobEntryPoller extends Thread {
30 private static final Logger LOG = Logger.getLogger(BatchJobEntryPoller.class);
31
32 TkBatchManager manager;
33 int secondsToSleep;
34 int startupSleep;
35 String ipAddress;
36
37 public BatchJobEntryPoller(TkBatchManager manager, int sleepSeconds, int startupSleep) {
38 this.manager = manager;
39 this.secondsToSleep = sleepSeconds;
40 this.startupSleep = startupSleep;
41 this.ipAddress = TKUtils.getIPNumber();
42 }
43
44 @Override
45 public void run() {
46
47 try {
48 Thread.sleep(1000 * startupSleep);
49 } catch (Exception e) {
50 LOG.error(e);
51 }
52
53 while(true) {
54 LOG.debug("Looking for BatchJobEntries to run on '" + this.ipAddress + "'");
55 try {
56
57 List<BatchJobEntry> entries = TkServiceLocator.getBatchJobEntryService().getBatchJobEntries(ipAddress, TkConstants.BATCH_JOB_ENTRY_STATUS.SCHEDULED);
58
59
60 for (BatchJobEntry entry : entries) {
61 manager.pool.submit(getRunnable(entry));
62 }
63 Thread.sleep(1000 * secondsToSleep);
64 } catch (Exception e) {
65 LOG.error(e);
66 }
67 }
68 }
69
70 private BatchJobEntryRunnable getRunnable(BatchJobEntry entry) {
71 BatchJobEntryRunnable bjer = null;
72
73 if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.APPROVE)) {
74 LOG.debug("Creating EmployeeApprovalBatchJobRunnable.");
75 bjer = new EmployeeApprovalBatchJobRunnable(entry);
76 } else if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.PAY_PERIOD_END)) {
77 LOG.debug("Creating PayPeriodEndBatchJobRunnable.");
78 bjer = new PayPeriodEndBatchJobRunnable(entry);
79 } else if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.SUPERVISOR_APPROVAL)) {
80 LOG.debug("Creating SupervisorApprovalBatchJobRunnabble.");
81 bjer = new SupervisorApprovalBatchJobRunnable(entry);
82 } else if (StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.INITIATE)) {
83 LOG.debug("Creating InitiateBatchJobRunnable.");
84 bjer = new InitiateBatchJobRunnable(entry);
85 } else if(StringUtils.equals(entry.getBatchJobName(), TkConstants.BATCH_JOB_NAMES.BATCH_APPROVE_MISSED_PUNCH)) {
86 LOG.debug("Creating BatchApproveMissedPunchJobRunnable.");
87 bjer = new BatchApproveMissedPunchJobRunnable(entry);
88 } else {
89 LOG.warn("Unknown BatchJobEntryRunnable found in BatchJobEntry table. Unable to create Runnable.");
90 }
91
92 return bjer;
93 }
94
95 }