Allow to create a CacheManager using an Ehcache builder#2347
Allow to create a CacheManager using an Ehcache builder#2347henri-tremblay wants to merge 9 commits intoehcache:masterfrom
Conversation
| public CacheManager getCacheManager(URI uri, ClassLoader classLoader, CacheManagerBuilder<org.ehcache.CacheManager> builder) { | ||
| Eh107CacheManager cacheManager; | ||
|
|
||
| synchronized (cacheManagers) { |
There was a problem hiding this comment.
We can probably extract this common block between here and the existing code in to a combination of a computeIfAbsent and a compute.
There was a problem hiding this comment.
Yes. I've been purposefully lazy.
| private Eh107CacheManager createCacheManager(URI uri, ClassLoader classLoader, CacheManagerBuilder<org.ehcache.CacheManager> builder) { | ||
| Eh107CacheLoaderWriterProvider cacheLoaderWriterFactory = new Eh107CacheLoaderWriterProvider(); | ||
|
|
||
| Object[] serviceCreationConfigurations = builder.getServices().toArray(); |
There was a problem hiding this comment.
Type safety all messed up here. The code is indeed looking for a ServiceCreationConfigurations but the builder will return services. We'll have to fix the "extra services" logic to catch both services instances and creation configs that would result in service instances. Would be good to have that as common between the two paths as well.
There was a problem hiding this comment.
Which means the findSingletonAmongst is strangely permissive and this code doesn't work at all? Or it supports both?
There was a problem hiding this comment.
findSingletonAmongst is just conventionally permissive. This is it's signature:
<T> T findSingletonAmongst(Class<T> clazz, Object ... instances)What we want as an end result is to be certain that the cache manager has a Jsr107Service and the Eh107CacheLoaderWriterProvider. We also need to make sure that any existing config is honored, which I think in this context means:
- use the 107 service creation config if it exists in the builder (that should be a natural thing though)
- not add a 107 service if there is one already defined
- not add the special loader writer factory if there is a loader writer already???
There was a problem hiding this comment.
Yep. I agree. Then, for the loader-writer... I'm not sure we actually need a CacheLoaderWriterProvider. We seem to just need something to handle CacheLoader and CacheWriter. The loader-writer is for a cache. So I guess we should ignore it is a CacheLoaderWriterProvider is already provided. If we want to keep things simple.
| services.add(new DefaultJsr107SerializationProvider()); | ||
| } | ||
|
|
||
| InternalCacheManager ehcacheManager = (InternalCacheManager) builder.build(true); |
There was a problem hiding this comment.
Need to actually add the services to the builder.
There was a problem hiding this comment.
Thats services collection doesn't get consumed (unless I'm missing something).
chrisdennis
left a comment
There was a problem hiding this comment.
Changes look good in principle but some details need fixing/clearing up.
94d1bd4 to
07631be
Compare
|
I think all changes were implemented. |
| this.jsr107Cache = ehCache.createJsr107Cache(); | ||
| } | ||
|
|
||
| private StatisticsService getStatisticsService(Eh107CacheManager cacheManager) { |
There was a problem hiding this comment.
Can be indeed
|
Could we separate this from the exposure of the ServiceLocator so that we can consider the two changes independently? |
|
It's hard (impossible?) because getting rid of |
|
Lets see if we can come to agreement on #2346 then, which would allow this to go through. |
07631be to
7792dca
Compare
d83920c to
3847f36
Compare
|
@chrisdennis Now rebased on top of #2346 . Can you have a look? |
| return getCacheManager(uri, classLoader, () -> createCacheManager(uri, classLoader, builder)); | ||
| } | ||
|
|
||
| private CacheManager getCacheManager(URI uri, ClassLoader classLoader, Supplier<Eh107CacheManager> cacheManagerCreator) { |
There was a problem hiding this comment.
It feel like this Supplier should really be a function, possibly taking the URI and ClassLoader as arguments.
There was a problem hiding this comment.
I tried but it makes things redundant. With lines like return getCacheManager(uri, classLoader, (u, c) -> createCacheManager(u, c, builder));. But I see what you mean. It removes the closure for these two params by the caller. But I still have a closure. Still prefer me to change it?
| private Eh107CacheManager createCacheManager(URI uri, Configuration config, Properties properties) { | ||
| Eh107CacheLoaderWriterProvider cacheLoaderWriterFactory = new Eh107CacheLoaderWriterProvider(); | ||
| private Eh107CacheManager createCacheManager(URI uri, ClassLoader classLoader, CacheManagerBuilder<org.ehcache.CacheManager> builder) { | ||
| Set<Service> services = builder.getServices(); |
There was a problem hiding this comment.
This method feels like it contains logic that should really be a part of the CacheManagerBuilder. Fixing this would mean either adding a new method to the builder that only added the service if it didn't already exist, or modifying the contract of the using method to behave more consistently with the using method that take a config object. This would really be moving a failure that will occur anyway when using using from being a CM build time to earlier in the builder invocations (arguably a good thing).
There was a problem hiding this comment.
What would you do instead? usingIfNotPresent or using(Service service, boolean overrideIfPresent)? I agree that I don't like the getServices either.
There was a problem hiding this comment.
I'm thinking the sensible solution would be to add usingIfAbsent(...) methods to the builder. At the same time it might make sense to also align the contracts for the service and service-config related methods since I think they vary a bit at the moment.
0ccb0cb to
f046974
Compare
|
Given our proximity to release and the associated need for stabilization I'd like to hold off on merging this until after the release goes out. I'd also like to see if we can align more of the using behaviors like previously discussed. |
f6b4709 to
01711c0
Compare
f70198f to
b870a6f
Compare
e16fb5f to
2318ff8
Compare
we are now pass the release
a218841 to
76d50d9
Compare
76d50d9 to
26e98cc
Compare
No description provided.