-
Notifications
You must be signed in to change notification settings - Fork 167
Support @PostConstruct and @PreDestroy #2544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2ba7e13
Support @PostConstruct and @PreDestroy
rrayst 3f5f743
Merge branch 'master' into support-post-construct-and-pre-destroy
christiangoerdes 5371d8d
fix: compilation error
rrayst e7167ab
doc
rrayst e882513
Merge branch 'master' into support-post-construct-and-pre-destroy
rrayst b308a7a
Merge branch 'master' into support-post-construct-and-pre-destroy
rrayst e6029f7
refactor
rrayst c540e0a
Merge branch 'support-post-construct-and-pre-destroy' of https://gith…
rrayst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanLifecycleManager.java
This file contains hidden or 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,23 @@ | ||
| package com.predic8.membrane.annot.beanregistry; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| /** | ||
| * A BeanLifecycleManager supports the init-destroy lifecycle of beans. | ||
| * | ||
| * Beans are inited (@PostConstruct method called) when they are being defined, that is before their instance is | ||
| * published via the registry. | ||
| * | ||
| * Beans are destroyed (@PreDestroy method called) when close() is called on the registry. | ||
| * | ||
| * The registry implements this interface. | ||
| */ | ||
| public interface BeanLifecycleManager { | ||
| /** | ||
| * Tells the registry that the <code>method</code> should be called on the <code>bean</code> when the registry is | ||
| * closed. | ||
| * | ||
| * The registry should call all pre-destroy-callbacks in <b>reverse</b> order in which they were registered. | ||
| */ | ||
| void addPreDestroyCallback(Object bean, Method method); | ||
| } |
This file contains hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
annot/src/main/java/com/predic8/membrane/annot/beanregistry/SpringContextAdapter.java
This file contains hidden or 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,68 @@ | ||
| package com.predic8.membrane.annot.beanregistry; | ||
|
|
||
| import com.predic8.membrane.annot.Grammar; | ||
| import org.springframework.context.ApplicationContext; | ||
| import org.springframework.context.support.AbstractRefreshableApplicationContext; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Adapter between Membrane's BeanRegistry and Spring's ApplicationContext. | ||
| * | ||
| * Methods are only implemented on a need-to-use basis. | ||
| */ | ||
| public class SpringContextAdapter implements BeanRegistry { | ||
|
|
||
| private final AbstractRefreshableApplicationContext ac; | ||
|
|
||
| public SpringContextAdapter(AbstractRefreshableApplicationContext ac) { | ||
| this.ac = ac; | ||
| } | ||
|
|
||
| @Override | ||
| public Object resolve(String url) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Object> getBeans() { | ||
| return List.of(ac.getBeanDefinitionNames()).stream().map(ac::getBean).toList(); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| @Override | ||
| public Grammar getGrammar() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> List<T> getBeans(Class<T> clazz) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> Optional<T> getBean(Class<T> clazz) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void register(String beanName, Object bean) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T registerIfAbsent(Class<T> type, Supplier<T> supplier) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| ac.close(); | ||
| } | ||
|
rrayst marked this conversation as resolved.
|
||
|
|
||
| public ApplicationContext getApplicationContext() { | ||
| return ac; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.