33import com .github .benmanes .caffeine .cache .Cache ;
44import com .github .benmanes .caffeine .cache .Caffeine ;
55import java .time .Duration ;
6+ import jenkins .util .SystemProperties ;
67import org .jenkinsci .plugins .workflow .flow .FlowExecution ;
78import org .jenkinsci .plugins .workflow .job .WorkflowRun ;
89
@@ -20,26 +21,24 @@ public static LiveGraphRegistry get() {
2021 return INSTANCE ;
2122 }
2223
23- /**
24- * Escape hatch. Setting this system property to {@code false} makes
25- * {@link #snapshot(WorkflowRun)} always return {@code null}, forcing callers to use the
26- * scanner fallback. Useful if a regression lands in the live-state path.
27- */
28- private static final String ENABLED_PROPERTY = "pipelinegraphview.livestate.enabled" ;
29-
3024 private final Cache <String , LiveGraphState > states = Caffeine .newBuilder ()
3125 .maximumSize (256 )
3226 .expireAfterAccess (Duration .ofMinutes (30 ))
3327 .build ();
3428
3529 LiveGraphRegistry () {}
3630
37- private static boolean enabled () {
38- return !"false" .equalsIgnoreCase (System .getProperty (ENABLED_PROPERTY ));
31+ /**
32+ * Escape hatch. Setting this system property to {@code false} makes
33+ * {@link #snapshot(WorkflowRun)} always return {@code null}, forcing callers to use the
34+ * scanner fallback. Useful if a regression lands in the live-state path.
35+ */
36+ private static boolean disabled () {
37+ return !SystemProperties .getBoolean (LiveGraphRegistry .class .getName () + ".enabled" , true );
3938 }
4039
4140 LiveGraphState getOrCreate (FlowExecution execution ) {
42- if (! enabled ()) {
41+ if (disabled ()) {
4342 return null ;
4443 }
4544 String key = keyFor (execution );
@@ -49,21 +48,13 @@ LiveGraphState getOrCreate(FlowExecution execution) {
4948 return states .get (key , LiveGraphState ::new );
5049 }
5150
52- LiveGraphState get (FlowExecution execution ) {
53- if (!enabled ()) {
54- return null ;
55- }
56- String key = keyFor (execution );
57- return key == null ? null : states .getIfPresent (key );
58- }
59-
6051 /**
6152 * Returns a snapshot of the live state for this run, or {@code null} if none exists
6253 * (feature disabled, state never populated, state poisoned). Callers must treat
6354 * {@code null} as "fall back to the scanner path."
6455 */
6556 public LiveGraphSnapshot snapshot (WorkflowRun run ) {
66- if (! enabled ()) {
57+ if (disabled ()) {
6758 return null ;
6859 }
6960 LiveGraphState state = states .getIfPresent (run .getExternalizableId ());
@@ -77,11 +68,6 @@ void remove(FlowExecution execution) {
7768 }
7869 }
7970
80- /** Test hook: drop all entries so a fresh Jenkins instance starts with a clean slate. */
81- void invalidateAll () {
82- states .invalidateAll ();
83- }
84-
8571 private static String keyFor (FlowExecution execution ) {
8672 try {
8773 Object exec = execution .getOwner ().getExecutable ();
0 commit comments