Skip to content

Allow to create a CacheManager using an Ehcache builder#2347

Open
henri-tremblay wants to merge 9 commits intoehcache:masterfrom
henri-tremblay:cachingproviderbuilder
Open

Allow to create a CacheManager using an Ehcache builder#2347
henri-tremblay wants to merge 9 commits intoehcache:masterfrom
henri-tremblay:cachingproviderbuilder

Conversation

@henri-tremblay
Copy link
Copy Markdown
Contributor

@henri-tremblay henri-tremblay commented Mar 20, 2018

No description provided.

public CacheManager getCacheManager(URI uri, ClassLoader classLoader, CacheManagerBuilder<org.ehcache.CacheManager> builder) {
Eh107CacheManager cacheManager;

synchronized (cacheManagers) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably extract this common block between here and the existing code in to a combination of a computeIfAbsent and a compute.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which means the findSingletonAmongst is strangely permissive and this code doesn't work at all? Or it supports both?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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???

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to actually add the services to the builder.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats services collection doesn't get consumed (unless I'm missing something).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dear.

Copy link
Copy Markdown
Member

@chrisdennis chrisdennis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good in principle but some details need fixing/clearing up.

@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch from 94d1bd4 to 07631be Compare March 21, 2018 21:33
@henri-tremblay
Copy link
Copy Markdown
Contributor Author

I think all changes were implemented.

this.jsr107Cache = ehCache.createJsr107Cache();
}

private StatisticsService getStatisticsService(Eh107CacheManager cacheManager) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be indeed

@chrisdennis
Copy link
Copy Markdown
Member

Could we separate this from the exposure of the ServiceLocator so that we can consider the two changes independently?

@henri-tremblay
Copy link
Copy Markdown
Contributor Author

It's hard (impossible?) because getting rid of Eh107InternalCacheManager makes it possible. Otherwise, I will need a CacheManagerBuilder.build107CacheManager

@chrisdennis
Copy link
Copy Markdown
Member

Lets see if we can come to agreement on #2346 then, which would allow this to go through.

@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch from 07631be to 7792dca Compare May 22, 2018 18:32
@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch 3 times, most recently from d83920c to 3847f36 Compare July 16, 2018 20:01
@henri-tremblay
Copy link
Copy Markdown
Contributor Author

@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) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feel like this Supplier should really be a function, possibly taking the URI and ClassLoader as arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you do instead? usingIfNotPresent or using(Service service, boolean overrideIfPresent)? I agree that I don't like the getServices either.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch 2 times, most recently from 0ccb0cb to f046974 Compare August 6, 2018 18:47
@chrisdennis
Copy link
Copy Markdown
Member

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.

@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch 2 times, most recently from f6b4709 to 01711c0 Compare August 29, 2018 18:04
@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch 2 times, most recently from f70198f to b870a6f Compare September 14, 2018 15:10
@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch 2 times, most recently from e16fb5f to 2318ff8 Compare December 10, 2018 16:41
@henri-tremblay henri-tremblay added this to the 3.7.0 milestone Dec 10, 2018
@henri-tremblay henri-tremblay dismissed chrisdennis’s stale review December 10, 2018 18:57

we are now pass the release

@akomakom akomakom closed this Dec 10, 2018
@akomakom akomakom reopened this Dec 10, 2018
@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch 5 times, most recently from a218841 to 76d50d9 Compare December 17, 2018 02:33
@henri-tremblay henri-tremblay force-pushed the cachingproviderbuilder branch from 76d50d9 to 26e98cc Compare January 4, 2019 18:12
@henri-tremblay henri-tremblay reopened this Jan 4, 2019
@chrisdennis chrisdennis removed this from the 3.7.0 milestone Feb 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants