Skip to content

Commit

Permalink
Fixing the loading of SPI contributions for Annunciators
Browse files Browse the repository at this point in the history
  • Loading branch information
shroffk committed Apr 12, 2024
1 parent cb5574a commit f829f3d
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.phoebus.applications.alarm.model.SeverityLevel;
import org.phoebus.framework.adapter.AdapterFactory;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class AnnunciatorController

private final BlockingQueue<AnnunciatorMessage> to_annunciate = new LinkedBlockingQueue<>();

private static ServiceLoader<Annunciator> loader;
private final List<Annunciator> annunciators;

private final Thread process_thread = new Thread(this::processMessages, "Annunciator");

Expand All @@ -62,6 +63,10 @@ public AnnunciatorController(final int threshold, final Consumer<AnnunciatorMess
this.threshold = threshold;
this.addToTable = addToTable;

// Initialize the annunciators
ServiceLoader<Annunciator> loader = ServiceLoader.load(Annunciator.class);
annunciators = loader.stream().map(ServiceLoader.Provider::get).collect(Collectors.toList());

// The thread should exit when requested by shutdown() call, but set to daemon so it dies
// when program closes regardless.
process_thread.setDaemon(true);
Expand All @@ -84,8 +89,6 @@ private void processMessages()
{
final List<AnnunciatorMessage> batch = new ArrayList<>();

loader = ServiceLoader.load(Annunciator.class);

// Process new messages until receiving LAST_MESSAGE
while (true)
{
Expand Down Expand Up @@ -120,8 +123,8 @@ private void processMessages()
{
addToTable.accept(message);
if (! muted)
loader.stream().forEach(annunciatorProvider -> {
annunciatorProvider.get().speak(message);
annunciators.stream().forEach(annunciator -> {
annunciator.speak(message);
});
}
}
Expand All @@ -138,7 +141,9 @@ private void processMessages()
addToTable.accept(message);
if (! muted)
{
loader.stream().forEach(annunciatorProvider -> annunciatorProvider.get().speak(message));
annunciators.stream().forEach(annunciator -> {
annunciator.speak(message);
});
}
}
else
Expand All @@ -154,7 +159,9 @@ private void processMessages()
addToTable.accept(message);
if (! muted)
{
loader.stream().forEach(annunciatorProvider -> annunciatorProvider.get().speak(message));
annunciators.stream().forEach(annunciator -> {
annunciator.speak(message);
});
}
}
}
Expand All @@ -173,7 +180,8 @@ public void shutdown() throws InterruptedException
process_thread.join(2000);

// Deallocate the annunciator's voice.
loader.stream().forEach(annunciatorProvider -> annunciatorProvider.get().shutdown());

annunciators.stream().forEach(annunciator -> {
annunciator.shutdown();
});
}
}

0 comments on commit f829f3d

Please sign in to comment.