-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0da5cfe
commit 9e72846
Showing
4 changed files
with
107 additions
and
50 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/io/vanillabp/springboot/adapter/SpringBeanUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package io.vanillabp.springboot.adapter; | ||
|
||
import io.vanillabp.spi.service.WorkflowService; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.event.ContextRefreshedEvent; | ||
import org.springframework.context.event.EventListener; | ||
|
||
import java.util.Map; | ||
|
||
public class SpringBeanUtil { | ||
|
||
private final ApplicationContext applicationContext; | ||
|
||
private Map<String, Object> workflowAnnotatedBeansCache; | ||
|
||
private boolean cached = true; | ||
|
||
public SpringBeanUtil( | ||
final ApplicationContext applicationContext) { | ||
|
||
this.applicationContext = applicationContext; | ||
|
||
} | ||
|
||
public Map<String, Object> getWorkflowAnnotatedBeans() { | ||
|
||
synchronized (this) { | ||
if (workflowAnnotatedBeansCache != null) { | ||
return workflowAnnotatedBeansCache; | ||
} | ||
final var beans = applicationContext | ||
.getBeansWithAnnotation(WorkflowService.class); | ||
if (cached) { | ||
workflowAnnotatedBeansCache = beans; | ||
} | ||
return beans; | ||
} | ||
|
||
} | ||
|
||
@EventListener | ||
void onApplicationEvent( | ||
final ContextRefreshedEvent event) { | ||
|
||
synchronized (this) { | ||
cached = false; // only cache during startup | ||
workflowAnnotatedBeansCache = null; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters