-
Notifications
You must be signed in to change notification settings - Fork 0
DI wrapping ObjectCache for SQL object cache #20
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
5 commits
Select commit
Hold shift + click to select a range
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
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
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
79 changes: 79 additions & 0 deletions
79
src/main/java/com/yetanalytics/hlaxapi/cache/ObjectCache.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,79 @@ | ||
| package com.yetanalytics.hlaxapi.cache; | ||
|
|
||
| import com.yetanalytics.hlaxapi.FOMXML; | ||
| import com.yetanalytics.hlaxapi.HLADecoderRegistry; | ||
| import com.yetanalytics.hlaxapi.config.XapiConfig; | ||
| import com.yetanalytics.hlaxapi.config.model.Expression; | ||
| import com.yetanalytics.hlaxapi.config.model.Target; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
|
|
||
| public class ObjectCache implements AutoCloseable { | ||
|
|
||
| private final FomCatalog catalog; | ||
| private final Map<String, Set<String>> subscriptions; | ||
| private HlaObjectCache delegate; | ||
|
|
||
| public ObjectCache(XapiConfig xapiConfig, FomCatalog catalog, FOMXML fomXml, HLADecoderRegistry decoderRegistry) { | ||
| this(xapiConfig, catalog, fomXml, decoderRegistry, HlaObjectCache.defaultJdbcUrl()); | ||
| } | ||
|
|
||
| ObjectCache( | ||
| XapiConfig xapiConfig, | ||
| FomCatalog catalog, | ||
| FOMXML fomXml, | ||
| HLADecoderRegistry decoderRegistry, | ||
| String jdbcUrl) { | ||
| this.catalog = catalog; | ||
| this.subscriptions = QueryReferenceCollector.collect(xapiConfig.statementTriggers); | ||
| if (!subscriptions.isEmpty()) { | ||
| this.delegate = new HlaObjectCache(jdbcUrl, catalog, fomXml, decoderRegistry); | ||
| } | ||
| } | ||
|
|
||
| public boolean isEnabled() { | ||
| return delegate != null; | ||
| } | ||
|
|
||
| public Map<String, Set<String>> subscriptions() { | ||
| return subscriptions; | ||
| } | ||
|
|
||
| public FomCatalog catalog() { | ||
| return catalog; | ||
| } | ||
|
|
||
| public Optional<Object> findFirstValue(String clazz, Target attrTarget, Expression criteria) { | ||
| if (delegate == null) { | ||
| return Optional.empty(); | ||
| } | ||
| return delegate.queryService().findFirstValue(clazz, attrTarget, criteria); | ||
| } | ||
|
|
||
| public void discoverObject(String objectHandle, String objectName, String className) { | ||
| if (delegate != null) { | ||
| delegate.discoverObject(objectHandle, objectName, className); | ||
| } | ||
| } | ||
|
|
||
| public void reflectAttributeValue(String objectHandle, String className, String attributeName, byte[] bytes) { | ||
| if (delegate != null) { | ||
| delegate.reflectAttributeValue(objectHandle, className, attributeName, bytes); | ||
| } | ||
| } | ||
|
|
||
| public void removeObject(String objectHandle) { | ||
| if (delegate != null) { | ||
| delegate.removeObject(objectHandle); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public synchronized void close() { | ||
| if (delegate != null) { | ||
| delegate.close(); | ||
| delegate = null; | ||
| } | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
src/test/java/com/yetanalytics/hlaxapi/ObjectCacheSpringContextTest.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,62 @@ | ||
| package com.yetanalytics.hlaxapi; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
|
||
| import com.yetanalytics.hlaxapi.cache.FomCatalog; | ||
| import com.yetanalytics.hlaxapi.cache.ObjectCache; | ||
| import com.yetanalytics.hlaxapi.config.XapiConfig; | ||
| import hla.rti1516e.encoding.EncoderFactory; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.portico.impl.hla1516e.types.encoding.HLA1516eEncoderFactory; | ||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| class ObjectCacheSpringContextTest { | ||
|
|
||
| @Test | ||
| void springWiresObjectCacheIntoConsumers() { | ||
| try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) { | ||
| context.register( | ||
| TestConfig.class, | ||
| FOMXML.class, | ||
| FomCatalog.class, | ||
| HlaInterfaceImpl.class, | ||
| InjectionHandler.class, | ||
| TriggerProcessor.class); | ||
| context.refresh(); | ||
|
|
||
| FomCatalog fomCatalog = context.getBean(FomCatalog.class); | ||
| ObjectCache objectCache = context.getBean(ObjectCache.class); | ||
| InjectionHandler injectionHandler = context.getBean(InjectionHandler.class); | ||
| HlaInterfaceImpl hlaInterface = context.getBean(HlaInterfaceImpl.class); | ||
|
|
||
| assertNotNull(hlaInterface); | ||
| assertSame(fomCatalog, objectCache.catalog()); | ||
| assertSame(objectCache, injectionHandler.objectCache()); | ||
| } | ||
| } | ||
|
|
||
| @Configuration | ||
| static class TestConfig extends AppConfig { | ||
|
|
||
| @Override | ||
| @Bean | ||
| public EncoderFactory encoderFactory() { | ||
| return new HLA1516eEncoderFactory(); | ||
| } | ||
|
|
||
| @Override | ||
| @Bean | ||
| public XapiConfig xapiConfig() { | ||
| return new XapiConfig(); | ||
| } | ||
|
|
||
| @Override | ||
| @Bean | ||
| public SimulationConfig simulationConfig() { | ||
| return new SimulationConfig(null, null, null, null, "config/HlaFedereplFOM.xml"); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weird that we would do constructor injection when there are already wired beans. just change to autowired and kill the 1-arg constructor OR make it a 3-arg constructor to not mix DI methodologies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
84cb59d and dea2303
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and fef0683