Merge pull request #3 from chberger/BATCHEE-140
BATCHEE-140 Propagate JobOperatorImpl instance to SimpleJobExecutionCallbackService
diff --git a/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java b/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java
index 9212839..092c5a8 100755
--- a/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/impl/JobOperatorImpl.java
@@ -297,6 +297,6 @@
}
public void waitFor(final long id) {
- callbackService.waitFor(id);
+ callbackService.waitFor(this,id);
}
}
diff --git a/jbatch/src/main/java/org/apache/batchee/container/services/callback/SimpleJobExecutionCallbackService.java b/jbatch/src/main/java/org/apache/batchee/container/services/callback/SimpleJobExecutionCallbackService.java
index bbf1465..f2c9666 100644
--- a/jbatch/src/main/java/org/apache/batchee/container/services/callback/SimpleJobExecutionCallbackService.java
+++ b/jbatch/src/main/java/org/apache/batchee/container/services/callback/SimpleJobExecutionCallbackService.java
@@ -18,9 +18,6 @@
import org.apache.batchee.container.exception.BatchContainerRuntimeException;
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
-import org.apache.batchee.container.services.BatchKernelService;
-import org.apache.batchee.container.services.InternalJobExecution;
-import org.apache.batchee.container.services.ServicesManager;
import org.apache.batchee.spi.JobExecutionCallbackService;
import org.apache.batchee.util.Batches;
@@ -32,6 +29,9 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import javax.batch.operations.JobOperator;
+import javax.batch.runtime.JobExecution;
+
public class SimpleJobExecutionCallbackService implements JobExecutionCallbackService {
private final ConcurrentMap<Long, Collection<CountDownLatch>> waiters = new ConcurrentHashMap<Long, Collection<CountDownLatch>>();
@@ -46,7 +46,7 @@
}
@Override
- public void waitFor(final long id) {
+ public void waitFor(final JobOperator jobOperator, final long id) {
Collection<CountDownLatch> toRelease = waiters.get(id);
if (toRelease == null) {
toRelease = new CopyOnWriteArrayList<CountDownLatch>();
@@ -55,7 +55,7 @@
toRelease = existing;
}
}
- if (checkIsDone(id)) {
+ if (checkIsDone(jobOperator, id)) {
return;
}
@@ -63,7 +63,7 @@
toRelease.add(latch);
try {
while (!latch.await(1, TimeUnit.SECONDS)) {
- if (checkIsDone(id)) {
+ if (checkIsDone(jobOperator, id)) {
return;
}
}
@@ -78,9 +78,9 @@
// no-op
}
- private boolean checkIsDone(final long id) {
+ private boolean checkIsDone(final JobOperator jobOperator, final long id) {
// check before blocking
- final InternalJobExecution finalCheckExec = ServicesManager.find().service(BatchKernelService.class).getJobExecution(id);
+ final JobExecution finalCheckExec = jobOperator.getJobExecution(id);
if (finalCheckExec != null && Batches.isDone(finalCheckExec.getBatchStatus())) {
waiters.remove(id);
return true;
diff --git a/jbatch/src/main/java/org/apache/batchee/spi/JobExecutionCallbackService.java b/jbatch/src/main/java/org/apache/batchee/spi/JobExecutionCallbackService.java
index 2496292..25bfd8c 100644
--- a/jbatch/src/main/java/org/apache/batchee/spi/JobExecutionCallbackService.java
+++ b/jbatch/src/main/java/org/apache/batchee/spi/JobExecutionCallbackService.java
@@ -16,9 +16,11 @@
*/
package org.apache.batchee.spi;
+import javax.batch.operations.JobOperator;
+
import org.apache.batchee.container.impl.jobinstance.RuntimeJobExecution;
public interface JobExecutionCallbackService extends BatchService {
void onJobExecutionDone(RuntimeJobExecution jobExecution);
- void waitFor(long id);
+ void waitFor(JobOperator jobOperator, long id);
}
diff --git a/jbatch/src/test/java/org/apache/batchee/container/impl/JobOperatorImplTest.java b/jbatch/src/test/java/org/apache/batchee/container/impl/JobOperatorImplTest.java
index 922a08b..4042cf5 100644
--- a/jbatch/src/test/java/org/apache/batchee/container/impl/JobOperatorImplTest.java
+++ b/jbatch/src/test/java/org/apache/batchee/container/impl/JobOperatorImplTest.java
@@ -34,7 +34,7 @@
public void runningExecutionMemory_BATCHEE112() {
final JobOperator operator = new JobOperatorImpl(new ServicesManager() {{
init(new Properties() {{
- setProperty(PersistenceManagerService.class.getName(), MemoryPersistenceManagerService.class.getName());
+ setProperty(PersistenceManagerService.class.getSimpleName(), MemoryPersistenceManagerService.class.getName());
}});
}});
for (int i = 0; i < 10; i++) {