Skip to content

Commit fc0713f

Browse files
committed
Replace hard-coded job wakeup signal constants
1 parent 1f0186a commit fc0713f

3 files changed

Lines changed: 19 additions & 12 deletions

File tree

framework/jobs/src/org/apache/cloudstack/framework/jobs/AsyncJob.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public static interface Topics {
3131
public static final String JOB_HEARTBEAT = "job.heartbeat";
3232
public static final String JOB_STATE = "job.state";
3333
}
34+
35+
public static interface Contants {
36+
37+
// Although we may have detailed masks for each individual wakeup event, i.e.
38+
// periodical timer, matched topic from message bus, it seems that we don't
39+
// need to distinguish them to such level. Therefore, only one wakeup signal
40+
// is defined
41+
public static final int SIGNAL_MASK_WAKEUP = 1;
42+
}
3443

3544
@Override
3645
String getType();

framework/jobs/src/org/apache/cloudstack/framework/jobs/dao/AsyncJobJoinMapDaoImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.apache.log4j.Logger;
2828

29+
import org.apache.cloudstack.framework.jobs.AsyncJob;
2930
import org.apache.cloudstack.framework.jobs.impl.AsyncJobJoinMapVO;
3031
import org.apache.cloudstack.jobs.JobInfo;
3132

@@ -158,11 +159,12 @@ public List<Long> wakeupScan() {
158159
//
159160
// performance sensitive processing, do it in plain SQL
160161
//
161-
String sql = "UPDATE async_job SET job_pending_signals=1 WHERE id IN " +
162+
String sql = "UPDATE async_job SET job_pending_signals=? WHERE id IN " +
162163
"(SELECT job_id FROM async_job_join_map WHERE next_wakeup < ? AND expiration > ?)";
163164
pstmt = txn.prepareStatement(sql);
164-
pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutDate));
165+
pstmt.setInt(1, AsyncJob.Contants.SIGNAL_MASK_WAKEUP);
165166
pstmt.setString(2, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutDate));
167+
pstmt.setString(3, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"), cutDate));
166168
pstmt.executeUpdate();
167169
pstmt.close();
168170

@@ -213,10 +215,11 @@ public List<Long> wakeupByJoinedJobCompletion(long joinedJobId) {
213215
//
214216
// performance sensitive processing, do it in plain SQL
215217
//
216-
String sql = "UPDATE async_job SET job_pending_signals=1 WHERE id IN " +
218+
String sql = "UPDATE async_job SET job_pending_signals=? WHERE id IN " +
217219
"(SELECT job_id FROM async_job_join_map WHERE join_job_id = ?)";
218220
pstmt = txn.prepareStatement(sql);
219-
pstmt.setLong(1, joinedJobId);
221+
pstmt.setInt(1, AsyncJob.Contants.SIGNAL_MASK_WAKEUP);
222+
pstmt.setLong(2, joinedJobId);
220223
pstmt.executeUpdate();
221224
pstmt.close();
222225

framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/AsyncJobManagerImpl.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ public class AsyncJobManagerImpl extends ManagerBase implements AsyncJobManager,
8080

8181
private static final Logger s_logger = Logger.getLogger(AsyncJobManagerImpl.class);
8282
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds
83-
// Although we may have detailed masks for each individual wakeup event, i.e.
84-
// periodical timer, matched topic from message bus, it seems that we don't
85-
// need to distinguish them to such level. Therefore, only one wakeup signal
86-
// is defined
87-
public static final int SIGNAL_MASK_WAKEUP = 1;
8883

8984
private static final int MAX_ONETIME_SCHEDULE_SIZE = 50;
9085
private static final int HEARTBEAT_INTERVAL = 2000;
@@ -235,7 +230,7 @@ public void completeAsyncJob(long jobId, Status jobStatus, int resultCode, Strin
235230
for(Long id : wakeupList) {
236231
// TODO, we assume that all jobs in this category is API job only
237232
AsyncJobVO jobToWakeup = _jobDao.findById(id);
238-
if (jobToWakeup != null && (jobToWakeup.getPendingSignals() & SIGNAL_MASK_WAKEUP) != 0)
233+
if (jobToWakeup != null && (jobToWakeup.getPendingSignals() & AsyncJob.Contants.SIGNAL_MASK_WAKEUP) != 0)
239234
scheduleExecution(jobToWakeup, false);
240235
}
241236

@@ -462,7 +457,7 @@ public void run() {
462457
s_logger.debug("Executing " + job);
463458
}
464459

465-
if ((getAndResetPendingSignals(job) & SIGNAL_MASK_WAKEUP) != 0) {
460+
if ((getAndResetPendingSignals(job) & AsyncJob.Contants.SIGNAL_MASK_WAKEUP) != 0) {
466461
AsyncJobDispatcher jobDispatcher = getWakeupDispatcher(job);
467462
if(jobDispatcher != null) {
468463
jobDispatcher.runJob(job);
@@ -651,7 +646,7 @@ public void run() {
651646
for(Long jobId : standaloneWakeupJobs) {
652647
// TODO, we assume that all jobs in this category is API job only
653648
AsyncJobVO job = _jobDao.findById(jobId);
654-
if (job != null && (job.getPendingSignals() & SIGNAL_MASK_WAKEUP) != 0)
649+
if (job != null && (job.getPendingSignals() & AsyncJob.Contants.SIGNAL_MASK_WAKEUP) != 0)
655650
scheduleExecution(job, false);
656651
}
657652
} catch(Throwable e) {

0 commit comments

Comments
 (0)