Skip to content

Commit

Permalink
Change DICOM storage stop behavior to soft stop
Browse files Browse the repository at this point in the history
- let the index queue worker thread
  finish processing all items in queue before exiting
- do not interrupt ongoing indexing tasks
  • Loading branch information
Enet4 committed Jan 26, 2024
1 parent 5fafbd3 commit 30f73de
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions dicoogle/src/main/java/pt/ua/dicoogle/server/DicomStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public class DicomStorage extends StorageService {
private BlockingQueue<ImageElement> queue = new PriorityBlockingQueue<>();
private NetworkApplicationEntity[] naeArr = null;
private AtomicLong seqNum = new AtomicLong(0L);
/**
* Whether the index worker thread
* should exit once it finishes processing the queue.
*/
private volatile boolean workerShouldExit = false;

private static boolean ASYNC_INDEX = Boolean.valueOf(System.getProperty("dicoogle.index.async", "true"));
Expand Down Expand Up @@ -373,9 +377,12 @@ class IndexerQueueWorker implements Runnable {

@Override
public void run() {
while (!workerShouldExit) {
while (true) {
try {
// Fetch an element by the queue taking into account the priorities.
if (workerShouldExit && queue.isEmpty()) {
break;
}
ImageElement element = queue.take();
URI exam = element.getUri();
if (ASYNC_INDEX)
Expand Down Expand Up @@ -415,6 +422,5 @@ public void start() throws IOException {
public void stop() {
device.stopListening();
workerShouldExit = true;
indexer.interrupt();
}
}

0 comments on commit 30f73de

Please sign in to comment.