47
47
import org .slf4j .LoggerFactory ;
48
48
import org .springframework .beans .BeansException ;
49
49
import org .springframework .context .ApplicationContext ;
50
+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
50
51
import org .springframework .core .env .ConfigurableEnvironment ;
51
52
52
53
import com .fasterxml .jackson .databind .ObjectMapper ;
61
62
import dev .dsf .bpe .api .plugin .ProcessPlugin ;
62
63
import dev .dsf .bpe .api .plugin .ProcessPluginFhirConfig ;
63
64
import dev .dsf .bpe .v2 .ProcessPluginApi ;
65
+ import dev .dsf .bpe .v2 .ProcessPluginApiFactory ;
64
66
import dev .dsf .bpe .v2 .ProcessPluginDefinition ;
65
67
import dev .dsf .bpe .v2 .ProcessPluginDeploymentListener ;
66
68
import dev .dsf .bpe .v2 .activity .Activity ;
@@ -92,11 +94,12 @@ public class ProcessPluginImpl extends AbstractProcessPlugin<UserTaskListener> i
92
94
private static final Logger logger = LoggerFactory .getLogger (ProcessPluginImpl .class );
93
95
94
96
private final ProcessPluginDefinition processPluginDefinition ;
95
- private final ProcessPluginApi processPluginApi ;
96
97
97
98
private final Function <DelegateExecution , Variables > variablesFactory ;
98
99
private final PluginMdc pluginMdc ;
99
100
101
+ private final AtomicReference <ProcessPluginApi > processPluginApi = new AtomicReference <>();
102
+ private final AtomicReference <FhirContext > fhirContext = new AtomicReference <>();
100
103
private final AtomicReference <ObjectMapper > objectMapper = new AtomicReference <>();
101
104
102
105
public ProcessPluginImpl (ProcessPluginDefinition processPluginDefinition , int processPluginApiVersion ,
@@ -109,13 +112,61 @@ public ProcessPluginImpl(ProcessPluginDefinition processPluginDefinition, int pr
109
112
MessageEndEvent .class , DefaultUserTaskListener .class );
110
113
111
114
this .processPluginDefinition = processPluginDefinition ;
112
- processPluginApi = apiApplicationContext .getBean (ProcessPluginApi .class );
113
115
114
116
variablesFactory = delegateExecution -> new VariablesImpl (delegateExecution , getObjectMapper ());
115
117
pluginMdc = new PluginMdcImpl (processPluginApiVersion , processPluginDefinition .getName (),
116
118
processPluginDefinition .getVersion (), jarFile .toString (), serverBaseUrl , variablesFactory );
117
119
}
118
120
121
+ @ Override
122
+ protected void customizeApplicationContext (AnnotationConfigApplicationContext context ,
123
+ ApplicationContext parentContext )
124
+ {
125
+ context .registerBean ("processPluginDefinition" , ProcessPluginDefinition .class , () -> processPluginDefinition );
126
+ context .registerBean ("api" , ProcessPluginApi .class ,
127
+ new ProcessPluginApiFactory (processPluginDefinition , parentContext ));
128
+ }
129
+
130
+ private ProcessPluginApi getProcessPluginApi ()
131
+ {
132
+ ProcessPluginApi entry = processPluginApi .get ();
133
+ if (entry == null )
134
+ {
135
+ ProcessPluginApi o = doGetProcessPluginApi ();
136
+ if (processPluginApi .compareAndSet (entry , o ))
137
+ return o ;
138
+ else
139
+ return processPluginApi .get ();
140
+ }
141
+ else
142
+ return entry ;
143
+ }
144
+
145
+ private ProcessPluginApi doGetProcessPluginApi ()
146
+ {
147
+ return getApplicationContext ().getBean (ProcessPluginApi .class );
148
+ }
149
+
150
+ private FhirContext getFhirContext ()
151
+ {
152
+ FhirContext entry = fhirContext .get ();
153
+ if (entry == null )
154
+ {
155
+ FhirContext o = doGetFhirContext ();
156
+ if (fhirContext .compareAndSet (entry , o ))
157
+ return o ;
158
+ else
159
+ return fhirContext .get ();
160
+ }
161
+ else
162
+ return entry ;
163
+ }
164
+
165
+ private FhirContext doGetFhirContext ()
166
+ {
167
+ return getApplicationContext ().getBean (FhirContext .class );
168
+ }
169
+
119
170
private ObjectMapper getObjectMapper ()
120
171
{
121
172
ObjectMapper entry = objectMapper .get ();
@@ -264,7 +315,7 @@ private IParser newJsonParser()
264
315
265
316
private IParser newParser (Function <FhirContext , IParser > parserFactor )
266
317
{
267
- IParser p = parserFactor .apply (processPluginApi . getFhirContext ());
318
+ IParser p = parserFactor .apply (getFhirContext ());
268
319
p .setStripVersionsFromReferences (false );
269
320
p .setOverrideResourceIdWithBundleEntryFullUrl (false );
270
321
@@ -383,7 +434,7 @@ public JavaDelegate getMessageSendTask(String className, List<FieldDeclaration>
383
434
SendTaskValues sendTaskValues = getSendTaskValues (fieldDeclarations , variableScope )
384
435
.orElseThrow (noOrIncompleteFhirTaskFields ("MessageSendTask" , className ));
385
436
386
- return new MessageSendTaskDelegate (processPluginApi , variablesFactory , target , sendTaskValues );
437
+ return new MessageSendTaskDelegate (getProcessPluginApi () , variablesFactory , target , sendTaskValues );
387
438
}
388
439
389
440
@ Override
@@ -393,7 +444,7 @@ public JavaDelegate getServiceTask(String className, List<FieldDeclaration> fiel
393
444
ServiceTask target = get (ServiceTask .class , className );
394
445
injectFields (target , fieldDeclarations , variableScope );
395
446
396
- return new ServiceTaskDelegate (processPluginApi , variablesFactory , target );
447
+ return new ServiceTaskDelegate (getProcessPluginApi () , variablesFactory , target );
397
448
}
398
449
399
450
@ Override
@@ -406,7 +457,7 @@ public JavaDelegate getMessageEndEvent(String className, List<FieldDeclaration>
406
457
SendTaskValues sendTaskValues = getSendTaskValues (fieldDeclarations , variableScope )
407
458
.orElseThrow (noOrIncompleteFhirTaskFields ("MessageEndEvent" , className ));
408
459
409
- return new MessageEndEventDelegate (processPluginApi , variablesFactory , target , sendTaskValues );
460
+ return new MessageEndEventDelegate (getProcessPluginApi () , variablesFactory , target , sendTaskValues );
410
461
}
411
462
412
463
@ Override
@@ -419,7 +470,8 @@ public JavaDelegate getMessageIntermediateThrowEvent(String className, List<Fiel
419
470
SendTaskValues sendTaskValues = getSendTaskValues (fieldDeclarations , variableScope )
420
471
.orElseThrow (noOrIncompleteFhirTaskFields ("MessageIntermediateThrowEvent" , className ));
421
472
422
- return new MessageIntermediateThrowEventDelegate (processPluginApi , variablesFactory , target , sendTaskValues );
473
+ return new MessageIntermediateThrowEventDelegate (getProcessPluginApi (), variablesFactory , target ,
474
+ sendTaskValues );
423
475
}
424
476
425
477
@ Override
@@ -429,7 +481,7 @@ public org.camunda.bpm.engine.delegate.ExecutionListener getExecutionListener(St
429
481
ExecutionListener target = get (ExecutionListener .class , className );
430
482
injectFields (target , fieldDeclarations , variableScope );
431
483
432
- return new ExecutionListenerDelegate (processPluginApi , variablesFactory , target );
484
+ return new ExecutionListenerDelegate (getProcessPluginApi () , variablesFactory , target );
433
485
}
434
486
435
487
@ Override
@@ -439,7 +491,7 @@ public TaskListener getTaskListener(String className, List<FieldDeclaration> fie
439
491
UserTaskListener target = get (UserTaskListener .class , className );
440
492
ClassDelegateUtil .applyFieldDeclaration (fieldDeclarations , target );
441
493
442
- return new UserTaskListenerDelegate (processPluginApi , variablesFactory , target );
494
+ return new UserTaskListenerDelegate (getProcessPluginApi () , variablesFactory , target );
443
495
}
444
496
445
497
private List <FieldDeclaration > filterFhirTaskValues (List <FieldDeclaration > fieldDeclarations )
0 commit comments