Skip to content

Commit

Permalink
RESTful service to List Diff Tasks : for large result lists avoid Out…
Browse files Browse the repository at this point in the history
…OfMemoryError #1333

- refactor/use also for bulk reschedule of tasks
  • Loading branch information
vrindanayak committed Jun 21, 2018
1 parent d969752 commit fa2481f
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.dcm4che3.json.JSONWriter;
import org.dcm4che3.net.Device;
import org.dcm4che3.ws.rs.MediaTypes;
import org.dcm4chee.arc.conf.ArchiveDeviceExtension;
import org.dcm4chee.arc.diff.DiffService;
import org.dcm4chee.arc.diff.DiffTaskQuery;
import org.dcm4chee.arc.entity.AttributesBlob;
Expand All @@ -72,6 +71,7 @@
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Date;
Expand Down Expand Up @@ -312,19 +312,17 @@ private Response rescheduleTasks(Predicate matchQueueMessage) {
Predicate matchDiffTask = MatchTask.matchDiffTask(
localAET, primaryAET, secondaryAET, checkDifferent, checkMissing,
comparefields, createdTime, updatedTime);
ArchiveDeviceExtension arcDev = device.getDeviceExtension(ArchiveDeviceExtension.class);
int fetchSize = arcDev.getQueueTasksFetchSize();
int count = 0;
List<Long> diffTaskPks;
do {
diffTaskPks = diffService.getDiffTaskPks(matchQueueMessage, matchDiffTask, fetchSize);
for (long pk : diffTaskPks)
diffService.rescheduleDiffTask(pk, null);
count += diffTaskPks.size();
} while (diffTaskPks.size() >= fetchSize);
try (DiffTaskQuery diffTasks = diffService.listDiffTasks(
matchQueueMessage, matchDiffTask, null, 0,0)) {
for (DiffTask diffTask : diffTasks) {
diffService.rescheduleDiffTask(diffTask.getPk(), null);
count++;
}
}
queueEvent.setCount(count);
return count(count);
} catch (IllegalTaskStateException e) {
} catch (IllegalTaskStateException | IOException e) {
queueEvent.setException(e);
return rsp(Response.Status.CONFLICT, e.getMessage());
} finally {
Expand Down

0 comments on commit fa2481f

Please sign in to comment.