Skip to content

Commit

Permalink
Logging important boot sequence events
Browse files Browse the repository at this point in the history
Changed a few string literals in the event one gets renamed, then there will be fewer places to change
  • Loading branch information
Ultraviolet-Ninja committed Oct 14, 2023
1 parent 5213f22 commit 3954ae2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/bomb/ManualController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void initialize() throws ExecutionException, InterruptedException {
regionMap = setupRegionMap().get();
long stop = System.nanoTime();
LOG.info("Boot Time: {}", convertTime(stop - start));
ObserverHub.ensureMapIsPopulated();
}

private static String convertTime(long nanos) {
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/bomb/tools/boot/FxmlBootDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import bomb.Widget;
import bomb.annotation.DisplayComponent;
import bomb.modules.ab.blind.alley.BlindAlley;
import bomb.modules.ab.blind.alley.BlindAlleyController;
import bomb.modules.s.souvenir.Souvenir;
import bomb.modules.s.souvenir.SouvenirController;
import bomb.tools.note.NoteController;
import bomb.tools.pattern.facade.FacadeFX;
Expand Down Expand Up @@ -44,6 +46,10 @@
* Reason is unknown, but more testing is required on other machines.
*/
public sealed interface FxmlBootDrive permits StandardFxmlBootDrive, VirtualThreadFxmlBootDrive {
String WIDGET_FILE = extractAssociatedFile(Widget.class);
String SOUVENIR_FILE = extractAssociatedFile(Souvenir.class);
String BLIND_ALLEY_FILE = extractAssociatedFile(BlindAlley.class);

Logger LOG = LoggerFactory.getLogger(FxmlBootDrive.class);
SequencedMap<String, Region> createFXMLMap(ResetObserver resetObserver);

Expand Down Expand Up @@ -91,10 +97,10 @@ private static Region loadSingleRegion(FXMLLoader loader, ResetObserver resetObs
Region output = FacadeFX.load(loader);
String location = loader.getLocation().toString();

if (!location.endsWith("widget.fxml")) resetObserver.addController(loader);
if (!location.endsWith(WIDGET_FILE)) resetObserver.addController(loader);

if (location.endsWith("souvenir.fxml")) loadSouvenirController(loader.getController());
else if (location.endsWith("blind_alley.fxml")) loadBlindAlleyController(loader.getController());
if (location.endsWith(SOUVENIR_FILE)) loadSouvenirController(loader.getController());
else if (location.endsWith(BLIND_ALLEY_FILE)) loadBlindAlleyController(loader.getController());
return output;
}

Expand All @@ -105,4 +111,9 @@ private static void loadBlindAlleyController(BlindAlleyController controller) {
private static void loadSouvenirController(SouvenirController controller) {
ObserverHub.addObserver(SOUVENIR_PANE, new SouvenirPaneObserver(controller));
}

private static String extractAssociatedFile(Class<?> clazz) {
return clazz.getAnnotation(DisplayComponent.class)
.resource();
}
}
26 changes: 23 additions & 3 deletions src/main/java/bomb/tools/pattern/observer/ObserverHub.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
package bomb.tools.pattern.observer;

import bomb.annotation.DisplayComponent;
import bomb.modules.ab.blind.alley.BlindAlley;
import bomb.modules.s.souvenir.Souvenir;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.EnumMap;
import java.util.Map;

import static bomb.tools.pattern.observer.ObserverHub.ObserverIndex.BLIND_ALLEY_PANE;
import static bomb.tools.pattern.observer.ObserverHub.ObserverIndex.SOUVENIR_TOGGLE;
import static bomb.tools.pattern.observer.ObserverHub.ObserverIndex.SOUVENIR_PANE;

public final class ObserverHub {
public enum ObserverIndex {
FORGET_ME_NOT_TOGGLE, SOUVENIR_TOGGLE, BLIND_ALLEY_PANE, SOUVENIR_PANE, RESET
}

private static final Logger LOG = LoggerFactory.getLogger(ObserverHub.class);
private static final EnumMap<ObserverIndex, Observer> OBSERVER_MAP = new EnumMap<>(ObserverIndex.class);
private static final Map<String, ObserverIndex> BUTTON_NAME_MAP = Map.of(
"Blind Alley", BLIND_ALLEY_PANE,
"Souvenir", SOUVENIR_TOGGLE
extractButtonLinkerName(BlindAlley.class), BLIND_ALLEY_PANE,
extractButtonLinkerName(Souvenir.class), SOUVENIR_PANE
);

private static String extractButtonLinkerName(Class<?> clazz) {
return clazz.getAnnotation(DisplayComponent.class)
.buttonLinkerName();
}

private ObserverHub() {
}

public static void addObserver(ObserverIndex index, Observer observer) {
if (OBSERVER_MAP.containsKey(index)) {
LOG.warn("{} value will be overwritten", index);
}
OBSERVER_MAP.put(index, observer);
}

Expand All @@ -35,4 +49,10 @@ public static void scanButtonName(@NotNull String buttonName) {
updateAtIndex(BUTTON_NAME_MAP.get(buttonName));
}
}

public static void ensureMapIsPopulated() {
if (ObserverIndex.values().length != OBSERVER_MAP.size()) {
LOG.warn("Observers not fully populated: {}", OBSERVER_MAP);
}
}
}

0 comments on commit 3954ae2

Please sign in to comment.