@@ -58,6 +58,7 @@ public class ShortCircuitWorkerService {
58
58
private final ShortCircuitExecutionService shortCircuitExecutionService ;
59
59
private final ObjectMapper objectMapper ;
60
60
private final Collection <AbstractReportMapper > reportMappers ;
61
+ private final ShortCircuitObserver shortCircuitObserver ;
61
62
62
63
private final Map <UUID , CompletableFuture <ShortCircuitAnalysisResult >> futures = new ConcurrentHashMap <>();
63
64
@@ -70,14 +71,15 @@ public class ShortCircuitWorkerService {
70
71
@ Autowired
71
72
public ShortCircuitWorkerService (NetworkStoreService networkStoreService , ReportService reportService , ShortCircuitExecutionService shortCircuitExecutionService ,
72
73
NotificationService notificationService , ShortCircuitAnalysisResultRepository resultRepository ,
73
- ObjectMapper objectMapper , Collection <AbstractReportMapper > reportMappers ) {
74
+ ObjectMapper objectMapper , Collection <AbstractReportMapper > reportMappers , ShortCircuitObserver shortCircuitObserver ) {
74
75
this .networkStoreService = Objects .requireNonNull (networkStoreService );
75
76
this .reportService = Objects .requireNonNull (reportService );
76
77
this .shortCircuitExecutionService = Objects .requireNonNull (shortCircuitExecutionService );
77
78
this .notificationService = Objects .requireNonNull (notificationService );
78
79
this .resultRepository = Objects .requireNonNull (resultRepository );
79
80
this .objectMapper = Objects .requireNonNull (objectMapper );
80
81
this .reportMappers = Objects .requireNonNull (reportMappers );
82
+ this .shortCircuitObserver = shortCircuitObserver ;
81
83
}
82
84
83
85
private Network getNetwork (UUID networkUuid , String variantId ) {
@@ -92,34 +94,36 @@ private Network getNetwork(UUID networkUuid, String variantId) {
92
94
return network ;
93
95
}
94
96
95
- private ShortCircuitAnalysisResult run (ShortCircuitRunContext context , UUID resultUuid ) throws ExecutionException , InterruptedException {
97
+ private ShortCircuitAnalysisResult run (ShortCircuitRunContext context , UUID resultUuid ) throws Exception {
96
98
Objects .requireNonNull (context );
97
99
98
100
LOGGER .info ("Run short circuit analysis..." );
99
- Network network = getNetwork (context .getNetworkUuid (), context .getVariantId ());
101
+ Network network = shortCircuitObserver . observe ( "network.load" , () -> getNetwork (context .getNetworkUuid (), context .getVariantId () ));
100
102
101
- Reporter rootReporter = Reporter .NO_OP ;
103
+ AtomicReference < Reporter > rootReporter = new AtomicReference <>( Reporter .NO_OP ) ;
102
104
Reporter reporter = Reporter .NO_OP ;
103
105
if (context .getReportUuid () != null ) {
104
- String reportType = context .getReportType ();
105
- if (StringUtils .isEmpty (reportType )) {
106
- reportType = StringUtils .isEmpty (context .getBusId ()) ? SHORTCIRCUIT_ALL_BUSES_DEFAULT_TYPE_REPORT : SHORTCIRCUIT_ONE_BUS_DEFAULT_TYPE_REPORT ;
106
+ AtomicReference <String > reportType = new AtomicReference <>();
107
+ reportType .set (context .getReportType ());
108
+ if (StringUtils .isEmpty (reportType .get ())) {
109
+ reportType .set (StringUtils .isEmpty (context .getBusId ()) ? SHORTCIRCUIT_ALL_BUSES_DEFAULT_TYPE_REPORT : SHORTCIRCUIT_ONE_BUS_DEFAULT_TYPE_REPORT );
107
110
}
108
- String rootReporterId = context .getReporterId () == null ? reportType : context .getReporterId () + "@" + reportType ;
109
- rootReporter = new ReporterModel (rootReporterId , rootReporterId );
110
- reporter = rootReporter .createSubReporter (reportType , reportType + " (${providerToUse})" , "providerToUse" , ShortCircuitAnalysis .find ().getName ());
111
+ String rootReporterId = context .getReporterId () == null ? reportType . get () : context .getReporterId () + "@" + reportType . get () ;
112
+ rootReporter . set ( new ReporterModel (rootReporterId , rootReporterId ) );
113
+ reporter = rootReporter .get (). createSubReporter (reportType . get () , reportType + " (${providerToUse})" , "providerToUse" , ShortCircuitAnalysis .find ().getName ());
111
114
// Delete any previous short-circuit computation logs
112
- reportService .deleteReport (context .getReportUuid (), reportType );
115
+ shortCircuitObserver . observe ( "report.delete" , () -> reportService .deleteReport (context .getReportUuid (), reportType . get ()) );
113
116
}
114
117
115
118
CompletableFuture <ShortCircuitAnalysisResult > future = runShortCircuitAnalysisAsync (context , network , reporter , resultUuid );
116
119
117
- ShortCircuitAnalysisResult result = future == null ? null : future .get ();
120
+ ShortCircuitAnalysisResult result = future == null ? null : shortCircuitObserver .observeRun ("run" , future ::get );
121
+
118
122
if (context .getReportUuid () != null ) {
119
123
for (final AbstractReportMapper reportMapper : reportMappers ) {
120
- rootReporter = reportMapper .processReporter (rootReporter );
124
+ rootReporter . set ( reportMapper .processReporter (rootReporter . get ()) );
121
125
}
122
- reportService .sendReport (context .getReportUuid (), rootReporter );
126
+ shortCircuitObserver . observe ( "report.send" , () -> reportService .sendReport (context .getReportUuid (), rootReporter . get ()) );
123
127
}
124
128
return result ;
125
129
}
@@ -231,7 +235,7 @@ public Consumer<Message<String>> consumeRun() {
231
235
long nanoTime = System .nanoTime ();
232
236
LOGGER .info ("Just run in {}s" , TimeUnit .NANOSECONDS .toSeconds (nanoTime - startTime .getAndSet (nanoTime )));
233
237
234
- resultRepository .insert (resultContext .getResultUuid (), result , resultContext .getRunContext ().getShortCircuitLimits (), ShortCircuitAnalysisStatus .COMPLETED .name ());
238
+ shortCircuitObserver . observe ( "results.save" , () -> resultRepository .insert (resultContext .getResultUuid (), result , resultContext .getRunContext ().getShortCircuitLimits (), ShortCircuitAnalysisStatus .COMPLETED .name () ));
235
239
long finalNanoTime = System .nanoTime ();
236
240
LOGGER .info ("Stored in {}s" , TimeUnit .NANOSECONDS .toSeconds (finalNanoTime - startTime .getAndSet (finalNanoTime )));
237
241
0 commit comments